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


Quiz5 Version A


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 50 moves back-and-forth along the diagonal from the top-left to the bottom-right, moving at a constant speed (initially changing both cx and cy by 5 at each step). The dot should start in the middle of the screen, moving towards the bottom-right. The ball should change direction each time its center moves off the canvas.
  2. When the user presses the mouse inside the red dot, the dot's radius is halved.
  3. When the user presses 's', the dot's speed increases by 2 (i.e. after the first 's' the dot changes cx and cy by 7 at each step, then 9, and so on).
  4. When the user presses 'p' and the dot is moving, it pauses (stops moving). When the user presses 'p' and the dot is paused, it starts moving again. Ignore 's' and mouse clicks when paused.
  5. When the user presses the mouse outside the red dot, 'Game Over' is displayed in the middle of the canvas and nothing further happens -- the dot stops moving, and all key and mouse presses are ignored.