Toyful and simple 2D N-body simulation of gravitational systems written in C. Handles collisions and provides fun interactions you can play with. It implements the Barnes-Hut approximation algorithm for N-body simulations through the use of a QuadTree data structure, spatialy accelerating collisions and gravity calculations. It runs single threaded and does all computations on the CPU side, even the rendering. Built on top of my rendering engine, the simple pixel engine.
Click and drag the mouse on top of the background to move the camera. Click and drag on the bodies to move them.
Key | Action |
---|---|
W | Move camera up |
S | Move camera down |
D | Move camera to the right |
A | Move camera to the left |
Z | Zoom in |
X | Zoom out |
O | Decrease size of physics time step, slow down time |
P | Increase size of physics time step, speed up time |
G | Turn gravity on and off |
Q | Switch the rendering of the quadtree on and off |
LShift | Switch the rendering of trails on and off |
Space | Pause the time of the physics in the simulation |
R | Restart the simulation |
Escape | Quit |
spxe depends on OpenGL libraries to manage windows and render graphics independently of the platform.
If you have all third party dependencies installed on your system you can easily try gsim with the following commands:
git clone --recursive https://github.com/LogicEu/gsim.git
cd gsim
make # or ./build.sh
./gsim -help
Both build script currently work on Linux an MacOS. The compiled binary will be created at the root of the repository.
make # or ./build.sh
Make sure to clean after compiling.
make clean # or ./build.sh clean