CMU 15-110 Spring 2019: Principles of Computing
Homework 2 (Due Wednesday 6-Feb at 8pm)


Note: This hw has a special Wed due date due to the missed lecture and recitation due to the Polar Vortex days.
This hw is entirely solo. See the syllabus for details.
Hints:

  1. Start early! Work solo (of course), but go to OH often! Ask questions! We are here to help!

  2. Before you start hw2, be sure you can do all of the examples from the Events and Conditionals notes, starting from the starter code, and without consulting the notes. That is really a pre-condition to being able to do hw2!

  3. Watch this helpful . It shows you how the app should look and behave when you run it.

  4. To test if two conditions are both true, you can use and. For example:
      if ((x > 0) and (y < 0)):
        ...

To start, download events-starter-code.py and rename that file hw2.py
In the file hw2.py that you just created, do the following (note: this is also demonstrated in the helpful video, as mentioned in the hints section):

  1. Use a 500x500 canvas and use a timerDelay of 25 milliseconds. Try to match the video demo fairly closely, for example when choosing by how much to move shapes on each step.

  2. If 'p' is pressed, the app is paused, and it ignores all timerFired events until 'p' is pressed again. When paused, mouse and keyboard events are still handled like normal, and 'PAUSED' is drawn in a very large font on top of everything else (hint: draw this last!).

  3. Draw a green (any shade, say 'green' or 'lightGreen') circle of radius 50 vertically centered along the left edge, and a gold circle of radius 50 vertically centered along the right edge. The left and right arrows control the green circle, and the up and down arrows control the gold circle. Each time the circles intersect, they immediately move back to their starting positions. Also, ignore any key presses that would result in the center of either circle moving off the canvas.

  4. Bounce the 50x50 cyan square back-and-forth along the top of the canvas, keeping a score inside the square. If the user clicks inside the square, the score goes up by one. Clicks outside the square do not affect the score. Hint: testing if a point is inside a square is entirely different from testing if a point is inside a circle. In particular, do not use the distance formula here!

  5. When the mouse is moved (not dragged), a small maroon diamond cursor follows the mouse. The cursor is not drawn during a mouse drag, so it is not drawn while the mouse is pressed, but it appears at the location where the mouse is released.

  6. When mouse is pressed, if the mouse press is not inside the cyan square (see above), then: an unfilled rectangle with a black outline is drawn starting from where the mouse is pressed, and ending at the current mouse position, so it "rubber bands" or moves with the mouse, until the mouse is released, when this rectangle is no longer drawn.