🟪 Sierpiński Carpet
About this simulation
The Sierpiński carpet is a plane fractal described by Wacław Sierpiński in 1916. It generalizes the idea behind the Sierpiński triangle to squares: instead of removing a single triangle from the middle of three, it removes a single square from the middle of a 3×3 grid, then repeats the process inside each of the eight remaining squares forever. The result is a self-similar shape with more holes than area — a classic example used to introduce fractal dimension.
How it works
- Start with one solid square.
- Divide it into a 3×3 grid of nine equal sub-squares.
- Remove the center sub-square, leaving eight.
- Recurse into each of the eight remaining squares, repeating the same 3×3 split-and-remove step down to the chosen depth n.
Key equations
N(n) = 8^n — number of filled squares remaining after n iterations.
A(n) = (8/9)^n · A0 — fraction of the original area still filled after n iterations.
D = log(8)/log(3) ≈ 1.8928 — the fractal (Hausdorff) dimension, between a line (1) and a filled plane (2).
Controls
- Iteration depth n — how many times the 3×3 subdivide-and-remove step is applied, from 0 (a plain square) up to 6.
- Square color — sets the fill color of the drawn squares.
- Invert (Squares / Holes) — toggle whether the remaining structure or the removed center squares are drawn.
- Animate (Instant / Animate) — reveal the recursion level by level instead of drawing the final result instantly.
- Replay animation, Reset — restart the progressive reveal, or return every control to its default.
Did you know?
Because each iteration keeps 8 of 9 sub-squares, the remaining area shrinks by a factor of 8/9 every level and tends to zero as n grows — yet the total edge length of every square boundary grows without bound. The Sierpiński carpet also has an important topological property: every possible planar curve that does not cross itself can be found as a subset of it, making it a "universal" curve for two-dimensional shapes.