# 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):

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:

https://github.com/simon-tiger/gravitational-attraction/blob/master/WorldGenerator.pde

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):