This project implements a deterministic 2D physics simulation where multiple balls move, collide, and bounce off boundaries, eventually revealing an uploaded image as their colors map to the pixels of the image.
- Deterministic Physics Engine: Uses Verlet integration for accurate motion simulation.
- Gravity & Collisions: Balls are affected by gravity, bounce off walls, and collide with each other.
- Image Reveal: Balls take colors from an uploaded image, forming a near pixel-perfect representation over time.
- Optimized Collision Handling: Uses spatial hashing to reduce computational overhead for collisions.
- CSV-based Ball Tracking: Ball positions and states are recorded in
ball_spawns.csvfor deterministic replay. - Customizable Parameters: Easily adjust gravity, ball radius, spawn rate, number of objects, and simulation steps.
- Fast Calculation Phase: Precomputes ball positions for smooth real-time display.
- Python 3.10+
- Pygame
- Pillow (PIL)
- Tkinter (for image file selection, usually included with Python)
Install required packages: pip install pygame pillow
How to run? Open Command Prompt or Windows Powershell and install the required dependencies. Then run python bouncing_balls.py to see the magic in action.
Note: View the created final image from afar for best results