This project performs physics-based rope simulation using Verlet integration. Users can interactively move the rope, adjust gravity, and damping settings.
- Verlet Integration: Uses Verlet integration for realistic physics simulation.
- Interactive Usage: Drag and drop rope segments with the mouse.
- Real-time Adjustments: Adjust gravity, damping, segment count, and segment length in real-time.
- Camera System: Zoom in/out and pan (camera movement) features.
- Interactive Interface: Easy control with sliders and buttons.
| Technology | Version | Description |
|---|---|---|
| Python | 3.14 |
Main programming language |
| Pygame | 2.6.1 |
2D graphics, game loop, and user interface |
rope_sim/
├── src/
│ ├── main.py # Main entry point and game loop
│ ├── requirements.txt # Dependencies (pygame==2.6.1)
│ ├── rope.py # Rope class (Verlet integration)
│ ├── physics/
│ │ ├── __init__.py
│ │ ├── particle.py # Particle (mass) class
│ │ └── constraint.py # Constraint (distance constraint) class
│ └── gui/
│ ├── __init__.py
│ └── gui.py # User interface classes
└── venv/ # Python virtual environment
- Clone the repository
git clone <repourl>
cd rope_sim- Create and activate virtual environment
python -m venv venv
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windows- Install dependencies
cd src
pip install -r requirements.txtcd src
python main.py| Key | Function |
|---|---|
SPACE |
Start/Stop simulation |
R |
Reset rope |
ESC |
Exit |
+ / Kp+ |
Zoom in |
- |
Zoom out |
Drag |
Move rope segments |
- Reset Rope: Reset rope to initial position
- Gravity Slider: Gravity force (0.1 - 2.5)
- Damping Slider: Damping coefficient (0.85 - 1.0)
- Segments Slider: Number of segments (2 - 5000)
- Segment Length Slider: Length of each segment (15 - 187)
- Zoom +/-/Reset: Camera zoom controls
The project uses Verlet integration for physics simulation:
v = (current_pos - old_pos) * damping
new_pos = current_pos + v + gravity * dt²
This method provides numerical stability and helps rope-like flexible structures appear realistic.
-
Particle
- Represents a mass
- Stores position, velocity, and mass information
is_fixed: Is this a fixed point?is_being_dragged: Is the user dragging it?
-
Constraint
- Maintains distance between two particles
- Controls flexibility with stiffness parameter
- Iterative solving for stability
-
Rope
- Combines particles and constraints
update(): Physics updatedraw(): Screen drawingdrag_particle(): Mouse interaction
-
Camera
- Zoom and pan operations
- World coordinates ↔ Screen coordinates transformation
The simulation screen includes:
- Background: Grid system
- Rope: White particles and gray segments
- UI Panel: Parameter controls in the top-right corner
- Info Panel: Real-time simulation statistics
Note: This is an educational physics simulation project written with the Pygame library.
Vibe Coding Note: This project was developed in approximately 2 hours of vibe coding.