Answered step by step
Verified Expert Solution
Link Copied!

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 4 Turtle Graphics
Assignment Overview
This assignment will give you more experience on the use of:
1. classes
2. 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 2 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
1. Define 2 classes (at least). Each class should create a shape (e.g. circle, square, triangle, etc.). Each shape should have a color.
2. Each class will have an __init__,__str__ 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.
3. 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 (e.g. mountain, house, etc.)
4. All classes, methods and functions require a comment for a general description of the object/method/function.
Deliverables
Turn in yourname-TurtleProj.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 square/rectangle.
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 help(turtle) 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.up(),pen.down(): Set the pen state to be up (not drawing) or down (drawing)
alex.right(degrees), pen.left(degrees): Turn the direction that the pen is facing. The amount of turn is indicated in degrees.
alex.forward(distance), pen.backward(distance): 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.goto(x,y): 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.pencolor(r,g,b), pen.pencolor(s): 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 0.0-1.0; 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, e.g.,green,red,#66FFFF. Hex color codes are at:
//www.web-source.net/216_color_chart.htm
alex.fillcolor(r, g, b), pen.fillcolor(s): Set the color for filling figures. Arguments are the same as for the pen color.
alex.circle(radius): 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.write(string): Write a string starting at the present pen point. pen.fill(flag): To fill a figure, use the command pen.fill(True) before you start drawing it. Draw the figure, then execute the command pen.fill(False). 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 turtle_example.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()
drawSquare(pen, fillcolor=green)
pen.clear()
drawCircles(pen,30)
drawCircles(pen, num=12)
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

2. How should this be dealt with by the organisation?

Answered: 1 week ago

Question

explain what is meant by the term fair dismissal

Answered: 1 week ago