Skip to content

This repository contains a 2D fluid simulation implemented in Python. Created as a learning project to explore how fluid dynamics can be modeled and visualized in a simple interactive environment.

License

Notifications You must be signed in to change notification settings

coderpeti/2d-fluid-simulation-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fluid Simulation with Hand Tracking

An interactive real-time 2D fluid dynamics simulator built with Python, combining advanced SPH (Smoothed Particle Hydrodynamics) physics, MediaPipe hand tracking, and Pygame visualization.

Overview

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.

Main Functionalities

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)

Preview

Mouse Interaction with Fluid under Earth Gravity Open Hand Interaction with Fluid in Space Fist Interaction with Fluid under Martian Gravity
Mouse Interaction with Fluid under Earth Gravity Open Hand Interaction with Fluid in Space Fist Interaction with Fluid under Martian Gravity

Tech Stack

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

Installation

Option 1 — Using Conda Environment

If you use Conda, you can easily recreate the environment:

conda env create -f environment.yml
conda activate 2d-fluid-simulation

Option 2 — Manual Installation with pip

Alternatively, install the dependencies directly:

pip install -r requirements.txt

Controls

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

License

This project is open-source and available under the MIT License.

Author

Created by: Péter Kóder Email: petercoder.dev@gmail.com GitHub: coderpeti YouTube: @peter_koder

About

This repository contains a 2D fluid simulation implemented in Python. Created as a learning project to explore how fluid dynamics can be modeled and visualized in a simple interactive environment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages