Gravitation Particles
A Barnes-Hut implementation of n-body gravitation simulation in Rust.
Running the project
The video rendering feature is implemented using the ffmpeg
, so you will need that installed. Assuming you also have cargo
installed, all you need to run a project is simply:
cargo run
Usage
Usage is pretty simple:
-
In
consts.rs
you can adjust window and world resolution as well as some other params -
In
main.rs
you can create "galaxies" using thecreate_galaxy()
function or by just inserting particles into particles vector -
After program is in run, you can see fps in the window title
-
To start rendering record you need to press
R
on your keyboard and thenS
to stop the record. After the recording process is stopped, video will be automatically created from screenshot images and saved intoresults
folder in the project root directory -
To move around the canvas you can use mouse scroll wheel to zoom in/out and hover cursor onto the edges of the window to move around
Algorithm
The Barnes-Hut algorithm is a way of optimizing n-body simulations. It allows to group particles into groups if they're enough far away to be considered as a single object. The complexity of this algorithm is O(n log(n)) compared to a Direct algorithm which complexity is O(n2)