Draw a Morton Fractal screenshot

Draw a Morton Fractal

Draw the Morton Z-order curve by interleaving index bits, visiting every cell of a 2^n square once.

Privacy First
0 Runs
Updated 2026-11-06
No upload
Runs in this tab

The Z comes from the bits

The Morton order visits every cell of a 2^n by 2^n square exactly once, in an order set by interleaving the bits of the row and column index: x takes the even bits of the index and y takes the odd ones. Consecutive indexes are always edge neighbours, so the path is continuous even though it zig-zags through four quadrants at every level. Order n holds 4^n cells.

The order is capped at seven, which is 16,384 cells. Order eight is 65,536 points, built one at a time before drawing, and the cells would be smaller than a pixel — a slow frame with nothing new to see.

The decode is pure bit arithmetic, so there is no search, no seed and no randomness. The same order always produces the same path, and the page draws entirely in the tab.

Draw a Morton (Z-order) curve: every cell of a 4^n grid is visited in one path, with x taking the even bits of the index and y the odd ones.

The Z shape is a consequence of the bit interleave rather than a search, and the same order always produces the same path.

How to use it

Set the order, then press Draw or Animate. Stop ends the animation, and the status line names the number of cells visited at that order.

The rule

Each index is split into even and odd bits: the even bits become x and the odd bits become y. That interleave produces the Z-shaped jumps, which is why Morton order is used where locality per level matters more than a short path.

Where it stops

Order is capped at 7, because the grid has 4^n cells and order 8 is 65,536 points — slow to build and impossible to see. There is no export and no seed.

What to Expect

Best for

  • seeing how bit interleaving produces locality
  • comparing Z-order with a Hilbert path

What this tool keeps

  • The interleave and the drawing are computed in this tab, so the page works offline and stores nothing.

Frequently asked questions

How does Morton order differ from Hilbert order?

Morton interleaves the bits of the index — even bits to x, odd bits to y — which produces Z-shaped jumps. The page draws that path; it does not claim the locality is as smooth as Hilbert's.

Why cap the order at 7?

Because the grid has 4^n cells. Order 8 is 65,536 points, which is slow to build and past anything the canvas can show.

Is the path searched for?

No. Each point's coordinates come directly from the bit split, so the path is arithmetic and needs no search.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.