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×.
Scenario
Spawn
Camera
Time
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.