Skip to main content

pydamicsvisual

Matplotlib + pygame rendering extension for pydamics, a small chainable-syntax 2D physics engine.

pydamics itself stays dependency-free (just the physics). This package is the opt-in visual layer on top.

Install

pip install pydamicsvisual        # once published to PyPI -- also installs pydamics
# or, from source:
pip install -e .

Note: this uses pygame-ce (Community Edition), not the classic pygame package. It's a drop-in replacement (import pygame works identically) but is actively maintained and ships wheels for current Python versions -- classic pygame still only has wheels up to Python 3.12, which causes a source-build failure (needs Visual Studio Build Tools) on 3.13/3.14.

Usage

from pydamics import Entity, World
from pydamicsvisual import MatplotlibRenderer, PygameRenderer, floor_bounce

ball = Entity(mass=1.0, position=(2, 10))
ball.physics2d.gravity(force=9.8)
ball.physics2d.fluid(density=1.0, drag=0.2)

world = World()
world.add(ball)
world.on_step = floor_bounce(floor_y=0.0, radius=0.4, damping=0.65)

Headless GIF (matplotlib)

renderer = MatplotlibRenderer(world, xlim=(-1, 8), ylim=(0, 16))
renderer.track(ball, radius=0.4)
renderer.save_gif("out.gif", frames=180, dt=1/60)

Interactive window (pygame)

renderer = PygameRenderer(world, width=800, height=600, ppu=40, floor_y=0.0)
renderer.track(ball, radius=0.4)
renderer.on_click(lambda x, y: print("clicked at", x, y))  # e.g. spawn a new ball
renderer.run(dt=1/120)   # blocks until window closed / ESC

API

floor_bounce(floor_y=0.0, radius=0.4, damping=0.65, x_bounds=None) Returns a callable for world.on_step that keeps entities above the floor (and optionally between walls), bouncing with energy loss on contact. This is demo-level logic, not a real collision system.

MatplotlibRenderer(world, xlim, ylim, floor_y=0.0, title=..., figsize=(6,6))

  • .track(entity, color=None, radius=0.4) — register an entity to draw (auto color if omitted)
  • .animate(frames=180, dt=1/60, steps_per_frame=1, interval=33) — returns a FuncAnimation
  • .save_gif(path, frames=180, dt=1/60, steps_per_frame=1, fps=30) — steps the sim and saves a GIF

PygameRenderer(world, width=800, height=600, ppu=40, floor_y=0.0, title=...)

  • .track(entity, color=None, radius=0.4)
  • .on_click(callback)callback(x_world, y_world) fires on every mouse click
  • .run(dt=1/120, fps=60) — opens the window, steps physics on a background thread, blocks until closed/ESC

Examples

pip install -e ".[dev]"
python examples/matplotlib_demo.py   # -> examples/falling_balls.gif
python examples/pygame_demo.py       # interactive window, click to drop balls

Publishing (for maintainers)

Same flow as pydamics itself:

git init
git add .
git commit -m "Initial commit: pydamicsvisual"
git branch -M main
git remote add origin https://github.com/<your-username>/pydamicsvisual.git
git push -u origin main

Then set up a PyPI Trusted Publisher (pypi.org → account → Publishing) with:

  • PyPI project name: pydamicsvisual
  • Owner: <your-github-username>
  • Repository: pydamicsvisual
  • Workflow: publish.yml
  • Environment: pypi

Create a matching pypi environment under GitHub repo Settings → Environments, then ship a release (tag v0.1.0) to trigger the publish workflow.

Download files

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

Source Distribution

pydamicsvisual-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

pydamicsvisual-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydamicsvisual-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pydamicsvisual-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7a528d393c57cb071080e590ad7c6fd227689c414acbeca39312972ad38b1251
MD5 b80fe814610ce587cdf39df242725232
BLAKE2b-256 6ee73d1df03678d0b1cf4525b5f95696279a9c126496e79a7cb84c91cabfcd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydamicsvisual-0.1.1.tar.gz:

Publisher: publish.yml on Reeed-cell/PydamicsVisual

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pydamicsvisual-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pydamicsvisual-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a4d1c5ac2721e3a449b2bc2a892c2da44068e49499a10a15343283683da4677
MD5 4c07e09e1fa930e623e0b03eb042be7e
BLAKE2b-256 f51b93f2727f29e4f6c0aa301d0c9f868a1b604c6d54e49bed07536a387a4866

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydamicsvisual-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Reeed-cell/PydamicsVisual

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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