%CustomEntities; %CourseEntities; %CommonEntities; ]>
&fractals-prefix;Exploring Fractal-Like Images Due: &fractals-due; Summary: In this assignment, you will explore some potentially interesting variants of a technique for designing images called fractals. Purposes: To help you think more about deep recursion (a technique in which you do multiple recursive calls per procedure call). To give you one final chance to explore techniques for making images before you begin your project. Expected Time: Two to three hours. Collaboration: We encourage you to work in groups of size three. You may, however, work alone or work in a group of size two or size four. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment. Submitting: Email your answer to &profemail;. The title of your email should have the form &fractals-subject; and should contain your answers to all parts of the assignment. Scheme code should be in the body of the message. Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.
Preliminaries One of the more mathematically interesting kinds of drawings is what is commonly called a fractal. Fractals are self-similar drawings. That is, each portion of the drawing bears some resemblance to the larger drawing. We normally draw fractals by breaking the larger drawing into equal portions and drawing each portion using the same technique. For example, to draw an NxM rectangle, we might draw nine (N/3)x(M/3) rectangles in a grid. Similarly, to draw each of those nine rectangles, we might draw nine (N/9)x(M/9) rectangles, and so on and so forth. When do we stop? When we've recursed enough of when the rectangles are small enough. We might express this technique in code as follows. Why would we use such a technique, since all we end up with is the same rectangle? Well, things get a bit interesting when you make subtle changes (other than just the level of recursion) at each recursive call. Most typically, you might draw the different subrectangles in modified versions of the original color. Once you do that, you can also think about changing whether or not you use an even grid, or even whether or not you draw each sub-rectangle. The technique sounds simple, but it can produce some very interesting images. More generally, fractals also let us provide interesting simulations of many natural objects, such as trees, mountains, and coastlines, that have some of the same self-similarity. We'll start our explorations with these rectangles.
Preparation In order to best understand how fractal drawing of rectangles works, it will be useful for you to practice a bit with variants of the fractal-rectangle! procedure. a. We'll start with the plain version of the procedure. Create a 200x200 image, call it canvas, and use fractal-rectangle! to draw a 200x200 blue rectangle using a recursion level of 0. b. Next, use fractal-rectangle! to draw a 200x200 red rectangle using a recursion level of 1. (Don't be surprised if it looks pretty boring.) c. Next, use fractal-rectangle! to draw a 200x200 green rectangle using a recursion level of 2. (Again, don't be surprised if it's boring.) d. After those three exercises, you are probably ready to do something a bit more interesting. Change the recursive calls for the top-middle, left-middle, right-middle, and bottom-middle subrectangles so that they use the complement of the color. Then, draw a 200x200 rectangle fractal with black as the initial color and a recursion level of 1. Once you've done that, try it with a recursion level of 2. e. Predict what will happen if you draw a 200x200 rectangle with yellow as the initial color and a recursion level of 3. Check your prediction experimentally. f. Here is a procedure that averages two colors. Rewrite fractal-rectangle! so that the colors in the top-middle, left-middle, right-middle, and bottom-middle subrectangles are averaged with black and the colors in the other five subrectangles are averaged with white. g. What do you expect to have happen if we draw a 200x200 level-2 fractal rectangle whose initial color is blue? Check your answer experimentally. h. What do you expect to have happen if we draw a 200x200 level-3 fractal rectangle whose initial color is green? Check your answer experimentally. i. Change the computation of the intermediate boundaries so that midcol1 is 1/4 of the way across, midcol2 is 1/2 of the way across, midrow1 is 1/4 of the way down, and midrow2 is 1/2 of the way down. j. What do you expect to have happen if we draw a 200x200 level-2 fractal rectangle whose initial color is red? Check your answer experimentally. What about a level-3 fractal? k. Change the computation of the intermediate boundaries so that midcol1 is 1/4 of the way across, midcol2 is 3/4 of the way across, midrow1 is 1/4 of the way down, and midrow2 is 3/4 of the way down. l. Draw one final level-3 fractal.
Assignment Okay, you're finally done with the preparation. On to the assignment. A. Using the basic ideas presented above, rewrite fractal-rectangle! to make the most interesting image that you can. You might change the size of the subrectangles, the function used to compute their colors, or even the number of subrectangles. B. In addition, write a procedure, random-fractal-rectangle!, that behaves much like fractal-rectangle! except that at least one of the computations (e.g., of the columns, rows, and/or colors) involves a random number. You may have noticed that level-3 fractals can take quite a while to draw. In your experiments, you may want to try your code with recursion levels of 1 and 2 to see what it looks like before trying recursion level 3.
Important Evaluation Criteria We will judge your procedures both on the quality of the images they produce and on the cleverness of your modifications to the code.