Category Archives: programming

Bouncing Ball

bouncing ball, rainbowified

Ruthie and I worked together on two assignments. The first was “Make a ball bounce around the screen.”

I thought I knew how to do this, but after beating my head against it for maybe forty-five minutes, I finally looked at the example online: Example 5-6: Bouncing Ball.

Ohhhhhhh. I would never have thought of that speed = speed * -1; in a million years.

So then we ended up copying the example, which is not much fun. To make it more interesting, we made the ball move diagonally. But with both speedY and speedY incrementing at a steady rate, the ball just does a box step. Still not very interesting. I wanted to introduce a little rotation, but using speed = speed * -1.1;, though interesting at first, eventually speedY goes too far from +/- 1, which causes the ball to go crazy and disappear.

So I added an if statement to reset the variable to 1 if it got outside the range -/+ 5, but that, too, caused the ball to start behaving weirdly after a couple of turns. I figured out that it had to do with not keeping the ball going in the right—-making the reset value always +1, never -1—but I didn’t know how to preserve a negative value. Jeremy came over and talked me through making it work. Yay, Jeremy!