In this assignment, you’ll warm up by writing a couple functions using
cond, then you’ll create some more sophisticated animations that these features enable.
Please write the following functions (with contracts) in a file called
YourNameBooleans1.rkt. Upload this file to Google Classroom, and leave me a comment (on Classroom) explaining how you tested your code (e.g., “I tested out each function in the interactions area”) and what happened (e.g., “they all worked!“).
Design a function that takes in an image as input, and returns a string describing the shape of the image as “wide”, “tall”, or “square”. An image is considered wide if it is wider than it is tall; tall if it is taller than it is wide; and square if has equal width and height.
Design a function that takes in a number representing a year (e.g.
1973), and returns
#true if that year is a leap year,
#false otherwise. (Look up the definition of a leap year–it’s not as simple as you think! For example, the year 1400 is not a leap year, but 1600 is.)
Write an animation function (that is,
boat-race : Number -> Image) such that
(animate boat-race) shows two boats, traveling left to right, at different speeds. Both boats should stop when they reach the end of the screen.
Write an animation function (
conversation : Number -> Image) such that
(animate conversation) shows two people (or other animal of your choice) meeting each other in a room (one should enter from the left, and one from the right) then stopping and saying “Hello!” to each other. We should see the word “Hello!” appear in one color, near one person’s mouth, and then afterward, in another color, near the other person’s mouth. The attached video should give an idea of what is expected!
CAR-1-X-SPEED, CAR-1-Y-SPEED, CAR-2-X-SPEED, CAR-2-Y-SPEED, CAR-1-START-X, CAR-1-START-Y, CAR-2-START-X, CAR-2-START-Y. Then define a function
car-crash that displays an animation in which two cars start at their respective start locations and travel at a constant speed in their respective directions (as determined by the speed variables, which might be negative, indicating “backward” movement). If the two cars hit each other, we should no longer see the cars on screen and only see some indication of the crash (perhaps the word “CRASH!” or an image of an explosion). Changing the variables you defined should change the animation accordingly, without having to modify other pieces of the code.