5. The Overlapping Model
Instead of hand-authored tiles, learn adjacency rules from a sample image -- then grow a bigger image that is locally similar everywhere.
Draw a sample, generate the output
The first four demos used the Simple Tiled Model — a hand-authored list of tiles and adjacency rules. The Overlapping Model is the other WFC variant: instead of tiles and rules, you give it a small sample image, and it grows a larger one that is locally similar everywhere.
Pattern extraction
The algorithm slides an N×N window across the sample image, extracting every possible patch. A 16×16 sample with N=3 yields up to 256 patches (with wrapping). Each unique patch becomes a “tile” with a frequency weight based on how often it appeared. The Symmetry option augments the set by adding rotated and mirrored variants.
Overlap-based adjacency
Two patterns are compatible in a given direction if their overlapping (N−1) pixel strip matches exactly. If pattern A is placed left of pattern B, then A's rightmost N−1 columns must equal B's leftmost N−1 columns. This overlap constraint is what makes the output seamless — neighbouring patterns always share a common border.
Support-count propagation
This implementation uses support counts (the AC-4 algorithm) for efficient propagation. For each cell, direction, and pattern, we track how many neighbouring patterns still support it. When a support count drops to zero, that pattern is impossible and gets removed — potentially cascading further. This is much faster than re-checking all neighbours from scratch.
The blended view
During generation, uncollapsed cells show a weighted average of all remaining patterns' colours. This creates the “crystallising out of fog” effect you see during animation — as constraints propagate and possibilities narrow, the blur resolves into sharp pixels.
Performance
The algorithm runs in a Web Worker to keep the UI responsive. The bottleneck is propagation, which scales with output cells × patterns². Practical limits: input up to ~48×48, output up to ~128×128, pattern size N = 2–4.
What we covered
- Five demos showing WFC on grids, 3D lattices, sequences, and images.
- The same three-step loop — observe, collapse, propagate — underpins all of them.
- What changes is the vocabulary: grid tiles, face labels, musical chords, syllables, image patches.
- Global structure always emerges from local adjacency rules.