A Python program that simulates balls bouncing with realistic physics, featuring an explosive chain reaction system where balls split into multiple smaller balls when they hit surfaces.
- Realistic gravity physics with bounce effects
- Explosive chain reactions - balls split into smaller balls on impact
- Colorful visual effects - each explosion creates balls of different colors
- Progressive ball splitting - larger balls create more smaller balls
- Performance optimization - limits total balls to prevent lag
- Real-time ball counter and position display
- Interactive controls for resetting the simulation
-
Make sure you have Python 3.11+ installed
-
Install the required dependencies:
pip install -r requirements.txt
python bouncing_ball.py
- SPACE: Reset to a single ball
- ESC: Quit the program
- Close window: Exit the program
You can modify these constants in the code to change the behavior:
GRAVITY = 0.5
: Strength of gravity (pixels per frame squared)BOUNCE_FACTOR = 0.8
: Energy retention on bounce (0.0 to 1.0)FRICTION = 0.99
: Air resistance factor (0.0 to 1.0)SPLASH_COUNT = 8
: Number of balls created per explosionSPLASH_VELOCITY = 8
: Initial velocity of explosion ballsMIN_BALL_RADIUS = 3
: Minimum size before balls stop exploding
- Initial Ball: Starts as a large red ball at the top
- First Impact: When the ball hits the ground with sufficient velocity, it explodes
- Chain Reaction: Each explosion creates 8 smaller balls in different colors
- Progressive Splitting: Larger balls create more dramatic explosions
- Size Limit: Balls smaller than 6 pixels radius stop exploding
- Performance: System limits to 100 balls maximum to maintain smooth performance
- Color Variety: Explosions create balls in red, blue, green, orange, purple, and yellow
- Size Scaling: Explosion velocity scales with the original ball's size
- Random Distribution: Balls explode in a circular pattern with slight randomness
- Real-time Stats: Shows current ball count and main ball position
The program uses realistic physics including:
- Gravity: Continuous downward acceleration
- Collision Detection: Bounces off all window boundaries
- Energy Conservation: Bounce factor reduces energy on each collision
- Friction: Air resistance gradually slows movement
- Explosion Physics: Momentum conservation in splash patterns
Watch as a single ball creates a spectacular chain reaction of colorful explosions!