Skip to main content

A small 2D SPH-style fluid & particle simulation built on pygame.

Project description

dynamic-fluid

A small 2D SPH-style (smoothed-particle hydrodynamics) fluid & particle simulation built on pygame.

Installation

pip install dynamic-fluid

Running the demo

The package ships a runnable demo that spawns a pool of water particles and lets you click-and-drag to blow air at them:

python -m dynamic_fluid
# or, equivalently
dynamic-fluid

Controls:

  • Left click + drag: spawn air particles that push water around
  • Right click: erase nearby air particles
  • Close the window (or press the window's close button) to quit

Using it as a library

import dynamic_fluid as fs

fs.init()
window = fs.display.set_mode((fs.screen_width, fs.screen_bottom))
fs.optimize_game()

fs.create_particle(fs.fluid_type.Water, x=400, y=300)

# in your own game loop:
fs.update_physics(fs.all_particles)
fs.update_particles()
fs.draw_particles(window)
fs.display.update()

Key public API (see dynamic_fluid/__main__.py for a complete usage example):

  • create_particle(fluid_type, x, y) — spawn a Water or Air particle
  • update_physics(all_particles) — advance the SPH physics simulation
  • update_particles() — run each particle's/air's own per-frame update()
  • draw_particles(surface) — draw all particles onto a pygame surface
  • optimize_game() — precompute the soft-circle sprite masks used for drawing
  • fluid_type.Water / fluid_type.Air — the available particle types
  • all_particles / air_particles — the live particle lists

Project layout

pyproject.toml
README.md
LICENSE
dynamic_fluid/
    __init__.py      # public API
    __main__.py       # `python -m dynamic_fluid` / `dynamic-fluid` entry point
    CLASS/            # Particle and Air particle classes
    FUNC/             # physics, config, and helper functions

License

MIT, with the Commons Clause — you're free to use, modify, and distribute this software (including commercially, e.g. inside a paid app or game), but you may not sell the software itself (or a product/service whose value derives substantially from it), and any use must clearly credit Danylo Stoian as the original author. See LICENSE for the full text.

License acceptance

The first time you import dynamic_fluid (or run python -m dynamic_fluid / dynamic-fluid), you'll be asked to type I AGREE to accept the license. Acceptance is remembered afterwards (in ~/.dynamic_fluid/license_accepted), so you're only asked once per machine.

In non-interactive contexts (CI, Docker builds, scripts with no attached terminal), set an environment variable to accept without a prompt:

export DYNAMIC_FLUID_ACCEPT_LICENSE=1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamic_fluid-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamic_fluid-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file dynamic_fluid-0.1.0.tar.gz.

File metadata

  • Download URL: dynamic_fluid-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for dynamic_fluid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ea578a9ff3aab0abcffeb83acf5109d9ba00a2ad4b789af72609c73e0f60cd7b
MD5 79f2c49311da7229be903fd34a055771
BLAKE2b-256 842d5e39eaf81e075d9f5995e3b0b0043595352bd50065e693af01e8536cc3a6

See more details on using hashes here.

File details

Details for the file dynamic_fluid-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dynamic_fluid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for dynamic_fluid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c098f4d37be8013090f9b293da5193f7a2e95296604b3c702cea0cb6f3664328
MD5 fa40a08ffdcc067948a20207bc4d77f2
BLAKE2b-256 f01ecf38e8f7422f893951c6ff5522cf52bfd6b82efd0c059bd141cda86cfcf9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page