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
- designing your own class
- working with separate files
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:
- function headers and function header comments for all the functions
you plan to use
- 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 Monday, 5/9/11 before 11:59 p.m.
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 Task
- The name of your file that contains main() 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 MUST 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. Your
class should be contained in its own file, which must
be called turtle.py. You are NOT allowed to use any already written
turtle classes.
- You are to write recusive functions that will draw the snowflake and
the C-Curve. Iterative versions of these functions will receive no
credit.
- Any functions you use that are modules, such as getValidInt(),
should be included in a file called util.py and imported.
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.
-
Use getValidInt() to restrict the degree
to be between 0 and 4, inclusive. Reprompt if other integers are
entered.
- You should restrict the user to entering just the names of a
few basic colors, perhaps the colors that come in a standard 8-pack
of crayons. You should test for invalid colors. It's only necessary
to provide a list of acceptable colors if the user has chosen a color
that is not on your list.
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.
Submitting your work
You must be logged into your account and in the same directory
as the file you are trying to submit.
To submit your project, type the following at the linux prompt:
submit cs201 Proj2 proj2.py turtle.py util.py
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show all files that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj2