This project is an interactive spring-mass simulation built with Python and matplotlib.
You can dynamically adjust spring stiffness, mass, damping, and maximum stretch using sliders, and watch the mass respond in real time!
-
Interactive sliders for adjusting:
- Spring stiffness (
k) in N/m - Mass (
m) in kg - Damping coefficient (
b) in kg/s - Maximum spring extension (
xmax) in meters
- Spring stiffness (
-
Real-time animation of spring and mass
-
Visual indication of spring breaking (changes color to red)
-
Smooth simulation with gravity and optional damping
-
Reset on parameter change
- Clone the repository:
git clone https://github.com/IbrokhimN/Spring-Mass-System-Simulation.git
cd Spring-Mass-System-Simulation- Install required packages:
pip install numpy matplotlib scipyRun the simulation:
python physic_project.py- Adjust the sliders to change parameters on the fly.
- Watch the mass oscillate or fall if the spring breaks.
- The system simulates a spring-mass-damper under gravity:
-
solve_ivpfromscipycomputes the motion. -
Animation updates spring shape and mass position in real time.
-
The spring breaks if:
|x| > xmaxork * |x| > k_max * xmax
- Add reset button to instantly reset the simulation.
- Enable multiple masses on one spring.
- Export animation as GIF or video.
- Add energy graphs (kinetic, potential).
This project is licensed under the MIT License – see the LICENSE file for details.
