Gravitational Attraction (World Generator in Java). Simon’s new own code!

Simon has come up with a new code of his own! It’s about gravitational attraction (particles attracted to targets or moons attracted to planets) and partially based upon the Box2D library but he wrote most of the code himself. Simon used the gravitational constant and Newton’s law of universal gravitation to build this project. The law states that every point mass (m1) attracts every single other point mass (m2by a force (F) pointing along the line intersecting both points. The force is proportional to the product of the two masses and inversely proportional to the square of the distance between them (r):
F=G{\frac {m_{1}m_{2}}{r^{2}}}\

Simon had come across this formula before in Daniel Shiffman’s tutorials and just like Daniel he changed r to d (for distance):

float strength = (G * 1 * p.mass) / (distance * distance);

Simon pushed his full code to GitHub at:

Here Simon added some new features, like pressing keys for adding new targets and particles:

Here the force is becoming stronger with more targets, Simon explains:

We’ve also got a video of Simon talking about this project in Dutch (showing it to his math teacher):


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s