Draw a Hilbert Fractal
Draw a Hilbert space-filling curve of any order up to seven, decoding each point from its index by bit interleaving.
A curve that never jumps
The Hilbert curve visits every cell of a 2^n by 2^n grid, and consecutive cells always share an edge, so the path is continuous even though it fills the square. The page decodes each index to a cell with the standard rotate-and-interleave step, then joins the points in order. Order n has 4^n points.
The order is capped at seven, which is 16,384 points. Order eight is 65,536 points built one at a time before a single line is drawn, and the grid would be four times finer than the canvas can resolve — a pause with no visible gain. The line width also thins with the order, so the strands stay distinguishable.
The decode is arithmetic only: no search, no seed and no randomness. The same order always emits the same sequence, and nothing is uploaded while it runs.
Draw a Hilbert curve of the order you set: the grid is 2^n by 2^n and every cell is visited exactly once.
Each point is decoded from its index by interleaving bits, so the whole path is a pure function of the order — no search and no randomness.
How to use it
Set the order, then press Draw or Animate. Stop ends the animation, and the status line names the number of points placed at that order.
The rule
The path is decoded from the index by bit interleaving with the rotation states the Hilbert construction implies. That is why a deep order is fast to compute but slow to draw: the points are arithmetic, the strokes are not.
Where it stops
Order is capped at 7, because the grid is 2^n by 2^n and order 8 would place 65,536 points for detail the canvas cannot resolve. There is no export and no seed.
What to Expect
Best for
- seeing a space-filling curve visit every cell once
- demonstrating a locality-preserving ordering
What this tool keeps
- The decode and the drawing happen in this tab, so the page works offline and stores nothing.
Frequently asked questions
How is the path generated?
Each point's coordinates are decoded from its index by interleaving bits, with the rotation states of the Hilbert construction applied. There is no search step and no randomness.
Why cap the order at 7?
Because the grid is 2^n by 2^n: order 8 is 65,536 points, which pauses visibly while adding detail no canvas can show.
Does the curve cross itself?
No. A Hilbert curve visits every cell of the grid exactly once, which is the property that makes it useful for locality-preserving orderings.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.