# CPSC 120: Lab Assignment 2

### Due by the start of class on Friday, 02/10/2017

Home | Calendar | Announcements | Assignments | Example Code | Notes

### A Bouncing Ball

This sketch simulates a ball ricocheting around the inside of a box. It makes use of if/else statements to detect when the ball has reached an edge of the box. When it does hit an edge, it "bounces",either vertically or horizontally.

Take a few minutes to study this code, run it, and understand how it works.

You are to modify this sketch in four ways:

1. When the mouse cursor moves outside of the box, the background of the entire window should turn bright red.

2. By default, the transparency of the ball should be 0, rather than 255. (You may want to comment out the noStroke() command until you're done testing everything.

3. When the mouse cursor is within a distance of 100 pixels from the center of the ball, the transparency should increase to 10.

4. When the mouse cursor is inside the ball, the transparency should increas to 255.

For items 3 and 4, here's some code to help with calculating the distance between points (a,b) and (c,d):

```float distance = sqrt((c-a)*(c-a)  +  (d-b)*(d-b));
```

### Bonus Fun (strictly optional)

• Have the ball change size over time, growing or shrinking.

• Add a second ball, with similar characteristics to the first one.

### Turn In

Make a folder in your turn in directory named "lab2". Copy all four of your solutions in to this folder. Consult the Linux tutorial from Lab #0 if you need a reminder of the details.

### Standards

• Your code must be syntactically correct. Any solution that contains a syntax error anywhere (and hence crashes when you hit the "play" button") will receive no credit.

If you run into any trouble here, please ask me or one of the TAs for help.

• Naturally, your code must be behaviorally correct, though partial credit is always given for partial solutions.

John H. E. Lasseter