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.2.tar.gz (7.0 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.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydamicsvisual-0.1.2.tar.gz
  • Upload date:
  • Size: 7.0 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.2.tar.gz
Algorithm Hash digest
SHA256 aab802d253a39d7051c4382d2028ab53e4b19e6f66dc5f89e1183354c3ba9239
MD5 a591577d379247ffd27c083be331c6fb
BLAKE2b-256 db816cb02cedc7cf87ecaa677bfb00ca1ccd12de74adb51f408969905bbb8697

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydamicsvisual-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: pydamicsvisual-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a6088e008f37e582b73d5a99a7411197c00f42a5d63ededa8a42e4feb7ac7fb
MD5 0a1e4bf9931a7171fd477d6a79ca0613
BLAKE2b-256 f666d5b0f9ec75b1aef3d96906ce174606405c86e7fe265f1252aa6e437aac93

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydamicsvisual-0.1.2-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