CIS2168 - Homework 5: Turtle Graphics
Handed out: 09/28/10
Due: by 10pm on 10/04/10
You may use the code and example provided in this
directory.
The Koch
Curve is a famous fractal often used to draw the sides of regular
polygons to create fake snowflakes. It is defined recursively in terms of
a distance, step, and an integer, n.
Assuming that we start at a given
point and we are oriented in a given direction (angle):
void koch(double step, int n) {
if (n == 0)
goForward(step);
else {
koch(step/3.0, n-1);
rotate(60);
koch(step/3.0, n-1);
rotate(-120);
koch(step/3.0, n-1);
rotate(60);
koch(step/3.0, n-1);
}
}
That is the orientation at the end of the curve is the same as at the
beginning.
For n from 3 to 8, draw a polygon with n sides where the sides are Koch
curves of order 3.
The Spira Mirabilis is another famous curve. It is defined by 3
double parameters, an angle, a step, and a factor.
Then, assuming that we start at a given
point and we are oriented in a given direction (angle):
void spiraMirabilis(double angle, double step, double factor) {
for (int k = 0; k < 10*360/angle; k++) {
goForward(step);
rotate(angle);
step = step*factor;
}
}
Draw at least two different spira mirabiles.
You are free to present all the drawings as a single drawing, or to
present them in succession.