20. Using Structures
Utility functions for posns. Accessing functions defined in other files.
A circle moves around the screen randomly. You win if you can click on it.
Brief explanation of how to stop animations and show a win screen.
Challenge Keep track of a score of how many circles have been clicked since the last time you missed a circle. This will require a posn inside another posn.
A simply silly 'game' to practice win conditions.
A square changes color as you balance between two circles.
Changing the colors in a picture, pixel by pixel.
One exercise working with color.
Review questions on posn and color.
You may use anything from your posn-util.rkt without comment. Write is-box?: posn -> boolean which returns true when the given point is in the illustrated box. Write p-circle. p-circle: posn(center) posn(edge-pt) image(background) -> image Draw a red circle on the given image background. The center of the circle should be at the posn center. The edge-pt should be on the perimeter or boundary of the circle.
Write a function slope-posn that takes in a posn and gives the slope of the line through (0,0) and the posn. slope-posn : posn -> number Write a function perp? that takes in two posns each being (change in x, change in y) - like above - and returns true if they represent slopes of perpendicular lines. perp? : posn posn -> boolean Write on-line?
A simple example of something you should be able to do.
In this animation you copy AimBooster.com, but simplified so you can make it with what you know from Chapter 20. A single circle is at a random place. Radius increases. Clicking on the circle gives you points inversely proportional to the radius (maybe 100/radius). When the circle is hit, it disappears and another starts growing. When the circle reaches a certain radius it disappears. After missing three circles, the game is over.