Gravity Toy


The parent blog about this script is found here.

  • Click and drag to add gravity bodies
  • Spacebar - pause the simulation
  • Backspace - reset the simulation
  • [Shift-click] to center the viewport on a single body
  • - / + - zoom in and out
  • Up / Down - change mass
  • Left / Right - change simulation speed
  • [ / ] - change accuracy of solver
  • w - toggle the barrier at the edge of the screen
  • q - normalize the view-radius of the circles
  • t - toggle trails
  • r / y - change duration of trails
  • s - spawn system
  • a / d - cycle through the systems

Hit the "Source" button to edit and run your own version of the code.
Any changes will be reset upon page refresh.

Source