Home More Java Resume


JavaBalls!

Click to begin a marvelous journey.

Hint: click repeatedly to produce a lot of balls.

Write to me!

JavaBalls is a "bouncing balls" applet. Each mouse click in the frame will cause a new randomly sized ball to appear in the center of the frame. The ball will be moving in a random direction at a random speed. When a ball hits the frame boundary, it bounces back at a random angle and chooses a new random speed.

When two balls collide, each ball will either be destroyed by the collision or split into two new balls. The new balls are each of random size and begin moving in random directions. Balls which are destroyed by a collision blink out of existence as a crosshair. Balls which are about to split in two expand in size and change color just prior to splitting.

The fun begins when a group of balls enter into a chain reaction caused by overlapping collisions. Watch it.

The JavaBalls applet has two buttons: stop and clear. Some chain reactions become so fierce that they start to suck up all of a computer's CPU. When this happens, you may press stop and/or clear to regain control. After pressing stop, it changes to a go button, allowing you to restart the animation.

For advanced users, JavaBalls accepts a parameter which determines how likely each ball is to be destroyed by a collision. The default value is .51 (51 percent). Values close to .5 are interesting. A value less than .45 will lead pretty quickly to CPU lock. A value greater than .55 will usually not be very interesting. If you are running the applet in your web browser you can specify the parameter "prob" as an html tag. If you are running the application, the probability is specified as a command line argument. (CPU lock would be less of a problem if JavaBalls used a better collision detection algorithm).

I wrote JavaBalls as a JAVA 1.1 application during a week long JAVA class. I converted it to JAVA 1.0 applet so that most web browsers will be able to play it.

The source code: