Gravity part deux.

So I’ve been playing around in Python lately, primarily because I’ve been teaching it to a kid I’ve been tutoring. I decided to take the opportunity to port my old C# based gravity simulation to see how hard it would be to implement. I chose to use pygame because it provides the screen update engine and drawing routines out of the box with an easy way to tell how many milliseconds have passed since the last frame update (required for accurate physics). I haven’t really made any tweaks to the physics engine since the mono version, but it’s still pretty cool to watch. One thing I did add to this is a 2×2 box with alpha 10 that simulates a pencil running over paper wherever a ball passes. I liked the visualization so much, I left it turned on in the version I hereby bequeath to you, dear internet. Below are two of the generated images, the lighter the color of the line, the faster the ball was moving at the time.

First image from my gravity simulator
First image from my gravity simulator
Second image from my gravity simulator
Second image from my gravity simulator

Oh, I suppose you’d like to download the current version. It’s sloppy, but you’re welcome to it! Some code borrowed from the python/pygame tutorials, but the physics are all mine.

Download it here.

Update: Almost forgot!!! Left click adds an additional ball, right click saves a screenshot and clears the background.

Update 2:

This one was after about 30 minutes with 6 balls
This one was after about 30 minutes with 6 balls

Just another image, click to enlarge.

Update 4: Put a video up on YouTube showing what it looks like while running: http://www.youtube.com/watch?v=OOBBPtsu5MM