# Project 2 - Recursive Curves

design2.txt - due on Sunday, 12/6/09, before 11:59 PM
proj2 - 24hr extension given Friday, 8:00 PM
project2 - due on Monday, 12/14/09, before 11:59 PM

Sue Evans

Hit the space bar for next page

# The Objectives

Experience working on a larger problem using good design practices including:

• top-down design
• top-down implementation using stubs
• incremental programming with individual function testing
• use of meaningfully named constants

For this project, you'll be required to use your own design.
A separate design document is due one week before the project code.

# The Design Document

The design document for this project, design2.txt, should be a plain text document written using emacs. It should include:

• any constants you plan to use
• a description of the class you will write, including its name, the names of the data members and a description of what they will hold, the names of the methods you plan to have and a description of what they will do
• We have been drawing design diagrams in class, but since we want just a plain text document, just describe in a paragraph or two how your program will work in sufficient detail that I could draw a diagram from your description.

design2.txt is due Sunday, 12/6/09 before midnight

Use the following submit command to submit it.

submit cs201 Proj2 design2.txt

How much does the design document count ?

The design document is worth 10 points of your project grade if it is submitted by its due date. There should be few variations between the design you turn in and the actual design of the project you turn in the following week. If your grader decides that you have altered your plan too much, a deduction of up to 5 points can be made for major changes.

# The Background

### Recursive Curves

We've looked at the Koch snowflake recursive curve on the lecture slides. Recall from the lecture, that the Koch snowflake starts as an equilateral triangle. So a Koch snowflake of degree 0 looks like this:

Here is a drawing of what each side of the snowflake looks like for each degree from 0 through 4, inclusive:

There are other recursive curves as well. Some are quite beautiful and intricate. This one is known as the dragon curve.

And this is the C-Curve

• The name of your file must be proj2.py
• You are to write a menu-driven program that will allow the user to view a Koch snowflake, view a C-Curve, or view an animation of the Koch snowflake. You are to use the graphics module for this.
• Your menu MUST accept upper-case or lower-case K, C, A, and Q and reprompt for any other input. If you are doing the extra credit, your menu should also accept upper-case or lower-case D.
• You are to write your own Turtle class that contains instance variables location, which is a Point, and direction, a float. You decide which methods you should have.
• You are to write recusive functions that will draw the snowflake and the C-Curve. Iterative versions of these functions will receive no credit.

# What's a Turtle

According to Wikipedia, "Turtle graphics is a term in computer graphics for a method of programming vector graphics using a relative cursor (the "turtle") upon a Cartesian plane. Turtle graphics is a key feature of the Logo programming language."

Here's an example of the turtle being used to make a drawing in Logo.

# The Details

• If the user chooses K, you should prompt the user for the degree of the snowflake and the color they would like. Restrict the degree to be between 0 and 4, inclusive. Reprompt if other integers are entered. You should also test for an invalid color. Here's the sample run when the user chooses k:
• If the user chooses C, draw the C-Curve of degree 12 in black. Here's the sample run.
• If the user chooses A, the animation of the Koch snowflake, begin by drawing degree 0, then change color and draw degree 1, overwriting the degree 0 image. Continue in this fashion through degree 4.
The length I used for this was 243 in a 500 X 500 window.

# Extra Credit

For 5 points of Extra Credit, add a choice D to your menu, which allows the user to view a dragon curve being drawn. The dragon() function MUST be recursive.