Sandbox Solar System

A vanilla JavaScript gravity sandbox. Every body pulls on every other body at once — planets fall into orbit, moons keep their planet, comets slingshot past and sometimes escape for good.

Left drag: launch a new body from that spot (drag length sets its speed, drag direction sets its course) · wheel or Zoom +/−: zoom · Space or the pause button: freeze time · when paused, click a body to select it

Environment: pick a scenario (solar system, binary star, figure-8 three-body, chaotic cluster, comet shower) and Load it · Export/Import saves the whole system as JSON · Camera buttons zoom, reset the view, centre on the star, or lock the camera to the selected body · Step frame advances one physics step while paused · speed presets jump time to 0.25×, 1× or 4×.


1.00
1.00x
3
90

Scenario

Spawn

14
50

Camera

Time

Bodies: 0
FPS: —
Simulated: 0.0 yr
Drag out a vector and the body leaves at the speed the arrow shows. Small bodies are lighter than they look — a planet of radius 13 pulls far less than the sun, so a moon orbits its planet easily and a comet on a wide path barely notices the planets at all.

Rules: every pair of bodies attracts with F = G · m₁ · m₂ / r² · the step is split into substeps of semi-implicit Euler, so orbits hold instead of spiralling in · bodies that touch merge into one, keeping the heavier body and conserving momentum · the star is pinned at the centre so the whole system cannot drift off the canvas · bodies that leave the view are removed once they stop coming back · trails are drawn on a fading overlay, so motion reads as arcs instead of dots

Units are not real-world: the star starts at 50,000 mass and a planet 140 units out completes an orbit in about 64 simulated seconds at time speed 1.0, which keeps a comfortable orbit near the canvas centre at launch power 50. Gravity, time speed and substeps are all live — crank the time speed and the system runs like a timelapse; drop it to 0.1x and you can watch a single moon wobble.