Pattern Formation

Wave Function Collapse

A grid of undecided cells, one local rule about which tiles may sit beside which — and a globally coherent network crystallizes, cell by cell, that no single choice ever planned.

Watch the pattern crystallize: the most-constrained cell picks a tile, and that choice ripples outward, forbidding incompatible neighbors. Press randomize for a completely different — but equally coherent — pipe network. Shrink the grid to follow each collapse-and-propagate step; if the constraints paint into a corner, the grid restarts (watch the restart counter).

What you're seeing

A grid of cells, each one initially undecided — holding every possible tile at once, a superposition. One at a time, the algorithm finds the cell with the fewest remaining options (the most constrained, lowest-entropy cell), and forces it to pick a single tile. That choice immediately ripples outward: any neighbor tile that can no longer fit beside the new one is forbidden, which constrains its neighbors, and so on. Cell by cell the undecided dots resolve into pipe segments, and when the dust settles a single globally coherent pattern has crystallized — connected pipes that always meet pipe-to-pipe, never a dead end against a wall. Nothing drew the network; it fell out of repeatedly enforcing one local rule.

The rule

Each tile carries a socket on each of its four edges: a pipe (1) or a blank (0). The only knowledge in the whole system is a single adjacency rule: two tiles may be neighbors iff their touching edges match — a piped edge must meet a piped edge, a blank must meet a blank. From a handful of base tiles (empty, straight, elbow, tee, cross) and their rotations, that rule alone is enough. The algorithm then loops three steps until every cell is decided:

Coherence is never imposed globally. There is no objective function, no search over whole layouts, no "make the pipes connect" instruction. The rule is purely local — which tiles may sit beside which — and propagated. If the constraints ever back a cell into a corner with zero legal tiles, that's a contradiction: this entry handles it the simplest way, by discarding the grid and restarting with a fresh seed (the readout counts how often that happens).

Why it matters

Wave Function Collapse is a vivid demonstration of global order from purely local constraints. With no objective function and no search, constraint propagation alone reliably produces structures that look designed. That is not a coincidence: Karth and Smith showed that WFC is constraint solving — specifically the arc-consistency idea at the heart of constraint-satisfaction solvers, the same machinery that powers a Sudoku solver. The algorithm was popularized by Maxim Gumin in 2016, and it descends directly from Paul Merrell's earlier model synthesis.

It is worth being honest about what kind of emergence this is. Most of the Atlas — boids, the Ising model, reaction–diffusion — is dynamical and interaction-based: many agents push on each other over time and order settles out of the feedback. WFC, like the Atlas's L-systems, is instead generative and algorithmic: there is no equilibrium being sought and no time-stepped physics — a constraint solver simply resolves a consistent assignment. Both are emergence in the sense that the whole is far richer than any rule, but the mechanism here is constraint propagation, not interaction, and it is fair to say so. One more honesty note: the quantum-sounding name is a loose metaphor. "Observing the lowest-entropy cell" and "collapse" borrow physics vocabulary, but nothing here is actual quantum mechanics.

In the wild

WFC and its descendants are a workhorse of procedural content generation in games — used to lay out levels, worlds, and textures in titles such as Bad North, Townscaper, and Caves of Qud, among many others. The same edge-matching idea drives tiling and texture synthesis. And because the core is ordinary constraint solving, its mechanism is shared by Sudoku-style constraint puzzles and the arc-consistency routines studied in computer science: propagate the consequences of each forced choice, and either a consistent solution falls out or a contradiction tells you to back up.

Try this

References

  1. Gumin, M. (2016). "Wave Function Collapse" algorithm (reference implementation and tilesets). github.com/mxgmn/WaveFunctionCollapse.
  2. Karth, I. & Smith, A. M. (2017). "WaveFunctionCollapse is Constraint Solving in the Wild." Proceedings of the 12th International Conference on the Foundations of Digital Games (FDG '17).
  3. Merrell, P. (2007). "Example-Based Model Synthesis." Proceedings of the 2007 Symposium on Interactive 3D Graphics and Games (I3D '07), 105–112.