Note: This is not a paired lab, each student must work individually, both on the prelab and the lab itself.
Prepare for completing Lab 9: Fractals. There is nothing to turn in for this prelab, but be sure to work through all lecture notes on recursion and read through the entire Lab 9 assignment. We suggest you sketch a plan on paper for the following two problems.
You will write a recursive function that draws a Sierpinski triangle.
Notice there are 3 smaller Sierpinski triangles in a Sierpinski triangle. Suppose you had code to draw each of the smaller Sierpinski triangles that took the the length of triangle side as an argument. How would you move the turtle to be in the correct locations to start the drawings of those 3 smaller Sierpinski triangles? After drawing the third smaller Sierpinski triangle, how to get the turtle back to where it started?
A recursive H is an H where the end of each vertical line of the H may have another recursive H. The recursive H is defined by a level.
A level 1 recursive H is just an H:
A level 2 recursive H has another smaller H at the end of each line:
A level 3 recursive H has another smaller H at the end of the each of these Hs:
Notice that the smallest level of H always ends in a dot (a “level 0” H).
Make a sketch on paper to gain insight into how a recursive H is composed of smaller recursive Hs. The size of an H is defined by the parameter
length. The vertical bars are of length
length and the horizontal bar of length
2 * length. Assume that the turtle starts in the middle of the drawing window, and thus the middle of the horizontal bar, facing to the right. At the end of drawing, the turtle should be at the same position and heading as when it started. Write out a high-level plan for how to produce the overall recursive H from smaller ones. You might find numbered/bulleted list is a good way to outline your algorithm.
There is nothing to turn in for this prelab.