Staaarter

Generate a Hilbert Curve

Generates the Hilbert curve, a continuous fractal that fills a square without ever crossing itself, using its standard Lindenmayer-system definition and turtle graphics. Renders as a downloadable SVG or PNG line drawing. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
fractalgeneratorsvg

Overview

Introduction

David Hilbert described this curve in 1891 as a concrete example of a continuous curve that can pass through every point of a square, a construction that helped mathematicians reason precisely about space-filling curves as a class.

This tool renders it at any iteration count from 0 to 7 using its standard Lindenmayer-system definition, so you can see the curve become progressively denser and download the result as SVG or PNG line art.

What Is Generate a Hilbert Curve?

A generator for the Hilbert curve, a right-angled, self-similar fractal built from a two-letter Lindenmayer system rather than a hand-drawn approximation.

The only input is an iteration count (the tool labels it "Iterations"); everything else, the axiom, production rules, and 90-degree turn angle, is fixed to the curve's standard definition.

How Generate a Hilbert Curve Works

The generator expands a two-symbol L-system axiom (A) using the rules A to -BF+AFA+FB- and B to +AF-BFB-FA+, repeated for the chosen iteration count, at a fixed 90-degree turn angle.

The expanded string is walked by a turtle-graphics interpreter: F moves forward and draws a segment, plus and minus turn 90 degrees left or right, and the A/B letters themselves draw nothing, they only steer how the rules unfold.

The resulting segments are rescaled to fit the SVG viewbox and rendered as a single connected path.

When To Use Generate a Hilbert Curve

Use it to see how the Hilbert curve's classic zigzag pattern looks at a given order, for a lecture slide, a design element, or general curiosity about space-filling curves.

It's a quick way to generate exportable line art of the curve without setting up a plotting library or writing the L-system expansion yourself.

If you want to experiment with a different angle or your own production rules on the same underlying engine, the general-purpose L-system Generator tool supports that.

Features

Advantages

  • Uses the Hilbert curve's real, standard L-system definition rather than an approximation.
  • Iteration count is validated against the curve's sane bounds (0 to 7), so you can't accidentally request an unrenderable string.
  • One-click SVG and PNG export of the rendered curve.

Limitations

  • Fixed to the standard Hilbert construction, no custom axiom, rules, or angle; use the L-system Generator for that.
  • At the maximum iteration count the curve becomes so dense that individual segments are hard to distinguish visually, even though the underlying geometry is exact.

Examples

Low iteration count

Input

Iterations: 1

Output

A simple U-shaped curve made of four straight segments.

At order 1, the L-system has only expanded once, so the curve shows its basic building block rather than any self-similar detail.

Default iteration count

Input

Iterations: 5

Output

A dense grid-like curve that visibly packs into the square without any lines crossing.

By order 5 the self-similar structure is fully visible, each of the four quadrants contains a smaller, rotated copy of the whole curve.

Best Practices & Notes

Best Practices

  • Step through iterations 1 through 4 first to see how each round subdivides the previous curve before jumping to the denser high orders.
  • Export as SVG rather than PNG if you plan to scale the curve up significantly, since the line art stays crisp at any size.

Developer Notes

The preset uses axiom A with rules A to -BF+AFA+FB- and B to +AF-BFB-FA+, a fixed 90-degree turn angle, and is bounded to iterations 0 through 7 (`HILBERT_CURVE_GENERATOR_BOUNDS`); it's dispatched through the shared `generateFractalFromPreset("hilbert-curve", iterations)` helper that every named-curve tool in this category reuses.

Generate a Hilbert Curve Use Cases

  • Generating reference line art of the Hilbert curve for teaching space-filling curves
  • Producing a downloadable SVG of the curve for a design or data-visualization project
  • Visually comparing how curve density scales with iteration count

Common Mistakes

  • Expecting the maximum iteration count to look meaningfully different from a high but lower one, past order 5 or 6 the visual density change is subtle even though the segment count keeps growing.
  • Assuming the rendered curve at a finite order actually fills every point of the square, in reality it approximates that property, true space-filling only holds in the mathematical limit.

Tips

  • Compare the Hilbert curve against the Dragon Curve Generator or Heighway Triangle Generator to see how different turn angles and rule sets produce very different fractal silhouettes from the same turtle-graphics engine.
  • Download at a high iteration count as PNG if you want a texture-like, densely packed background image.

References

Frequently Asked Questions