DEV Community

Cover image for 🎯 Pygame + Pymunk Collision Lab — tweak mass & speed, watch the physics happen
Joseph Sen
Joseph Sen

Posted on

🎯 Pygame + Pymunk Collision Lab — tweak mass & speed, watch the physics happen

I built a small 2D collision sandbox to visualize elastic collisions using Pygame for rendering and Pymunk (Chipmunk2D) for physics. A tiny Tkinter launcher lets you set the initial speeds and masses of two balls. The app then displays each ball’s live speed and the post‑collision speeds captured via a Pymunk post_solve callback.

Demo highlights

đź§Ş Set speed & mass for both balls before the sim starts (Tkinter dialog).

⚙️ Real‑time physics with elasticity and friction; damping for subtle energy loss.

📊 On‑screen HUD: current speed (px/s) for each ball + speeds right after impact.

đź§± Static wall segments on both sides to keep objects in view.

🟢🟥 Color‑coded bodies: Green vs. Red.

Top comments (0)