N-body Gravity

Bodies
0
FPS
–
Time
0.0
Sim speed
–
Steps/s
–
Threads
–
ΔE
–

Recording

How to play

Every body attracts every other body by Newton's law of gravitation. Launch planets, drop in whole scenarios, and watch orbits, collisions and slingshots play out.

Mouse & trackpad

  • Click: add a planet (in a circular orbit when Tap = circular orbit is on)
  • Click, pull back & release: launch it like a slingshot
  • Click a body: inspect it (mass, speed, orbit) and follow or delete it
  • Wheel / pinch: zoom around the cursor
  • Right-drag, middle-drag or Shift-drag: pan

Touch

  • Tap: add a planet (in a circular orbit when Tap = circular orbit is on)
  • Tap, pull back & release: launch it like a slingshot
  • Tap a body: inspect it (mass, speed, orbit) and follow or delete it
  • Two fingers: pan, and pinch to zoom

Toolbar

Keyboard

A
Sound on / off
D
Random scenario and settings
Space
Pause / resume
. or N
Step once
P S
Add a planet / add the next thing in the list
1–9, 0
Load a scenario
R
Fit view
F
Cycle camera follow
+ -
Zoom
[ ]
Slower / faster
C
Remove all bodies
G
Show / hide settings
V
Start / stop recording (video and GIF)
L
Copy a share link
Delete
Delete the selected body
Esc
Cancel aiming / deselect

Under the hood

Choose between Euler, leapfrog (Verlet), Yoshida 4th-order and Runge–Kutta 4 integrators, and exact O(n²) gravity or the Barnes–Hut O(n log n) approximation. Adaptive substeps automatically shrink the time step during close encounters. The ΔE readout shows how well energy is conserved. Physics runs in background threads, using every spare CPU core for big systems, and bodies are drawn with WebGL, so tens of thousands of bodies stay smooth.

Source on GitHub