A line that fills a square
2026-06-09
A line has one dimension. A square has two. So a line should never be able to reach every point of a square - there is simply too much room in there. And yet, with recursion, one unbroken line can thread through every part of a square without ever crossing itself. The trick is that the line never stops folding.
The rule is one sentence: to draw the next level, replace every cell with four shrunk copies of the current curve, rotate two of them, and join the four end to end. Step the depth up and watch it happen. The four colours are those four copies - and each colour is itself a smaller Hilbert curve. That is recursion you can see: the whole is built from quarter-size copies of itself, and each of those from copies of it.
The property that makes it useful
The Hilbert curve isn't just a curiosity. Look at the colours again: the four quarters of the line land in the four quarters of the square. The first quarter of the journey stays in one corner; the next quarter in the next. Zoom in and the same is true of every sub-quarter. Points close together along the line are close together in the square.
That is rare and valuable. Most ways of flattening a grid into a list - reading it row by row, say - put two cells that are neighbours on the page hundreds of steps apart in the list. The Hilbert curve almost never does. So it is how images get stored so that nearby pixels sit nearby on disk, how 2D map coordinates get squashed into one sortable number, how databases keep things that are near each other findable together. A line that fills a square, with the neighbourhood kept intact.
Where the dimension goes
Each step multiplies the number of cells by four and halves the spacing. Push the depth to infinity and the line passes arbitrarily close to every point of the square - it genuinely fills it. The length races off to infinity while the curve stays trapped in the same finite box, exactly as the Koch snowflake's edge does. It is a relative of the recursive tree: a simple rule, applied to its own output, building structure no single drawing could.
Four copies of itself, joined and shrunk, forever. The line never crosses, never lifts, and in the limit it touches everything - keeping near things near the whole way down.