Visualizations
368 / 500

368 · Physics

Marble Computer

A wooden pegboard computer where falling marbles count, add and multiply in binary.

Six rocking bits run down a pegboard. Each rocker's lower arm blocks one of two holes: a marble slides down its free face, wedges against the arm, and its weight tips the rocker over, so it drops through the hole it just uncovered. A bit at 0 flips to 1 and lets the marble fall out; a bit at 1 flips to 0 and sends it rolling into the next bit, which is a carry. Nothing scripts that logic: an impulse solver integrates rigid marbles, capsule rails and each rocker's rotation, inertia, over-centre spring and end stops, six substeps a frame. A glass tube above each bit adds its place value, so the board counts, adds A then B, and multiplies by shift-and-add, while a bucket lift returns spent marbles from the tray to refill the tubes.

Try it. Pick Count, Add or Multiply to run a program, or Build to drag ramps, crossovers, catches and extra bits onto the pegs (drag a part off the board to remove it). Click a tube to drop its next marble (hold to stream), click a bit to flip it by hand, or click anywhere on the board to drop a marble there. Space pauses, N steps one frame, S toggles slow motion and 1 to 4 switch modes.

  • Impulse-based rigid body physics
  • Bistable rocker flip-flops
  • Ripple-carry binary arithmetic
  • Shift-and-add multiplication

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a marble-powered binary counter with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a full-window canvas, sharp on high-DPI screens, with a light wooden background.
- Write a tiny 2D physics engine: marbles are circles with gravity, rails are line segments with a thickness. Each step, push any overlapping marble out of a rail along the contact normal and cancel its velocity into the rail (with a little bounce). Use several substeps a frame.
- Make a "bit": a rocker on a pivot with an angle, angular velocity, a moment of inertia, end stops at plus and minus 25 degrees and a weak spring that pushes it away from the middle so it rests at either stop. When a marble touches the rocker, apply the impulse to both, using the contact point's distance from the pivot, so the marble's weight can tip it.
- Shape the rocker so its lower arm blocks one of two holes. A marble funnelled onto it wedges against the arm, tips it, and drops through the hole it uncovered: one hole leads out, the other into the next bit, below and to the right.
- Stack four bits down a diagonal and drop a marble into the first one every second.

Once that works, make it beautiful:
- Draw the rockers as coloured acrylic paddles with brass hubs, the rails as wooden strips with soft shadows, and the marbles as glass with a highlight and a band that rotates as they roll.
- Show the register as lamps and a decimal number read straight from the rockers' angles.
- Let me click a rocker to flip it and click anywhere to drop a marble.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as a glass tube above each bit so you can add any number, multiplication by shift-and-add, or a lift that carries spent marbles back up to the top.
PreviousTree RingsA pine grows for a century under a simulated climate, one sanded ring per year. NextGeometric IllusionsSix classic illusions on graph paper, and a lab that measures how much they fool you.

Related visualizations

  • Marble LabyrinthGames A wooden tilt maze where a careful AI steers a steel ball between the holes.
  • Breadboard CPURetro A microcoded 8-bit breadboard computer paints cellular automata on a 16x16 LED matrix.
  • Sorting NetworkAlgorithms A sorting network as a wooden marble run: brass gates swap marbles into order.
  • Difference EngineRetro Brass figure wheels tabulate a polynomial with nothing but addition and rippling carries.
  • Wireworld CircuitsEmergence A four-rule cellular automaton runs a six-bit counter and logic gates on a PCB.
  • Turing MachineRetro A brass Turing machine runs busy beavers, including all 47 million steps of BB(5).
  • Rigid BodiesPhysics Stacked towers of boxes knocked down by a swinging wrecking ball.
  • Hash AvalancheAlgorithms Real SHA-256 woven round by round: flip one input bit and half the state catches fire.
  • Lights Out AlgebraMath The toggle-tile puzzle solved instantly at any size by linear algebra over GF(2).

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs