An interactive real-time 2D fluid dynamics simulator built with Python, combining advanced SPH (Smoothed Particle Hydrodynamics) physics, MediaPipe hand tracking, and Pygame visualization.
This project demonstrates a high-performance particle-based fluid simulation with real-time gesture control. It allows you to interact with simulated water using hand gestures, such as grabbing, stirring, or pushing fluid particles.
Simulation Core
- Implements PCISPH (Predictive-Corrective Incompressible SPH) algorithm
- Realistic fluid pressure, surface tension, viscosity, and vorticity confinement
- Adaptive time step integration for stability
Gesture Control
- Uses MediaPipe Hands via OpenCV to track hands and finger positions
- Left or right hand can interact dynamically with the liquid surface
- Detects open palms vs. fists
Graphics & Interaction
- Rendered in real time with Pygame
- Mouse and hand gesture input supported
- On-screen gravity mode buttons (Earth / Mars / Space)
| Mouse Interaction with Fluid under Earth Gravity | Open Hand Interaction with Fluid in Space | Fist Interaction with Fluid under Martian Gravity |
|---|---|---|
![]() |
![]() |
![]() |
| Category | Technologies |
|---|---|
| Language | Python 3.10+ |
| Simulation Engine | NumPy, Numba (for JIT acceleration), mathematical fluid modeling |
| Computer Vision | OpenCV, MediaPipe Hands |
| Graphics & UI | Pygame |
| Physics Model | SPH / PCISPH algorithms, surface tension, viscosity, adaptive CFL time step |
If you use Conda, you can easily recreate the environment:
conda env create -f environment.yml
conda activate 2d-fluid-simulationAlternatively, install the dependencies directly:
pip install -r requirements.txt| Action | Description |
|---|---|
| Left Mouse Drag | Push or pull nearby fluid particles |
| Left / Right Fist | Grab and move particles in the fluid |
| Open Hand | Stir or splash the liquid |
| Keys 1 / 2 / 3 | Switch gravity between Earth / Mars / Space |
| ESC | Exit the program |
This project is open-source and available under the MIT License.
Created by: Péter Kóder Email: petercoder.dev@gmail.com GitHub: coderpeti YouTube: @peter_koder


