Sierpinski Fractal Generator
Both figures have a description that needs no recursion at all. A cell of the Sierpinski triangle is filled exactly when its row and column share no binary digit — the same pattern as Pascal's triangle modulo two. A cell of the carpet survives exactly when no base-three digit pair of its row and column are both one. Those rules produce the whole figure at once, and the counts they give, three and eight to the power of the depth, are what the page checks.
What this generator does
Fills a grid by testing each cell against a digit rule — binary for the triangle, base three for the carpet — and reports how many cells survived alongside the figure's fractal dimension.
How to use this tool
- Choose the triangle or the carpet.
- Set the depth — the carpet grows much faster, so its ceiling is lower.
- Read the filled-cell count and compare with the formula.
- Look at the dimension: between one and two for both.
Understanding the controls
- Figure
- The triangle, whose filled count is three to the depth, or the carpet, whose count is eight to the depth.
- Depth
- Up to 7 for the triangle and 4 for the carpet, since the carpet's cell count grows eight times faster per step.
Common use cases
- Showing self-similarity with an exact count at every scale
- Teaching the link between Pascal's triangle modulo 2 and the Sierpinski triangle
- Generating fractal patterns for design work
- Comparing two fractals with different dimensions side by side
- Illustrating why the carpet fills less of the plane than it appears to
How this generator works
No recursion is involved. The triangle test is a single bitwise AND between the column and the row minus the column; the carpet test walks the base-three digits looking for a pair that are both one. The check confirms the count matches the formula, that no cell repeats, and that no triangle cell strays outside the triangle.
Randomness and fairness
Nothing here is random. The depth and the figure determine every cell, so there is no seed and no variation between runs.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Triangle depth stops at 7 and carpet depth at 4, where each already has thousands of cells.
- Only these two figures; the Menger sponge and other relatives are three-dimensional or otherwise out of scope.
- Cells are drawn as squares, so the triangle is a stepped approximation rather than a smooth outline.
- No colouring options beyond the accent colour.
- Figures are not stored between visits.
Privacy and your data
Every cell is computed in your browser from a digit rule. Nothing is transmitted or stored.
Related generators
- Koch Curve GeneratorThe Koch curve and snowflake at any depth, with the exact segment count, length factor and fractional dimension.
- L-System GeneratorWrite your own rewriting rules — or take one of five classics — and watch the string grow and turn into a path, with the size worked out before anything is drawn.
- Elementary Cellular Automaton GeneratorAll 256 one-dimensional rules, run from a single cell or from noise, with the rule number decoded into its eight outputs.
- Geometric Pattern GeneratorBuilds a tiled pattern under a symmetry rule and hands you the SVG — mirrored, half-turn or quarter-turn.