Gravity

This is a gravity simulation that I wrote for the Java portion of a four-language computer course: lisp, ML, Prolog, and Java. This applet suffers the same ailments as the Java flocking with obstacles applet, namely: poor randomization, no screen double-buffering, and gui components that disappear when the mouse moves over them. However, the physics model works pretty well. What you see are a number of planetoids. These planetoids have a given mass, denoted by each circle's size. The standard gravitational one-over-distance-squared algorithm is used to determine the universal gravitational force acting on each planetoid. This algorithm must run in N-squared time as a result. The force felt by each planetoid is visualized in its color. Black is minimal, then red, green, yellow, cyan, and finally blue, signifying tremendous force. As planetoids collide, the power of the collision is measured as a product of the sum of the masses of the two planetoids and the square of the impact velocity. If this power is less than a certain amount relative to the larger planetoid's mass, both planetoids merge into a larger planetoid. If the power is greater than the magical cutoff however, both planetoids are vaporized into a cloud that may settle back into a solid body, or may disperse.

A quick rundown of the GUI components:

  • Speed: animation speed
  • Gravity: the gravitational constant
  • Cohesion: that magical collision cutoff the separates merging from dividing
  • Dispersal: initial dispersal configuration
  • Initial Velocity: this applies to each planetoid when Restart is pressed
  • Restart: start over
  • Quit: end the simulation

If the mouse is pressed while inside the map, the planetoid that is nearest the mouse becomes an anchor in the middle of the map. This does not affect the gravitational equation at all. It simply "visually" achors that planetoid at the center. Clicking near another planetoid picks a new anchor, clicking near the anchor "releases" it.

Be sure to check out the other Java simulation I wrote as part of the same assignment, Flock with Obstacles.

ALT= "Applet could not be loaded" Sorry, it is time to upgrade your browser to a Java powered one.