Physics as code
Build physics models in code
Write down bodies, relationships, and motion, then get a physics model you can edit and play.
Pendulum timing
Release a long and a short pendulum together. The shorter one completes more swings in the same time.
scene two_swings
support beam orientation=horizontal #blue
pendulum short 0.6m 16deg subject=swing #gold
pendulum long 1.5m 16deg subject=swing #red
short <-> beam
long <-> beam
animate duration=3s speed=0.5
show short.path short.equilibrium long.path long.equilibrium
Visual motion is compressed to fit the diagram; readouts still use the physical distance.
Playback speed is adjusted; time readouts still show physical time.
Diagram description
Animated physics diagram: Which swing moves faster?; showing time.
Closed circuits
Change only open to closed. The circuit becomes complete and the lamp lights.
scene switch_lamp
source V 6V #blue
switch S open #gray
lamp L 6V 3W #gold
V <-> S <-> L <-> VDiagram description
Static physics diagram: Close the switch: why does the lamp light?.
scene switch_lamp
source V 6V #blue
switch S closed #gray
lamp L 6V 3W #gold
V <-> S <-> L <-> VDiagram description
Static physics diagram: Close the switch: why does the lamp light?.
Lens images
As the candle approaches a convex lens, the real image moves farther away and grows larger.
scene candle_lens_distance
object candle 5cm #gold
lens L converging 10cm #blue
candle -> L object_distance=35cm #red
animate candle object_distance=16cm duration=5s speed=1
Visual motion is compressed to fit the diagram; readouts still use the physical distance.
Diagram description
Animated physics diagram: Move the candle: where does the image go?; showing object distance, image distance, magnification.