← Back to blog

The Hilbert Curve: Space-Filling Art

Discover the Hilbert curve - a space-filling curve that passes through every point of a 2D region. Learn how this mathematical marvel is used in art and computing.

Space-filling Hilbert curve pattern rendered across an image creating intricate maze-like art

In 1891, German mathematician David Hilbert created a mathematical monster: a curve that seems impossible. It has zero width, yet it fills an entire square region. It's continuous, yet it has infinite length. It's the Hilbert curve, and despite its mathematical strangeness, it's visually beautiful.

What Is a Space-Filling Curve?

A space-filling curve is a continuous curve that passes through every point of a 2D region (like a square). Intuition says this is impossible - a 1D line can't fill a 2D area. But mathematics proves otherwise.

The trick: the curve must be infinitely complex. At each refinement level, the curve gets more intricate, filling more area. In the infinite limit, it fills the entire square.

How the Hilbert Curve Works

The Hilbert curve is defined recursively:

  1. Order 1: A simple U-shape pattern
  2. Order 2: Four U-shapes arranged so they connect into a larger U
  3. Order 3: Four Order-2 curves arranged to form a larger pattern
  4. And so on, infinitely...

Each iteration doubles the resolution. The Order-1 Hilbert curve has 4 segments. Order-2 has 16. Order-10 has over a million.

Peano Curves and Variants

Hilbert wasn't first. Italian mathematician Giuseppe Peano discovered space-filling curves in 1890. His curve is simpler (9 segments at order 1, 81 at order 2) but has the same property: it fills the plane.

Since then, mathematicians have invented hundreds of variants: the Lebesgue curve, the Sierpinski curve, Moore's curve, and many others. Each has unique properties and visual characteristics.

Why Hilbert Curves Matter in Computer Science

Space-filling curves like Hilbert are used in computer science because they preserve locality. Points that are close along the curve are likely to be close in 2D space. This property is useful for:

  • Database indexing: Speed up spatial queries
  • Cache optimization: Improve CPU cache hit rates
  • Image compression: Process pixels in an order that exploits locality
  • Machine learning: Better data organization for neural networks

Hilbert Curves in Art

When rendered as a visual curve, Hilbert curves have mesmerizing beauty. The recursive structure creates intricate, self-similar patterns. Artists use Hilbert curves:

  • As abstract compositions: Drawing them in high orders creates complex geometric patterns
  • For image traversal: Using the curve's order to determine which pixel to process next
  • With color mapping: Mapping colors along the curve's path creates beautiful gradients
  • In generative art: The curve itself becomes the artwork

The Strange Beauty of the Infinite

What makes space-filling curves so aesthetically appealing is their paradox: they're simple rules, infinitely applied, creating infinite complexity. They're deterministic yet feel organic. They're mathematical yet look natural.

Looking at a high-order Hilbert curve, you see structure at every scale. Zoom in, and there's more detail. It's like a fractal, and in fact, many space-filling curves are fractal curves.

Ready to try it? Open GlitchArt Studio and experiment with this effect.

Try this effect in GlitchArt Studio 85+ effects, real-time preview, free to use
Open Editor