Assignment 3
Due Date: Thursday 5/16/19 at 10:00pm
Purpose It is time to graduate from programming to program design.
Write enough check-expects for these exercises so that when you hit "run" no black text appears. Make sure to follow the Design Recipe!
Graded Exercises
Exercise 1 The drawing of a chameleon in Section 5.11 of HtDP/2e is a transparent image. To insert it into DrRacket, copy and save the image from HtDP/2e and insert it with the "Insert Image" menu item. Define the image with the name CHAM. Using this instruction preserves the transparency of the drawing’s pixels.
When a partly transparent image is combined with a colored shape, say a rectangle, the image takes on the underlying color. In the chameleon drawing, it is actually the inside of the animal that is transparent; the area outside is solid white. Try out this expression in your DrRacket:
(overlay CHAM (rectangle (image-width cham) (image-height cham) "solid" "red")) Design a world program that has the chameleon continuously walking back and forth across the screen (you should rotate the image 90 degrees so it is facing right). It starts walking from left to right and when it reaches the right end of the screen, it flips horizontally and begins walking from right to left and switches direction again when it reaches the left boundary.
Of course, like all chameleon’s, ours can change color, too: the key "r" turns it red, "b" blue, and "g" green.
Start with a data definition, VCham, for representing chameleons. You will need to represent the position, color and direction of the chameleon in your definition.
Here is a wish list for the functions you will need:
draw-cham – renders the world as a chameleon facing left or right
next-cham – compute the new location of the chameleon in one clock tick from now
change-cham – changes the color of the chameleon if the "r", "g" or "b" key is pressed