A Barnes-Hut implementation of n-body gravitation simulation in Rust.
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 runUsage is pretty simple:
-
In
consts.rsyou can adjust window and world resolution as well as some other params -
In
main.rsyou can create "galaxies" using thecreate_galaxy()orspawn_circle()functions 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
Ron your keyboard and thenSto stop the record. After the recording process is stopped, video will be automatically created from screenshot images and saved intoresultsfolder 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
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)
