〰️ Peano Space-Filling Curve
About this simulation
A space-filling curve is a continuous curve whose image, in the limit of infinite subdivision, covers every point of a two-dimensional region. Giuseppe Peano constructed the first such example in 1890, stunning mathematicians of the time: intuition says a one-dimensional line cannot cover a two-dimensional square, yet Peano proved that a continuous surjective map from the unit interval onto the unit square exists. His discovery forced a rethink of what “dimension” really means for continuous curves.
How it works
- The unit square is divided into a 3×3 grid of nine equal sub-squares.
- The curve visits the three columns left to right, and within each column it sweeps through the three cells bottom-to-top or top-to-bottom — a back-and-forth “boustrophedon” pattern, named after the way an ox ploughs a field.
- Each of the nine sub-squares is recursively filled by a smaller copy of the same pattern, individually mirrored horizontally and/or vertically so that every hand-off between neighbouring sub-squares stays a single unbroken step.
- Repeating this subdivision n times produces 9n cells and one continuous path that comes within 1/3n of every point in the square.
Key equations
Cell / sample count: N = 9^n. Grid resolution per axis: 3^n. Each additional order multiplies the point count by 9 and shrinks the spacing between visited cells by a factor of 3 along each axis, so the path's resolution improves geometrically while remaining a single connected line.
Controls
- Recursion order n — sets how many times the 3×3 subdivision is applied (capped at 5, since 95 = 59,049 points is already very dense).
- Draw speed — how many points are revealed per animation frame as the curve is traced.
- Grid overlay — shows the faint 3n×3n subdivision lines behind the curve.
- Colour — switch between a single accent colour and a hue ramp that shows progress along the path.
- Redraw / Reset — replay the current curve from the start, or restore all controls to their defaults.
Did you know?
Peano's 1890 curve shocked the mathematical world because it seemed to violate the intuitive belief that continuous maps preserve dimension — a line simply “shouldn’t” be able to fill a plane. A few years later David Hilbert devised a related, visually simpler space-filling curve based on a 2×2 subdivision, which today is the more famous of the two and is widely used in computer science for locality-preserving data indexing.