Skip to content

A simple physics engine built using C and Raylib to simulate the movement and collision of particles under gravity. The simulation evolves through multiple versions, incorporating friction, variable particle sizes, and alpha blending for enhanced realism.

License

Notifications You must be signed in to change notification settings

Assem-ElQersh/Particle-Collision-Simulation

Repository files navigation

🎮 Particle Collision Simulation using Raylib 🚀

A simple physics engine built using C and Raylib to simulate the movement and collision of particles under gravity. The simulation evolves through multiple versions, incorporating friction, variable particle sizes, alpha blending, and interactive playground resizing for enhanced realism.

📌 Features

  • ✔️ Basic particle movement under gravity
  • ✔️ Elastic collisions between particles
  • ✔️ Wall collisions with velocity damping
  • ✔️ Friction force to slow particles over time
  • ✔️ Variable particle sizes for more realistic dynamics
  • ✔️ Alpha blending to simulate fading effects
  • ✔️ Interactive playground with resizable boundaries

🔧 Installation & Setup

1️⃣ Install Raylib

Ensure you have Raylib installed on your system:

Windows (W64Devkit)

# Download w64devkit from https://github.com/skeeto/w64devkit
# Download raylib from https://github.com/raysan5/raylib/releases
# Extract both and copy raylib files to w64devkit directories

Linux (Ubuntu/Debian)

sudo apt install libraylib-dev

macOS (Homebrew)

brew install raylib

2️⃣ Clone the Repository

git clone https://github.com/Assem-ElQersh/Particle-Collision-Simulation.git
cd particle-simulation

3️⃣ Compile & Run

# Using w64devkit terminal:
gcc "interactive version - resizable playground.c" -o interactive_sim.exe -O2 -Wall -Wno-missing-braces -I raylib/raylib-5.0_win64_mingw-w64/include -L raylib/raylib-5.0_win64_mingw-w64/lib -lraylib -lopengl32 -lgdi32 -lwinmm
./interactive_sim.exe

📂 Project Versions

Version Features Added
main.c Basic gravity & collisions
second version - added friction force.c Introduced friction for damping
third version - support particles of different sizes.c Added variable particle sizes
fourth version - alpha blending.c Implemented alpha transparency for fading effect
interactive version - resizable playground.c Added interactive playground with draggable boundaries

🎮 Interactive Version Features

  • ✔️ Draggable boundaries to resize the playground
  • ✔️ Real-time physics adjustment to new boundaries
  • ✔️ Visual feedback with yellow boundary lines
  • ✔️ Smooth particle transitions when resizing

🎯 Future Improvements

  • Optimize performance using QuadTree spatial partitioning
  • ✅ Implement inelastic collisions for more realism
  • ✅ Add particle creation with mouse clicks
  • ✅ Use multithreading (OpenMP) to improve efficiency
  • ✅ Add save/load playground configurations

📜 License

This project is licensed under the MIT License. Feel free to use and modify it!

About

A simple physics engine built using C and Raylib to simulate the movement and collision of particles under gravity. The simulation evolves through multiple versions, incorporating friction, variable particle sizes, and alpha blending for enhanced realism.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages