A Small Project

As per my last post about the Stanford engineering classes I’ve been taking online, I’m going to upload a small project I’ve been working on to help me get my head around Java programming. The instructor had shown an in-class example of how to do animation in Java. His example was just a single ball that bounced across the screen in a set path, and the animation ended. I decided to take this a little bit further, adding a (really) rudimentary physics engine behind it all, the ability to generate new balls with mouse clicks, random initial velocity with a random number generator, and wrapped it all up in a neat little applet. I also learned a little bit about multi-threading and frame buffering (I had to do this to smooth out the animation).

But seriously, the physics engine is pretty bad for ball collisions. If any collision happens, at any angle or velocity, the two colliding balls just swap velocities and continue on. This only really looks accurate for head-on collisions, but I just didn’t feel like doing all the vector math to make it look “proper” as this wasn’t intended to be an exercise in math, but rather programming. Anyways, All you’ve got to do do have a grand ol’ time is just click in the box below. Ignore the “frame xxx” counter.. that’s just counting the frames of animation that the applet has processed. I never took it out.


Oh, and here is a link to the source code if anyone is interested.