Truchet tiles — patterns that connect
Give each cell a random orientation and watch a maze of flowing curves appear.
A plain grid repeats the SAME cell everywhere. The next step is a tile that comes in a few variations, dropped at random per cell — and if the variations are designed so their edges always line up, the whole surface joins into one connected pattern. That is a Truchet tiling, and it is how shaders make mazes, circuit boards, pipes and woven knots.
The classic Truchet tile has two quarter-circle arcs joining opposite corners. Each cell randomly either keeps the tile or flips it (here, mirror the x inside the cell when the cell’s random value is over 0.5). Because every arc still meets the cell edge at the same two points, flipped or not, the arcs connect across cell borders into long flowing curves. One random bit per cell, and an ordered grid becomes an endless woven maze.
That maze of curves came from one tile and one coin-flip per cell. It builds on everything in the patterns and randomness lessons: floor() for the cell, fract() for the position inside it, and random() for the per-cell choice. Swap the arcs for diagonal lines and you get a maze; thicken them and you get pipes.
Why do Truchet tiles connect into continuous curves across the grid?