Overview
This is a p5.js sketch inspired by the Coding Train’s Coding Challenge #7 of creating a Solar System.
It makes use of Newton’s Law of Gravitation:
F = G * m1 * m2 / (r * r)
Additionally, it uses values for Mass and Radii based on actual values for the masses of the planets in our solar system.
And, after randomly placing the masses, it determines what their approximate orbital velocity based by determining the speed that would generate a Centripetal Force equal to the gravitational force at that distance.
Caveat: The objects only experience the gravitational attraction of the “sun” at the center; which in turn does not experience any gravitational force. This allows for a stable system, but lacks the interplay of forces in a true n-body simulation.
Controls
(No interactivity implemented yet).