How to play
This is a sandbox for experimenting with orbits. Pick a scene above the view and it starts at once. To add a body, choose a mass, press anywhere in the dark view and drag. The arrow shows the starting direction and speed, and a dashed line predicts the path.
A tap places a body at rest. With Circular orbit ticked, the new body instead gets exactly the sideways speed it needs to circle that body, and dragging only chooses the direction.
Tap a body to see its mass, speed and orbit in the Info panel. Camera follows has three settings: Off, Selected body and Centre of mass. A followed target stays centred and trails are drawn as seen from it, which turns a moon’s wavy path into neat loops around its planet.
Controls
Mouse
- Drag launches a body, a click places one, a click on a body selects it.
- The wheel zooms around the pointer. Drag with the right or middle button, or in Pan mode, to move the view.
Touch
- Drag one finger to launch a body (Add mode) or move the view (Pan mode). Tap a body to select it.
- Pinch to zoom, move two fingers to pan. The page does not scroll while you touch the view.
Keyboard
- Space play or pause, S step, R reset, N select the next body, F follow it, C follow the centre of mass, Delete remove it.
- A Add mode, P Pan mode, + − zoom, 0 fit everything, arrow keys pan when the view has focus.
How the physics works
Every body pulls on every other body according to Newton’s law of gravitation, F = G·m₁·m₂ / r², where r is their distance; with N bodies that is N(N−1)/2 pairs on every step. It uses G = 1 and plain units of length (L), mass (M) and time (T); in the inner planets scene 1 AU = 100 L, the Sun = 1000 M and one year ≈ 199 T. In near misses r² is replaced by r² + ε², where ε is a tiny softening length that avoids enormous forces.
Motion is advanced with the leapfrog method, also called velocity Verlet: half a kick from the current forces, a drift for one time step, new forces, then the second half kick. The step size is fixed per scene; the speed control only changes how many steps run per frame. Leapfrog is symplectic: its energy error wobbles around zero instead of piling up, so orbits stay closed for thousands of turns. Energy drift shows this error as a percentage.
When bodies collide they merge: the masses add up and the new velocity keeps the total momentum exactly the same, while some kinetic energy is lost, as in a real impact. After a merge, and whenever you add or delete a body, the reference energy starts again, so the drift always shows the integrator’s error since the last change.
For a circular orbit, gravity must supply exactly the force that bends the path into a circle, giving the speed v = √(G(M + m) / r). Kepler’s third law follows: T² ∝ a³, which is why outer planets are slower.
The centre of mass (barycentre) is the average position of all bodies, each weighted by its mass: Σ(m·r) / Σm. Gravity between the bodies only trades momentum among them, so for an isolated system the total momentum is conserved and the centre of mass moves in a straight line at constant velocity. Every body, even a heavy star, orbits this point, not the heaviest body itself. Following it removes the overall drift, so a binary star that sails across space draws two closed ellipses. Show centre of mass draws a cross-hair marked CM; the Info panel shows its speed.
Tips and strategy
- Keep moons close. A moon is safe only well inside its planet’s Hill sphere, of radius about a·∛(m / 3M) for a planet of mass m at distance a from a star of mass M; in the Sun, Earth and Moon scene that is roughly 24 L.
- Watch the slingshot. A body passing behind a moving planet is pulled along and speeds up; space probes use this to save fuel.
- Disturb the dance. Add a fourth body near the figure-eight and see how long it survives.
Frequently asked questions
Is the inner solar system to scale?
Orbit sizes, shapes and periods are. Bodies are drawn far larger than life, orbits lie in one plane, and each planet starts at its closest point to the Sun.
Why is the energy drift not exactly zero?
Time steps are finite and numbers are rounded. Leapfrog keeps the error small and bounded; in the presets it stays far below one percent, and bigger values come from very close passes.
What makes the figure-eight special?
Most systems of three bodies are chaotic. In this rare solution three equal masses chase each other along one curve and return to their start after every period. It was found in computer experiments by Cristopher Moore in 1993 and proved to exist by Alain Chenciner and Richard Montgomery in 2000.
How many bodies can I add, and is my scene saved?
Up to 400. Your settings and scene are stored in this browser and restored next time; everything works offline.
More free games
- Game of Life – patterns from simple cell rules.
- Falling Sand – a particle sandbox.
- Flocking Simulator – watch flocks form.
- Double Pendulum – chaos in motion.
- Brick Breaker – bounce a ball through a wall.
- Minesweeper – clear the field with logic.
- 2048 – slide and merge tiles.
- Sudoku – fill the grid.