You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Stephen Downward 74a46b1116 Save every frame 1 year ago
Cout-2.mp4 Example simulations 1 year ago
Cout.mp4 Example simulations 1 year ago
Makefile Engine changes for readability and possibly 3D in the future 1 year ago Saving/loading 1 year ago
collide.c Collision catalyst handles stars with NAN coords/velocities 1 year ago
engine.c Engine changes for readability and possibly 3D in the future 1 year ago
engine.h MASSIVE performance improvement(barnes hut algorithm), better colours when converting to img 1 year ago
main.c Save every frame 1 year ago
qdbmp.c first commit 1 year ago
qdbmp.h first commit 1 year ago

C Gravitational Engine

Simulates a large array of stars in a galaxy. The amount is configurable, as well as various other parameters. They start with some angular momentum. It’s pretty fast, but it can probably be optimized further.

The engine features full multithreading support when calculating forces.

10 iterations(configurable) are added together for each frame. This allows the paths and velocities of the different stars to be easily seen.


  • Automatic video processing - Export X frames, turn them into a video, delete the frames. Repeat until the simulation is done, and then stick the videos together. At the moment, a long simulation can take hundreds of GB to store all of the images.

  • Allow processing over a distributed set of computers

Sample footage

I have included some simulations that were previously generated using my engine. These took minutes, rather than the hours that would have been required with the python version of the engine, which I wrote the day before.

Cout.mp4 - 1k stars. Already, a clump of stars can be seen easily, and seems to be stable.

Cout-2.mp4 - 10k stars. This is my favourite so far! It is starting to act like a proper galaxy. Near the beginning, 2 galaxies are created by chance. The smaller one gets attracted towards the larger one, and is ripped apart from the gravitaional forces! Before this, the larger galaxy exhibits some properties of a spiral galaxy for a very short time. I believe that adding more stars will make it more stable, as they will be able to come together to form a ‘black hole’ in the center.