Conditional Testing

c28-fig-5001.jpg

Left or Right

Create a sketch in which a text display indicates whether the cursor is on the left side or the right side of the canvas.

c28-fig-5002.jpg

Billiard Ball

Create a sketch with a moving ball that bounces off the edges of the canvas. Take care that the ball never appears to overlap the edge of the canvas.

c28-fig-5003.jpg

One-Person Pong

Create a sketch that recreates the game of Pong for a single user. Can you add a scoring system?

c28-fig-5004.jpg

Choose Your Own Adventure

Create a branching narrative experience in which clicking in different regions of the screen leads to different rooms, situations, and outcomes. Enhance the experience with sound effects (e.g., door latches) and ambient audio recordings.

c28-fig-5005.jpg

State Machine I

Place a white square on a gray background. Create an interaction wherein a click inside the square turns it black, after which it stays that way. (In this exercise and those that follow, make sure that clicks outside the square have no effect.)

c28-fig-5006.jpg

State Machine II

Place a white square on a gray background. Create an interaction wherein each click in the square flips its color. It should flip from white to black (if it is white) or from black to white (if it is black).

c28-fig-5007.jpg

State Machine III

Place a white square on a gray background. Create an interaction wherein two clicks in the square are required to turn it from black to white, but three clicks are required to turn it from white to black.

c28-fig-5008.jpg

State Machine IV

Place a white square on a gray background. Turn the square into a button with a “hover” state: make it white when inactive, yellow when the user is hovering over it (without having clicked), and black when the user is actively holding the mouse button down inside of it.