Morton Fractal Generator
The Morton curve (Z-order curve) fractal pattern. Customize and download as PNG.
Generate a Morton fractal (Z-order curve) by setting the iteration depth, picking a line color, and hitting render — the canvas draws the full Z-shaped space-filling pattern in seconds. Download the result as a PNG at up to 2000×2000 pixels.
And everything runs in your browser. Nothing gets uploaded.
How It Works
The Morton curve maps a 1D sequence onto a 2D grid using bit-interleaving. Each iteration quadruples the number of cells — the generator calculates the (x, y) position for every index by interleaving the binary digits of x and y coordinates. Then it connects each point in order, drawing the characteristic Z-shaped path across the canvas.
Examples
Quick Logo Background
You need a subtle geometric pattern for a presentation slide background.
Iterations: 3
Color: #cccccc
Canvas: 800x800
64-cell Z-curve, light gray on white — clean, minimal pattern ready for layering behind text.
Teaching Space-Filling Curves in a CS Class
A professor wants to show students how iteration depth affects the Morton curve's coverage of a 2D plane. Screenshots from a textbook won't cut it — students need to see the progression live.
Iterations: 1, then 2, then 4, then 6
Color: #2563eb
Canvas: 600x600
4 separate PNGs showing 4 → 16 → 256 → 4,096 cells. Each image clearly shows the Z-pattern at different scales.
Generative Art Print
An artist generating high-res fractal art for a gallery print.
Iterations: 7
Color: #f59e0b
Canvas: 2000x2000
16,384-cell dense Z-curve in amber on a large canvas. Sharp enough for a 20-inch print at 100 DPI.
Who Uses This
Visualizing Z-order indexing for spatial data structures like quadtrees and Morton-coded databases.
Studying space-filling curves in computer science or math courses and need quick visual references.
Creating geometric patterns and fractal artwork for prints, posters, or digital wallpapers.
Building lecture slides that show how Morton curves fill space at increasing iteration levels.
Common Mistakes
At iteration 8 or above, you're drawing 65,000+ line segments. On a 400x400 canvas they all pile on top of each other and you just get a solid block. Use a larger canvas (1500+) for high iterations, or keep iterations at 5-6 for smaller sizes.
Light yellow on a white canvas? The fractal is there, you just can't see it. Pick a color with strong contrast against white, or change the background color first.
The Morton curve is not smooth — it's made of sharp Z-shaped turns. If you want a smooth space-filling curve, the Hilbert curve is a better pick. Morton curves are useful for their bit-interleaving properties, not their aesthetics.
Technical Details
- Processing: 100% client-side (Canvas API)
- Browser Support: Chrome, Firefox, Safari, Edge
- Max Canvas Size: 2000 x 2000 pixels
- Export Format: PNG
- Max Iterations: Limited by browser memory — 8-9 is practical upper bound
Frequently Asked Questions
What is a Morton curve used for?
Morton curves (Z-order curves) are used in computer science to map multidimensional data into one dimension while preserving spatial locality. Databases use them for spatial indexing, and game engines use them to organize texture memory. The fractal itself is a visual representation of that mapping.
What is the difference between a Morton curve and a Hilbert curve?
Both are space-filling curves, but they look and behave differently. The Hilbert curve never crosses itself and produces smooth-looking bends. The Morton curve uses Z-shaped jumps and does cross itself at higher iterations. Morton is faster to compute (just bit-interleaving), while Hilbert gives better spatial locality.
How many iterations should I use?
For most purposes, 4 to 6 iterations hits the sweet spot. That gives you enough detail to clearly see the fractal pattern without overwhelming your browser. Going above 8 iterations can slow things down significantly and won't look much different on a standard screen.
Is the Morton fractal really a fractal?
Technically, yes. The Z-order curve is self-similar — each quadrant contains a smaller copy of the whole pattern. At infinite iterations it fills the entire unit square, which is the formal definition of a space-filling curve. At finite iterations, it is a fractal approximation.
Can I use the generated image commercially?
The Morton curve is a mathematical concept — nobody owns it. The PNG you generate here is yours to use however you want, including commercial projects. No attribution needed.