One diagonal that bounces around an 87 by 100 grid until it corners, marking alternate cells.
A billiard on a grid
var left = x == 0 && dx == -1;
var right = x == CellsW - 1 && dx == 1;
var down = y == 0 && dy == -1;
var up = y == CellsH - 1 && dy == 1;
if ((left || right) && (down || up)) break;
if (left || right) { dx = -dx; y += dy; }
else if (down || up){ dy = -dy; x += dx; }
else { x += dx; y += dy; }
A point moves diagonally across the grid and reflects off the edges, exactly like a
billiard ball on a rectangular table struck at forty-five degrees. It stops only when it
reaches a corner, where both reflections would apply at once.
A tenth of the walk.
Why the dimensions matter
The grid is 87 by 100, and those numbers are coprime. That is the whole reason the piece
works.
A forty-five-degree billiard path on a w × h table returns to its start after
lcm(w, h) steps. When w and h share a factor, the path closes early and covers only
part of the table, leaving a striped remainder. When they are coprime, lcm(w, h) = w·h
— the path visits every cell exactly once before cornering.
87 = 3 × 29 and 100 = 2² × 5². No common factor, so the walk covers the whole grid.
The code checks this explicitly before drawing the second layer:
if (Gcd(CellsW, CellsH) == 1)
A quarter. Cells are marked alternately — mark = !mark on every step — so the trail
is dashed rather than solid, which is where the stitched appearance comes from.
Half.
Three quarters.
Cornered. Each marked cell is then drawn as a diagonal — one way or the other depending
on the parity of i + j — so the marks join across cells into continuous zig-zags, which
is a Truchet condition arriving from a completely different direction.
Five renderings
| Rendering | Grid | lcm | Cell (px) | HatchPerCell | Ink |
|---|
| Stitch Cyan | 87×100 | 8 700 | 10 | 4 | cyan on black |
| Stitch Pink | 67×80 | 5 360 | 12 | 5 | pink on near-black |
| Stitch Amber | 23×28 | 644 | 36 | 2 | amber on near-black |
| Stitch Violet | 43×50 | 2 150 | 20 | 8 | violet on near-black |
| Stitch White | 97×110 | 10 670 | 9 | 5 | near-white on charcoal |
All five grids are coprime, so the walk covers every cell exactly once before cornering
and the hatching pass runs for all of them. Choosing grid dimensions that share a factor
is the one way to break this piece — the walk would corner early and leave most of
the grid blank.
Determinism
Nothing is seeded and nothing is random. The walk is integer arithmetic with a fixed
starting position and direction.