CMU 15-112: Fundamentals of Programming and Computer Science
Quiz5b


Quiz5 Version B


See the quiz5 frontmatter.


You may not use LISTS (except implicitly in loops), LIST INDEXING, SETS, DICTIONARIES, or RECURSION.
(20 min.)

Free Response: Animation [100 points]

Note: you should assume the canvas is square, so app.width == app.height.

Write an animation such that:
  1. A red dot of radius 20 starts in the center of the canvas. The dot's radius grows at a constant speed (initially changing the radius by 5 at each step)until the dot touches one of the sides, at which point it shrinks until it is 20, at which point it grows again. It does this grow-and-shrink cycle endlessly.
  2. When the user presses 's', the speed that the red dot's radius changes by increases by 2. (i.e. after the first 's' the radius changes 7 at each step, then 9, and so on)
  3. When the user presses 'p' and the red dot is changing size, it pauses (stops changing). When the user presses 'p' and the red dot is paused, it starts changing size again. Ignore 's' and mouse clicks when paused.
  4. Each time the mouse is pressed, if there is no blue dot, then a blue dot of radius 20 appears where the mouse was pressed. If the blue dot is already visible, then the blue dot disappears.
  5. If ever the blue dot is visible and it intersects the red dot, then 'Game Over' is displayed in the middle of the canvas and nothing further happens -- the dot stops growing or shrinking, and all key and mouse presses are ignored.