Skip to content

Omanand10/Simblackhole

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

🌌 Black Hole Simulation (C++ + Raylib)

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.

🚀 Features

  • 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

🖥️ Preview

  • 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

📂 Project Structure

BlackHoleSimulation/
│── main.cpp          # Main simulation code
│── README.md          # Documentation

⚙️ Requirements

  • C++ compiler (g++, clang++, MSVC, etc.)
  • Raylib graphics library

🛠️ Installation & Setup

🪟 Windows Setup

Option 1: MSYS2 + MinGW (Recommended)

  1. Download and install MSYS2https://www.msys2.org/

  2. Open MSYS2 MinGW 64-bit terminal

  3. Update packages:

    pacman -Syu

    (Close and reopen the terminal if asked)

  4. Install Raylib:

    pacman -S mingw-w64-x86_64-raylib
  5. Compile and run:

    g++ main.cpp -o blackhole -lraylib -lopengl32 -lgdi32 -lwinmm
    ./blackhole

Option 2: Visual Studio (MSVC)

  1. Download precompiled Raylib binaries from: https://github.com/raysan5/raylib/releases
  2. Extract to a folder, e.g., C:\raylib
  3. In Visual Studio:
    • Add C:\raylib\include to Include Directories
    • Add C:\raylib\lib to Library Directories
    • Under Linker → Input → Additional Dependencies, add:
      raylib.lib
      opengl32.lib
      gdi32.lib
      winmm.lib
      

🐧 Linux Setup

  1. Install Raylib:

    sudo apt install libraylib-dev
  2. Compile and run:

    g++ main.cpp -o blackhole -lraylib -lm
    ./blackhole

🍎 macOS Setup

  1. Install Raylib using Homebrew:

    brew install raylib
  2. Compile and run:

    g++ main.cpp -o blackhole -lraylib -framework OpenGL
    ./blackhole

🧠 Concepts Demonstrated

  • 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

✨ Future Improvements

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

🎮 Controls

  • ESC - Exit simulation

📜 License

This project is open source. Feel free to modify and distribute.


Enjoy exploring the fascinating physics of black holes! 🌠

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages