Visualizations
191 / 500

191 · Algorithms

PCB Annealer

Simulated annealing places chips on a circuit board, then a maze router lays copper.

A small board (a microcontroller, three 8-pin chips, a crystal, a regulator, LEDs, a reset button and two connectors) starts with its parts scattered at random. Simulated annealing shrinks the ratsnest, the yellow airwires drawn as a minimum spanning tree for every net: each move shifts, rotates or swaps a part, improvements are always kept and worse moves are kept with probability exp(-added length / T), so hot parts jitter all over the board and cold ones freeze into a tidy layout. Then a Lee-style maze router lays the copper with A* on a two-layer grid, using eight directions with turn penalties that favor 45 degree corners, vias between layers, and rip-up and reroute when a connection is boxed in, its search wavefront flooding visibly across the board. Power and ground pins drop vias to inner planes, as on a real four-layer board, and the LEDs light up once every connection is made.

Try it. Drag a part to move it and the board re-anneals around it. Reheat shakes the layout up, New board generates another circuit, Layer view switches to red top and blue bottom copper, and Pause stops the clock. Keys: R reheat, N new board, V view, Space pause.

  • Simulated annealing
  • Metropolis criterion
  • Minimum spanning tree ratsnest
  • A* maze routing
  • Rip-up and reroute

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 simulated annealing circuit board placer 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 canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and draws a green board on a grid of about 60 by 40 cells.
- Create about 15 rectangular parts of a few sizes, each with two to eight pins at integer cell offsets, and a netlist of about 25 nets, each a list of two or three pins. Scatter the parts at random.
- The cost is the total wire length (for each net, the length of a minimum spanning tree over its pins, using Prim's algorithm) plus a penalty for every cell where two parts overlap.
- Each frame, try a few hundred random moves: shift a part by a random offset whose range shrinks as the board cools, or rotate it a quarter turn. Keep a move if it lowers the cost, or with probability exp(-increase / T) otherwise. Multiply T by a constant slightly below 1 every frame.
- Draw the parts and the airwires (spanning tree edges) and watch them shorten.

Once that works, make it beautiful:
- Ease drawn positions toward the true ones so jumps read as jitter, and draw chips with legs, resistors and capacitors.
- Show a temperature gauge and a chart of wire length over time.
- When T is cold, route the nets: breadth first search (Lee's maze router) on the grid from one pin to the other, avoiding pins and earlier traces, then draw each path as a copper trace with rounded corners.
- Let me drag a part to move it, and add a Reheat button.

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 second copper layer with vias, A* search with turn penalties for 45 degree traces, or rip-up and reroute for blocked connections.
PreviousGastrulationA vertex-model embryo folds its own gut, purely from cell mechanics. NextPlankton BloomEddies stir green diatom and turquoise coccolith blooms, like ocean-color imagery.

Related visualizations

  • Wireworld CircuitsEmergence A four-rule cellular automaton runs a six-bit counter and logic gates on a PCB.
  • Autograd CircuitMachine learning Type a formula and watch reverse-mode autodiff run on a printed circuit board.
  • Circuit SimulatorPhysics A SPICE-style solver runs a live schematic: LEDs blink, capacitors charge, current flows.
  • Maze SolverAlgorithms A maze carves itself, then A* hunts for the way out.
  • Breadboard CPURetro A microcoded 8-bit breadboard computer paints cellular automata on a 16x16 LED matrix.
  • Marble LabyrinthGames A wooden tilt maze where a careful AI steers a steel ball between the holes.
  • Perfect SnakeAlgorithms A snake AI that can never crash, cutting safe shortcuts until it fills every cell.
  • Tiny CompilerAlgorithms A whole compiler, from source to running bytecode, rebuilt on every keystroke.
  • Hyperbolic MazeGames A labyrinth in negatively curved space: the world glides past while you stay at the center.

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

← More from Emergent Mind Labs