This project is a black hole gravity simulation written in C++ using the Raylib graphics library. It simulates how stars move when affected by the immense gravitational pull of a black hole, showing the event horizon, accretion disk, and dynamic star movement.
- Simulates gravitational attraction of a black hole at the center of the screen
- Stars are randomly generated with initial velocities
- Stars can orbit, spiral inward, or escape depending on their speed
- Stars crossing the event horizon are absorbed (removed from the system)
- Accretion disk effect around the black hole for visual realism
- Labels for Event Horizon and Accretion Disk
- The black hole is shown at the center with a glowing accretion disk
- Stars are drawn as white pixels moving dynamically
- Event horizon and labels make the simulation more informative
BlackHoleSimulation/
│── main.cpp # Main simulation code
│── README.md # Documentation
- C++ compiler (g++, clang++, MSVC, etc.)
- Raylib graphics library
-
Download and install MSYS2 → https://www.msys2.org/
-
Open MSYS2 MinGW 64-bit terminal
-
Update packages:
pacman -Syu
(Close and reopen the terminal if asked)
-
Install Raylib:
pacman -S mingw-w64-x86_64-raylib
-
Compile and run:
g++ main.cpp -o blackhole -lraylib -lopengl32 -lgdi32 -lwinmm ./blackhole
- Download precompiled Raylib binaries from: https://github.com/raysan5/raylib/releases
- Extract to a folder, e.g.,
C:\raylib - In Visual Studio:
- Add
C:\raylib\includeto Include Directories - Add
C:\raylib\libto Library Directories - Under Linker → Input → Additional Dependencies, add:
raylib.lib opengl32.lib gdi32.lib winmm.lib
- Add
-
Install Raylib:
sudo apt install libraylib-dev
-
Compile and run:
g++ main.cpp -o blackhole -lraylib -lm ./blackhole
-
Install Raylib using Homebrew:
brew install raylib
-
Compile and run:
g++ main.cpp -o blackhole -lraylib -framework OpenGL ./blackhole
- Gravitational force simulation with Newton's law of gravitation
- Vector math for acceleration, velocity, and position updates
- Event horizon mechanics: stars crossing the boundary are absorbed
- Real-time graphics with Raylib: rendering stars, circles, and text labels
- Physics simulation with time-based updates
- Add color variation for stars based on temperature/velocity
- Implement relativistic orbit curves for accuracy
- Add camera zoom/pan controls for better viewing
- Show star trails for enhanced visual appeal
- Add gravitational lensing effects
- Implement different types of celestial objects (planets, asteroids)
- ESC - Exit simulation
This project is open source. Feel free to modify and distribute.
Enjoy exploring the fascinating physics of black holes! 🌠