Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Project 4 Turtle Graphics Assignment Overview This assignment will give you more experience on the use of: 1 . classes 2 . class methods
Programming Project Turtle Graphics
Assignment Overview
This assignment will give you more experience on the use of:
classes
class methods
In this project, we are going to use a library package called turtle graphics to draw some pictures, but we will define and use classes to create the basic shapes and assemble them into a picture. You are going to create at least classes. Using instances of these classes, you are going to draw a simple scene. You will write a function that assembles the scene.
Project Description Specification
Define classes at least Each class should create a shape eg circle, square, triangle, etc. Each shape should have a color.
Each class will have an initstr and a draw method:
a the init method will take a string argument, either indicating a fill color or if the argument is the empty string that the shape is not filled.
b the draw method will take at least x and y coordinates arguments indicating where the figure is drawn and a turtle.Turtle object to use for drawing the shape.
c the str is the conversion to a string; it returns the string to be used for printing in python.
d Other arguments may be required for your methods; all arguments will be described in your comments.
Create a picture using your shape classes. Both classes should be used in the picture. You can use the shapes multiple times. See if you can create a cohesive picture using the shapes to create a more complex image eg mountain, house, etc.
All classes, methods and functions require a comment for a general description of the objectmethodfunction
Deliverables
Turn in yournameTurtleProj.py containing all of your class and function definitions.
Assignment Notes:
The idea is to make classes for objects in your scene that have to be drawn and are not just a circle or a squarerectangle
Using turtle graphics: In order to use turtle graphics in python you must first import the turtle module. You can then use the help function in idle to find out what methods this module includes and what they do Just type import turtle in the idle command window, hit enter, and then type helpturtle and scroll up through the list and information.
First create your draw windows with this command: window turtle.Screen
Then name your turtle can use any name, I chose alex: alex turtle.Turtle some useful features include,:
alex.uppen.down: Set the pen state to be up not drawing or down drawing
alex.rightdegrees pen.leftdegrees: Turn the direction that the pen is facing. The amount of turn is indicated in degrees.
alex.forwarddistance pen.backwarddistance: Move the pen forward or backward the amount of distance indicated. Depends on the direction the pen is facing. Draws a line if the pen is down, not if the pen is up
alex.gotoxy: Move the pen to the specified point, drawing a line along the way if the pen is down, and not drawing if the pen is up
alex.pencolorrgb pen.pencolors: Set the color that the pen will hold for all drawing until the pen color is changed. In the first version, each argument is a floating point number between ; the first is the amount of red, the second, the amount of green and the third the amount of blue. In the second version, the argument is a string indicating a color by name or by its hex code, eggreenred#FFFF Hex color codes are at:
wwwwebsource.netcolorchart.htm
alex.fillcolorr g b pen.fillcolors: Set the color for filling figures. Arguments are the same as for the pen color.
alex.circleradius: draw a circle of the indicated radius. The circle is drawn tangent to the direction of the pen in a clockwise direction if radius is positive
alex.writestring: Write a string starting at the present pen point. pen.fillflag: To fill a figure, use the command pen.fillTrue before you start drawing it Draw the figure, then execute the command pen.fillFalse The figure drawn between the two fill commands will be filled with the present color setting.
alex.clear: Clear erase everything written by the pen.
The file turtleexample.py is a simple example illustrating how to use turtle graphics. Bring up a python shell, load this example program which imports turtle then create a pen and call the functions defined in the example program with different size arguments. For instance, type in the shell:
window turtle.Screen
pen turtle.Turtle
drawSquarepen fillcolorgreen
pen.clear
drawCirclespen
drawCirclespen num
Continue to learn about turtle graphics by invoking other methods on pen.
The pictures below demonstrate comprehensive pictures involving multiple shapes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started