pygame is
Simple DirectMedia Layer is
Site Swing
Gravity Simulation

Gravity Simulation - 1.0.0

Ian Mallett (geometrian)



This little demo uses physics to determine the motions of objects. To begin, there will be a user specified amount of particles of equal mass. As they coalesce, they will gain mass. The screenshot can really not describe this. It has to be demoed to be appreciated.


Home Page:


click to view original size


Gravity Simulation - 4.0.0 - Jul 25, 2013
Gravity Simulation - 1.0.0 - Feb 2, 2008 account Comments

If you wish to leave a comment with your account, please sign in first.

July 25, 2013 9:49am - Ian Mallett - nickname: (geometrian)
Version 4.0.0 released (versions 2.0.0/3.0.0 were prerelease and the gravity situation (, which had its own version 2.0.0). I don't even know exactly. Just, this is version 4.0.0 :-)

Completely rewritten, with clean source, more options, better accuracy, and some optimizations. Designed/written for clarity for the beginning-intermediate programmer.
February 7, 2008 7:22pm - Nathan Tornquist - nickname: (petron)
February 3, 2008 1:14pm - pymike - nickname: (pymike)
February 2, 2008 11:01pm - Ian Mallett - nickname: (geometrian)
Who am I to copyright the laws of the universe? Go ahead! Have fun!
February 2, 2008 8:53pm - pymike - nickname: (pymike) - 5/5
Thanks! The code looks fairly simple. Maybe I'll use it! Is that okay?
February 2, 2008 8:38pm - Ian Mallett - nickname: (geometrian)
You'll find the source directly below the .exe link.
February 2, 2008 8:35pm - Ian Mallett - nickname: (geometrian)
Coming up!
February 2, 2008 8:10pm - pymike - nickname: (pymike)
Yea I want a source release! I'm not to good at physics yet... ;-)
February 2, 2008 6:13pm - Ian Mallett - nickname: (geometrian)
It should run slowly at first, but then accelerate. I couldn't get very good speed after about 50 particles. (I've 1.7ghz duo). Of course, the more they clump together, the fewer the calculations, so as the demo progresses, the framerate should increase.

I don't see why you couldn't see the source, but there are really only a few equations you need. Each particle has a position, a speed, and a mass.

Find the gravitational force:
F = (G*M1*M2)/(Distance**2)
G is gravitational constant (I used 1)
M1 is the mass of the first particle
M2 is the mass of the second
Distance is the distance between the two objects' centers of mass.

Then find the acceleration:
A = F/M
A is acceleration.
F is the force you just found.
M is the mass

Then add the acceleration to the speed.

Do this for each particle, and you get the effect.

If you still want to see the (messy) source, I can make a source release. Just say so.
February 2, 2008 6:01pm - Andy Hanson - nickname: (rhodiumgames)
Oops! UPDATE TO MY PREVIOUS COMMENT: it does work. But it runs very very slowly.
Probably just my processor, since it works fine for others.
February 2, 2008 5:54pm - Jordan Trudgett - nickname: (tgfcoder)
Is there a source release? [Okay, obviously there isn't yet. But why not?]
February 2, 2008 5:51pm - pymike - nickname: (pymike) - 5/5
It's cool but how come I can't see the source? I might use your code for a game I'm making. (if that's okay)
February 2, 2008 5:30pm - Ian Mallett - nickname: (geometrian)
Did you see a console window? Does it crash?
February 2, 2008 5:22pm - Andy Hanson - nickname: (rhodiumgames)
It doesn't really work for me. It takes a while to load, then nothing happens.
Sorry I can't be much more help than that.
February 2, 2008 5:08pm - Ian Mallett - nickname: (geometrian)
Version 1.0.0 released!

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Jan 31, 2017

Jan 24, 2017

Jan 19, 2017

Jan 18, 2017

Jan 7, 2017

Dec 30, 2016

Dec 8, 2016

Nov 28, 2016

Nov 27, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)