Barnes-Hut Simulation

This is a simulation of 1000 point mass particles interacting through gravity using the Barnes-Hut algorithm in pure javascript.


You can pan by dragging with your mouse, and zoom by scrolling with your mouse wheel. If you're on a touch device you can pan & zoom in the standard way.


The threshold input determines how accurate/expensive the simulation is. How higher the threshold is, the more the gravity calculations will be approximated, and how less computationally expensive the simulation will be. This amount is determined on every step of the simulation, and can be seen below. If the threshold is set to 0 the simulation is 100% accurate. The time step and gravity constant of the simulation can also be changed below. A higher time step translates to a faster but more approximative simulation. If it is set too high the simulation can even become unstable!