Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

jhaanurag/Soft-Body-Experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Spring-Based Constraint Animation and Softbody in Pygame

This Pygame project is a hands-on exploration of simulating soft body dynamics using spring-based constraints. It provides a visual representation of interconnected points (circles) that react to forces like gravity and user interaction, demonstrating the fundamental principles behind soft body animation.

Features

  • Simple Soft Body Simulation: Visualizes a basic soft body structure formed by interconnected circles.
  • Spring-Based Constraints: The connections between the circles are modeled as springs, applying forces based on their extension or compression.
  • Interactive Central Point: You can drag the central circle with the mouse (left-click and hold) to interact with the soft body in real-time.
  • Gravity Simulation: A basic gravitational force acts on all the circles, causing them to fall and bounce.
  • Border Collision: The circles collide with the screen boundaries, providing a simple form of environmental interaction.
  • Velocity-Based Color Change: The color of the central circle changes based on its vertical velocity, providing visual feedback on its movement.

How to Use

  1. Prerequisites:

    • Ensure you have Python installed on your system.
    • Install the Pygame library:
      pip install pygame
  2. Run the script: Save the provided Python code as a .py file (e.g., test1.py) and run it from your terminal:

    python test1.py
  3. Interact with the simulation:

    • Drag the Center: Press and hold the left mouse button to drag the central blue circle around the screen. Observe how the connected red circles react.
    • Observe the Dynamics: Watch how the circles bounce off the edges of the screen and how the spring forces maintain the shape of the soft body.

Potential Improvements

This is a basic implementation and can be expanded upon in several ways:

  • More Robust Collision Detection: Implement collision detection between the individual circles themselves and with other potential objects.
  • Different Soft Body Structures: Experiment with different arrangements of interconnected circles to create various soft body shapes.
  • Adjustable Spring Parameters: Allow users to modify the spring_constant and damping_factor to observe their effects on the soft body's behavior.
  • External Forces: Introduce other forces like wind or explosions.
  • More Advanced Spring Models: Explore more sophisticated spring models for more realistic or interesting behaviors.
  • Performance Optimization: For more complex soft bodies, optimization techniques might be necessary.

This project provides a starting point for understanding and visualizing spring-based constraint animation and soft body dynamics in Pygame. Feel free to experiment and build upon it!

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages