Gravity Simulator v1.0

This project actually grew out of a demo I did for my students in Governor’s School, now it’s basically a zero-player video game (meaning, you set it up, and then watch it). It has a lot of cool features which I’ll try to go through here. Each frame solves the gravity differential equations describing the system using the Euler Method (aka, it just assumes it’s linear for a small interval). Presently it’s set to calculate 250 steps each frame. The model for gravity employed by this simulation is ∝ 1/r^2. Objects are non-corporeal (meaning they can freely pass through one another), however they are assumed to have a uniform density. Therefore when one object is inside another the force ∝r. Where r means the distance between the centers of the two objects. Basically, when an object is inside another the simulation assumes it feels gravity only from the shells that lie “bellow” it, so gravity will be zero at the center of any object. For more about this read up on Gauss’ Law for Gravity.

There’s an interactive method for creating a simulation from scratch, as well as a bunch of premade simulations that I wrote which are fun to watch. To place objects is a 3-step process. First you click where on the screen you want the object to start the simulation, next two buttons appear that will make the object larger or smaller, next you click anywhere else on the screen to set the object’s initial velocity vector. At any time you can click the lower righthand corner and stop placing objects and start the simulation, if an object is being placed when you do this it will be discarded.

At any time (except at the main menu) you can click the lower lefthand corner and abort back to the main menu. Your toggle choices are left as they were in this case.

Here’s the rundown on the “Toggle Options” you get:

CoM Centering

By default the simulation is played in the “Center of Mass” frame, meaning that the center of the screen or the center of mass of the system. The Center of Mass is defined to be the point where the “weighted relative position” of the masses sums to zero. Put another way, were the simulation a rigid object this is the point at which the whole thing would balance. This can be turned off (but then if the objects fly off the screen that’s your problem).

Object Paths

This records the last 100 frames’ positions for each object in the simulation, and displays a curve corresponding to lines joining them. For really small objects you kind of want this on, or else you won’t actually see what they’re doing.

Orbit Projection

Enabling this option projects the NEXT 100 frames when placing an object. This is done by ACTUALLY running the simulation ahead, so it can be quite costly. This doesn’t really work effectively for more than about 12 object. The projection will appear on the step wherein you choose the object’s initial velocity.

Manual Coloring

By default the color of an object is determined by its size in a way that is intended to be suggestive of the real solar system. Enabling this option produces a color wheel before the initial position step for a new object where you can click the color you want the new object to be. The color wheel was adapted from some code by Shanfan Huang whose website is here and whose OpenProcessing portfolio is here used under the terms of the GPL.