Draw Cantor Dust Fractal
Draw true Cantor Dust (4-corner) or Sierpiński carpet (8-square) in your browser. Color modes, PNG export. Free, offline, client-side, instant, secure.
Draw two related 2D fractals. True Cantor Dust (the Cartesian product of Cantor sets - keep only the 4 corner sub-squares at each iteration, dimension ≈ 1.2619). Or Sierpiński carpet (3×3 minus the center - keep 8 sub-squares, dimension ≈ 1.8928).
How to Use Draw Cantor Dust Fractal
- Pick the pattern. "Cantor Dust" is the Cartesian product of Cantor sets - at each iteration, the 3×3 sub-grid keeps only the 4 corner squares (top-left, top-right, bottom-left, bottom-right) and discards both the middle row AND middle column. Dimension log(4)/log(3) ≈ 1.2619. "Sierpiński carpet" removes ONLY the center square of the 3×3 grid, keeping the 8 surrounding squares. Dimension log(8)/log(3) ≈ 1.8928.
- Set iteration depth (1-6) via the slider. Iter 1 = first subdivision. Iter 4 = recommended (visible structure, fast render). Iter 6 with carpet = ~262k squares (slow - "Drawing…" loading state shown).
- Choose render mode: Solid fill (every square painted), Outline only (border strokes - adjust width 1-5 px), or Alternating colors (primary/secondary switched by recursion depth, useful to see level structure).
- Pick colors and background. Transparent bg lets you composite the fractal over another image. Low-contrast pairings (e.g. white-on-white) trigger a warning toast.
- Canvas size: 400 / 600 / 800 / 1000 px. Backing store is multiplied by your devicePixelRatio for Retina-crisp output.
- Press Ctrl+Enter or click Draw Fractal. Stats line shows pattern name, square count, dimension, theoretical measure ((4/9)^n for dust, (8/9)^n for carpet), and render time.
- Copy or Download. Filename includes pattern name and iteration:
cantor-dust-iter-4.pngorsierpinski-carpet-iter-4.png.
Frequently Asked Questions
How does true Cantor Dust differ from Sierpiński carpet?
Both subdivide each square into 3×3. Cantor Dust removes the MIDDLE ROW AND MIDDLE COLUMN (5 squares removed: top-middle, all of middle row, bottom-middle) – keeping just the 4 CORNERS. Sierpiński carpet removes ONLY the center square (1 removed) – keeping 8. After many iterations, Cantor Dust becomes “dust-like” widely-separated pixels (measure → 0 fast, since (4/9)^n shrinks fast). The carpet still has connected paths between sub-squares (measure → 0 slowly, (8/9)^n).
Why are the fractal dimensions different?
The formula is dim = log(N) / log(S) where N = number of sub-copies kept and S = scale factor between original and copy. Both fractals have S = 3 (squares get divided into thirds). Cantor Dust keeps N = 4 → dim = log(4)/log(3) ≈ 1.2619. Sierpiński carpet keeps N = 8 → dim = log(8)/log(3) ≈ 1.8928. Lower dimension = more “sparse.” Cantor Dust at high iterations looks like scattered points; the carpet looks like a lacework.
What is “measure” in the stats line?
The total area still occupied as a percentage of the original square. Cantor Dust: (4/9)^n × 100%. After iter 6: (4/9)^6 ≈ 0.78%. Sierpiński carpet: (8/9)^n × 100%. After iter 6: (8/9)^6 ≈ 49.32%. As n → ∞, both measures go to 0 (the limit set has Lebesgue measure zero) – but Cantor Dust gets there much faster because more is removed per step.
Why does iteration 6 take so long for the carpet?
Square count per iteration: dust = 4^n, carpet = 8^n. At iter 6: dust = 4,096 squares, carpet = 262,144 squares. The carpet is 64× more work. Each square is a separate Canvas fillRect call. At 262k fillRects, even on a fast desktop, you’re looking at 200-500 ms. Mobile devices can take 1-2 s. That’s why iter 6 + carpet triggers the “Drawing…” loading state.
Are these the only two fractals you can build this way?
No – there are many “Cantor-product” variants. You can remove different subsets of the 3×3 grid: middle row only (Sierpiński-like, dim log(6)/log(3) ≈ 1.6309), middle column only (same), middle column AND row but keep middle-middle (Cantor cross), edges only (4 corners + 4 edges = 8 squares, like carpet but with different removal). Or change grid size to 4×4 or 5×5. We chose dust + carpet as the two most-named cases.
What’s the alternating color mode showing?
Each square’s recursion-level depth gets a color: even depths use primary, odd depths use secondary. Useful for visualizing WHICH iteration step produced each region. In carpet mode, you’ll see a pleasing checker-of-checker pattern. In dust mode, the four-corner structure becomes very visible because depth changes happen along diagonals.
Why is my canvas crisp on Retina now?
The backing-store resolution is multiplied by window.devicePixelRatio (2 on Mac Retina, 2 or 3 on phones), then the drawing transform is scaled by the same factor. So a 600×600 CSS canvas gets a 1200×1200 pixel buffer on Mac Retina, then we draw at 2× scale. Result: anti-aliased fills are sharp.
What’s the connection to Cantor’s original set?
Georg Cantor (1883) defined his set on [0,1]: remove the middle third (1/3, 2/3), then remove middle thirds of each remaining interval, etc. Limit = uncountable, measure 0, totally disconnected. Cantor Dust extends this to 2D as the product set C × C. Sierpiński (1916) generalized differently – instead of a product, he defined a “carpet” by direct iteration on the 2D square. Both predate the term “fractal” (coined by Mandelbrot in 1975) by 50-90 years.
Is it secure?
Yes – 100% client-side. All subdivision and rendering happen in your browser. No parameters or images leave your device. Verify via your browser’s Network tab.