Rendering a 3D Rubik's Cube with Matplotlib
How to draw a fully interactive Rubik’s cube using Poly3DCollection, handle keyboard events for face rotations, and integrate the Kociemba two-phase solver.
Why Matplotlib for a Rubik’s Cube?
Rubik’s cube visualizations typically use OpenGL, Three.js, or a game engine. Using matplotlib’s
mpl_toolkits.mplot3dis unconventional. It’s designed for scientific plotting, not real-time 3D interaction. But it has one huge advantage: zero dependencies beyond what you already have for data visualization. No WebGL, no GPU shaders, no build pipeline. Justpip install matplotliband you have a working 3D cube.Building a Physics Simulation Engine in Python
How the physics_modeling package is architected: base classes, numerical integrators, separation of physics from visualization, and property-based testing.
The Core Abstraction
Every physics simulation answers the same question: given a system’s current state, what is its state at the next instant? Whether you’re modeling a spring, an epidemic, or a galaxy of gravitating bodies, the computation follows one pattern: compute derivatives, advance time, repeat.
The
physics_modelingpackage encodes this pattern in aSimulationbase class:Modernizing Legacy Code: From 2004 VPython to Python 3.14
Taking old college physics simulations written twenty years ago and getting them running on modern Python.
The Time Capsule
In 2004, I was a student at The Evergreen State College in a program called Modeling Motion. We wrote Python simulations of physics phenomena (springs, gravity, epidemics, particle collisions) using a library called VPython. I was learning physics and programming simultaneously, translating equations of motion into running code for the first time.