Gravity Sandbox
An N-body gravity simulator with planets, colliding galaxies and the figure-eight three-body orbit.
- Body, one color each
- Body of mass 50 or more
- Weightless star
- Weightless star, thrown
- Recent path of a body
Drag on space to launch a new body or star cloud; the dashed line previews its orbit, and Rerun starts again from t = 0 with what you launched. Scroll to zoom, right-drag (or the Pan tool) to move around. The galaxy collision preset shows tidal tails forming.
How is Gravity Sandbox working for you?
About Gravity Sandbox
Gravity Sandbox is a free N-body simulator that runs in your browser. Up to 300 massive bodies — suns, planets, black holes — pull on each other with Newton's law of gravitation, while up to 20,000 weightless stars and asteroids feel the bodies' gravity without pulling back. That split lets you watch whole galaxies, asteroid belts and accretion disks move at full speed.
Orbits are integrated with the leapfrog (kick-drift-kick) method, a symplectic scheme that keeps planets on stable orbits for a very long time; the readout shows how little the total energy changes. A small softening length keeps close encounters well behaved, and bodies that collide merge into one, conserving mass and momentum.
Start from the Solar system, Binary stars, the famous figure-eight three-body orbit discovered by Cris Moore and proven by Alain Chenciner and Richard Montgomery, a Galaxy collision that throws out long tidal tails, or an Accretion disk where gas drag spirals matter inward. Drag to launch new bodies — a dashed line previews their path — throw clouds of stars, zoom and pan, follow the center of mass, and export a 4K PNG or a video or GIF.
How to use Gravity Sandbox
- Pick a preset. Choose Solar system, Binary stars, Figure-eight three-body, Galaxy collision, Accretion disk or Empty space.
- Launch a body. With Launch body selected, press on empty space and drag: the launch point becomes the new body and the drag sets its velocity. The dashed line predicts its orbit before you let go. Set its mass with New body mass.
- Throw stars. Switch to Throw stars and drag to launch a cloud of 300 test stars that orbit whatever is nearby. Rerun starts the preset again from t = 0 with every body and cloud you launched, from where and how fast you threw it; Restart clears them and starts the preset again; Reset also returns every setting to its default.
- Navigate. Scroll or use + and − to zoom, and right-drag or use the Pan tool to move. Follow center of mass keeps the system centered.
- Change the pace. Speed runs more integration steps per frame; Trails draws each body's recent path; Gas drag slowly steals energy from stars so they spiral in.
- Export. Save a PNG up to 4096 px or record a video or GIF of the motion. Record 30 s from the start runs the same setup again from the beginning and records its first 30 seconds, frame by frame.
Frequently asked questions
What is the N-body problem?
It is the problem of predicting how a group of objects moves under their mutual gravity. Two bodies follow simple ellipses, as Kepler and Newton showed, but three or more generally have no closed-form solution and can behave chaotically, so astronomers simulate them numerically, as this tool does.
What is the figure-eight orbit?
It is a periodic solution of the three-body problem in which three equal masses chase each other around a figure-eight curve. Cris Moore found it numerically in 1993, and Alain Chenciner and Richard Montgomery proved its existence in 2000. It is stable enough to watch for many loops, but tiny errors eventually break it apart.
Why do galaxies grow tails when they collide?
During a close pass, each galaxy's gravity pulls harder on the near side of the other than on the far side. These tidal forces pull stars out into long curving tails and bridges, as Alar and Juri Toomre showed with early computer simulations in 1972. The Antennae and Mice galaxies are real examples.
Why do the stars not affect each other?
Computing every star's pull on every other star would be far too slow for a browser at this scale. Treating stars as massless 'test particles' that only feel the massive bodies is a standard approximation that still reproduces orbits, rings, tidal tails and disks.
How accurate is the simulation?
Leapfrog integration conserves energy very well for orbits like the solar-system preset, and the readout shows the change in total energy. Softening (a small minimum distance in the force law) and merging on contact trade a little realism for stability during close encounters.





