Skip to content
Snippets Groups Projects

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.

TODO:

  • 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.