Building an Infinite Grid

Jul 5, 26

The gallery on the home page is an infinite grid - drag in any direction and it wraps around forever. The trick is modular arithmetic.

Each cell’s position is computed as:

rawX = (baseX + offset) % totalWidth

When a cell scrolls off one edge, the modulo wraps it back to the other side, so the canvas feels endless while only ever rendering a handful of tiles.

Pair that with a spring for smooth momentum, and you get a canvas that feels alive.