An interactive physics simulation of a pendulum in different environments (Air, Water, and Vacuum) using Python and Pygame.
This project simulates a simple pendulum's motion in three different environments, demonstrating key physics concepts such as:
- Simple harmonic motion
- Damping effects in different media
- Energy conservation and transformation
- Interactive physics manipulation
- Multiple Environments:
- Air: Slight damping (0.999)
- Water: Significant damping (0.95)
- Vacuum: No damping (1.0)
- Interactive Controls:
- Click and drag to manipulate the pendulum
- Adjust pendulum length using arrow keys
- Reset pendulum position with spacebar
- Switch environments using number keys (1, 2, 3)
- Real-time Physics:
- Accurate pendulum motion simulation
- Visual trail of pendulum movement
- Environment-specific visual effects
- Visual Feedback:
- Real-time angle and velocity display
- Environment-specific backgrounds
- Pressure gauge in vacuum mode
- Water surface effects in water mode
The pendulum follows the classic simple pendulum equation:
θ'' = -(g/L)sin(θ)
where:
- θ is the angle of displacement
- g is gravitational acceleration (9.81 m/s²)
- L is the length of the pendulum
The simulation models different levels of energy loss:
- Air: Very slight damping (0.999)
- Water: Significant damping (0.95)
- Vacuum: No damping (1.0)
The pendulum continuously converts between:
- Potential Energy: U = mgh = mgL(1 - cos(θ))
- Kinetic Energy: K = ½mv² = ½mL²ω²
- Ensure you have Python 3.x installed
- Install required packages:
pip install pygameRun the simulation:
python main.py- 1: Switch to Air environment
- 2: Switch to Water environment
- 3: Switch to Vacuum environment
- Left/Right Arrow: Adjust pendulum length
- Space: Reset pendulum position
- Mouse: Click and drag to manipulate pendulum
- ESC: Quit simulation
main.py: Main simulation loop and user interfacependulum.py: Pendulum physics implementationdecoration.py: Visual effects and environment renderingconstants.py: Simulation constants and configuration
- The damping coefficients are simplified models and not based on actual experimental data
- The simulation uses basic Euler integration for physics calculations
- Air and water resistance are modeled using simplified damping factors
- Pygame library for graphics and user input handling
- Physics principles based on classical mechanics
- Inspired by educational physics simulations