%CustomEntities; %CourseEntities; %CommonEntities; ]>
Laboratory: Project Ideas Summary: In this laboratory, you will explore the three new approaches to making images that were covered in the corresponding reading.
Preparation a. Create a new 200x200 image called canvas. b. Add the various procedures given at the end of this lab to your definitions pane.
Exercises on Color Trees
Exercise 1: Color Tree Basics a. What effect do you expect the following instruction to have? > (render-color-tree! "blue" canvas 0 0 200 200) b. Check your answer experimentally. c. What effect do you expect the following instruction to have? > (render-color-tree! (cons "black" "red") canvas 0 0 200 200) d. Check your answer experimentally. e. What effect do you expect the following instruction to have? > (render-color-tree! (cons "red" "black") canvas 50 50 100 100) f. Check your answer experimentally. g. What effect do you expect the following instruction to have? > (render-color-tree! (cons (cons "green" "yellow") "orange") canvas 0 0 200 200) h. Check your answer experimentally. i. Create one or two color trees of your own and render them.
Exercise 2: An Alternate Implementation a. Compare new-render-color-tree! to render-color-tree!. What do you see as the primary difference? b. Redo all but the last step from Exercise 1, using new-render-color-tree! in place of render-color-tree!. c. What do you expect the result of the following command to be? > (new-render-color-tree! (cons (cons (cons color-black color-green) color-yellow) color-orange) canvas 0 0 200 200) d. Check your answer experimentally.
Exercise 3: A Simple Series of Images Look at the code for series-1. a. What do you expect (series-1 5 100 100) to produce? b. Check your answer experimentally. c. What do you expect (series-1 42 100 100) to produce? d. Check your answer experimentally. e. Do you expect (series-1 43 100 100) to be similar or very different? How do you expect it to differ? f. Check your answer experimentally. g. How do you expect (series-1 43 500 500) to differ? h. Check your answer experimentally. i. How do you expect (series-1 43 800 100) to relate to the previous two images? j. Check your answer experimentally.
Exercise 4: From Rectangles to Ovals Replace image-select-rectangle! in new-render-color-tree! with image-select-ellipse!. Try the last few examples from the previous exercise.
Exercises on Fractals
Exercise 5: Simple Fractal Activities a. Use fractal-rectangle! to draw a 200x200 blue rectangle on canvas, using a recursion level of 0. b. 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. 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. Here's a modified version of fractal-rectangle! in which we've changed the recursive calls for the top-middle, left-middle, right-middle, and bottom-middle subrectangles so that they use the complement of the color. Put this new version at the end of your definitions pane. (Scheme always uses the last definition.) Use this procedure to 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 RGB colors. And here is a rewritten fractal-rectangle! that averages the colors in the top-middle, left-middle, right-middle, and bottom-middle subrectangles with black and the colors in the other five subrectangles 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. Let's 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. Add the following to the end of your definitions pane. 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.
Exercises on Genetic Art
Exercise 6: Visualizing Files While we are unlikely to use file-visualize in the project, it's probably worth playing with it once or twice to see its effect. a. Use file-visualize to visualize /usr/bin/vi, a simple text editor. > (file-visualize "/usr/bin/vi" 50 50) b. Use file-visualize on a file of your choice. c. What effect do you expect if we use a 100x100 image? A 500x500 image? d. Check your answers experimentally.
Exercise 7: Visualizing With Grids Here's a simple palette. (define sample-palette (vector color-black color-white color-grey color-blue)) a. Using this palette and image-file->grid!, visualize the same two files that you tried in the previous exercise, using a 50x50 image size and a 10x10 grid. b. What effect do you expect if we continue to use a 10x10 grid, but expand to a 100x100 image? A 500x500 image? c. Check your answers experimentally. d. What effect do you expect if we continue to use a 500x500 image, but expand to a 20x10 grid? A 10x20 grid? e. Check your answers experimentally.
Exercise 8: Another Series of Images Consider the code for series-2. a. What colors (palette) do you expect it to use if n is 42? b. How many columns do you expect in the grid if n is 42? c. How many rows do you expect in the grid if n is 42? d. Check your previous three answers experimentally. e. How do each of those answers change if n is 43? 49? f. Check your answers experimentally. g. [This is definitely a math problem, so you can skip it if you wish.] Is there another n that gives the same palette, columns, and rows as 42? If so, find one (or think about how you might find one). If not, explain why not. Is there one less than 1000 that uses the same file?
Exercise 9: Teaching Turtles to Draw a. Using file-instruct-turtle and a file of your choice, draw a picture. (You should probably use at least 100 commands.) b. Try changing a few of the letters in the lists at the beginning of the definition and see the effects of those changes.
Notes The point of 8.g is to suggest that coming up with four parameters to your image, one of which has five values, one of which has seven values, one of which has nine values, and one of which has eleven values gives you many more than 1000 different images. As importantly, you can easily turn any number between 0 and 1000 to a set of those values by using modulo.
Useful Procedures and Definitions (define color-white (rgb-new 255 255 255)) (define color-black (rgb-new 0 0 0)) (define color-grey (color-name->rgb "grey")) (define color-red (color-name->rgb "red")) (define color-green (color-name->rgb "green") (define color-yellow (color-name->rgb "yellow")) (define color-orange (color-name->rgb "orange")) ; +-------------+--------------------------------------------------------------- ; | Color Trees | ; +-------------+ ; +----------+------------------------------------------------------------------ ; | Fractals | ; +----------+ ; +-------------------------------+--------------------------------------------- ; | Repurposing Files/Genetic Art | ; +-------------------------------+