CS206 Data Structures
Programing Assignment#4
Due on Tuesday, March 6, 2007
Vesion#1 due on Thursday, March 1, 2007 (see Time Line below)
Problem: In this exercise, you will become familiar with the graphics module graphics.py mentioned in Appendix A of your text.
- First, download the module graphics.py from the link below. Install it in your directory/folder where you keep all your Python programs. Read the documentation (link given below) and become familiar with the module and its features. Then, Try out the program listing 3.7 (Sierpinski Triangle) from your text. Show your output for level 4.
- Next, you will use the graphics module by implementing a simple Turtle graphics module. Here is a description of the Turtle object:
A turtle lives in a graphics window. At any given time, it is located at some position in the window and is oriented in a specific direction. The direction is maintained in radians with 0 radians pointing east, PI radians pointing west. The turtle is capable of the following operations:
moveTo(somePoint): Relocates the turtle to the given point (somePoint)
turn(amount): Turns the turtle amount radians from its current orientation.
draw(length): Draws a line of length from the current position and orientation of the turtle. This can be computed as dx = length * cos(direction) and dy = length * sin(direction). After the ine is drawn, the turtle is located at the end point of the new line.
Test your module using the commands below:
win = GraphWin("Turtle Graphics", 500, 500)
win.setCoords(0, 0, 500, 500)
t = Turtle(Point(250, 250), math.pi, win)
for i in range(4):
....t.draw(50)
....t.turn(-math.pi/2)
This should draw a square of side 50 pixels in the middle of the window. Also, make sure to test the other turtle operations.
- Using the turtle module you implemented, implementthe Koch Curve drawing algorithm (handout given in class). Use it to design at least three snowflakes.
Hand in a printout of all the following: a printout of the output from (1) above, your Turtle module, your Koch program, and the snowflakes.
Time Line: By Thursday, March 1 you should have completed (1) above and have a design for (2) ready to be tested. Hand in a printout of your output from (1) as well as a design of the Turtle module.
Back to CS206 Materials