IS
All experiments
wip

Orbit Sandbox — toy gravity in your browser

Drop bodies, give them a flick, and watch n-body gravity pull them into orbits, slingshots and collisions. A tiny nod to Universe Sandbox.

lab note
Why I built it

Universe Sandbox is my comfort software. I wanted to feel out how much of that 'poke the universe' joy survives in a 200-line canvas toy with naive gravity.

What I learned

Naive O(n²) gravity is totally fine up to a few hundred bodies at 60fps. The hard part isn't the physics — it's a stable integrator. Plain Euler explodes; semi-implicit Euler stays calm.

Where it broke

With plain Euler, two close bodies gain infinite energy and rocket off-screen. Softening the distance (adding an epsilon so r never hits zero) plus semi-implicit integration fixed the fireworks.

Stack
Canvas 2DTypeScriptrequestAnimationFrame

Poke the universe

Click empty space to drop a body. Click-drag to fling it with velocity. Everything attracts everything — so small clusters fall into orbits, and near-misses turn into slingshots.

live demo
Loading demo…

This one is marked wip on purpose: the integrator is stable but there's no collision merging yet, and I want to add mass-by-drag-radius next. That's the point of a lab note — showing the seams, not hiding them.

Orbit Sandbox — toy gravity in your browser — Lab