Lab 2: Recursion Projects
In this lab, students explore more variety in fractal shape generation and practice writing recursive definitions (like tree
in Lab 1) right away without first constructing non-recursive versions (e.g. tree 1
, tree 2
, tree 3
, etc.) of their programs. Students explore several common fractal structures, see how fractal structures occur in the natural world, and then use recursion to model the artwork of Mondrian.
Looking Ahead
- Students work with recursive commands in this unit; they will program recursive reporters in Unit 8.
Pacing
The 3 required lab pages could be split across 3–5 days (
95–190 minutes). Expected times to complete follow:
Prepare
- You may find it helpful to try a few of the lab pages yourself before presenting them to students—perhaps one of the fractals (Triangle Fractal, Koch Snowflake, or Lévy C-Curve) and the Recursive Mondrian page.
- It may help you to read the Wikipedia article on Mondrian before students work on that page. His tree paintings start out completely realistic and then gradually, over time, he abstracts away some of the details. The last of his tree paintings look a lot like his later abstracts.
Lab Pages
-
Page 1: Triangle Fractal.
- Learning Goal: Practice recursion by developing several fractal-drawing programs.
-
Debugging: Triangle
- This optional debugging activity is similar to one that students saw in Unit 1 with a pentagon. The purpose is to highlight the difference between the interior angle of a polygon and the turning angle that a sprite must move through in order to create each angle of the shape. Use as needed with your students. Additional details on clarifying this idea are included in the "Tips" section below.
- Tip: You may need to remind students of the difference between an interior angle (like the angles they learn about in math class) and an angle of sprite rotation (exterior angle). Students associate the angles of a equilateral triangle are 60° but, to draw a triangle with a sprite, they need to think how the sprite turns. After drawing each side, note the direction the sprite is facing; it must turn 120° in order to draw the next side. Demonstrating this to students by using a physical object (e.g., a pencil) to represent the sprite as it moves may help.
-
Page 2: Koch Snowflake.
- Learning Goal: Practice recursion by developing several fractal-drawing programs.
- Discussion: Discuss the last "For You To Do" question as a class: Why does the size in each recursive call have to be one third the size of the previous level? There are four copies; why not one fourth the size?
-
Page 3: Lévy C-Curve Fractal.
- Learning Goal: Apply mathematics (including Pythagorean formula, coordinate positioning, and angles) to computer graphics.
- Discussion: After students have had time to explore them on their own, you may want the class to discuss the first two questions (about the size input for the recursive calls and about how the turning angles combine to create a 180° angle).
-
Tip: Students may require some support around the use of the Pythagorean formula on this page, but it is not beyond an introductory algebra student. Since size is the length of the long side of an isosceles right triangle, the size of the smaller sides can be found in this way:
smaller^2 + smaller^2 = size^2
2 \times smaller^2 = size^2
smaller^2 = \frac{size^2}{2}
smaller = \sqrt{\frac{size^2}{2}}
smaller = \frac{size}{\sqrt{2}}
-
Page 4: Recursive Mondrian.
- Learning Goal: Use recursion to create Mondrian-style pictures.
-
Tips:
- This page is quite a bit harder than most previous work, in part because we deliberately refrained from extensive scaffolding. It may take your class longer than most pages and they may leave the first class session with their code still not working.
- As with any recursion, tell the students not to try to trace the steps of the program down to the base case. Instead, they have to have faith that the recursive call will work, and make sure that the rest of the code uses it correctly, e.g., maintaining state transparency (returning the sprite to the position and direction in which it started).
- The page tells students to draw the solid colored rectangle by setting the pen size to the desired width, then moving through the desired height (or the other way around). To make that work, the sprite must be positioned in the middle of the width side, because the rotation center of the sprite is in the midpoint of the wide pen. We don't tell this to students; they should discover it for themselves if their first try doesn't work.
- There's another way to draw a solid rectangle: First draw the black border, then, with the pen up, move the sprite to inside the rectangle, then use the
fill
block. The solution file includes both approaches. If a student uses fill
instead of following the directions in the lab, that's fine; don't make a fuss about it.
- If the entire stage fills with color, they didn't pick the pen up before moving inside the rectangle.
- Problem 7 and the If There Is Time problems try to pull students out from the coding details they've been focused on, to think about the art. In particular, problem 7 is an attempt to get more-is-better students to see that a level-15 picture may work (if they use
warp
or turbo mode), but it doesn't look anything like a Mondrian.
Related Resources:
These Wikipedia articles may be too advanced for students, but you may find some of the images and background useful resources:
Solutions