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

from dynamic_fluid import*

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

create_particle(fluid_type.Water, 400, 300)

# in your own game loop:
update_physics(all_particles)
update_particles()
draw_particles(window)
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.1.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.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic_fluid-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 376afbeea8093d978febdf8ca18317b3693ac4bd910a7c2b412f4a00b4fc2a1c
MD5 fe902da1fcc08101dc7085a4c0418dba
BLAKE2b-256 0b420890646023e3986b8ba351047201231aed3ae64496b8586328d32787a848

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dynamic_fluid-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ee03b6950ed93f3b4bcb071b1237f3764553041fc2ce7d634f8520125388ab5
MD5 fdee9cf349052475f63eee5c675880d7
BLAKE2b-256 89c427ecc904775a9c032a96c05206f29a816a30f6ffc827a64c0c42e438da1c

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