Draw Sierpinski Fractal

Draw the Sierpinski triangle (Sierpiński 1915) via recursive subdivision or chaos game. Dim log(3)/log(2) ≈ 1.585. Free, offline, client-side, instant, secure.

Renders the Sierpinski triangle (Wacław Sierpiński, 1915) via two algorithms: recursive subdivision (deterministic IFS) or the chaos game (random midpoint iteration). Both converge to the same attractor with dimension log(3)/log(2) ≈ 1.585.

How to Use Draw Sierpinski Fractal

  1. Pick the algorithm. Recursive subdivision (deterministic IFS) renders 3ᴺ leaf triangles; chaos game (random midpoint iteration, M. Barnsley 1988) renders points and is great for showing how randomness converges on an attractor.
  2. For recursive subdivision: set iterations 0-9. Iter 6 = 729 triangles; iter 9 = 19,683.
  3. For chaos game: set the point count 100-50,000. The first 100 iterations are skipped (warm-up onto the attractor) before any point is plotted.
  4. Pick render mode (subdivision only): outline shows clean structure; filled shows area; both is the default.
  5. Adjust fill opacity (filled/both) and line width (outline/both).
  6. Pick color and canvas size. A toast warns if the color is too close to white.
  7. Click Draw Fractal or press Ctrl/Cmd + Enter. Iter 9 or 40k+ points triggers a non-blocking info toast - no modal interrupts you.
  8. Copy or download the PNG. The filename encodes the algorithm and parameters (e.g. sierpinski-chaos-pts-10000.png).

Frequently Asked Questions

What is the Sierpinski triangle?

The Sierpinski triangle (also called the Sierpinski gasket) is a fractal described by the Polish mathematician Wacław Sierpiński in his 1915 paper “Sur une courbe dont tout point est un point de ramification”. It is constructed by starting with an equilateral triangle and recursively removing the central triangle formed by joining the midpoints of the sides. The same construction had appeared in mosaic floors centuries earlier – in particular in 13th-century Cosmati pavements in Rome.

What is the algorithm labeled “Recursive subdivision”?

An IFS (Iterated Function System) construction: start with one triangle; each iteration replaces it with 3 smaller copies at half-scale at the corners. The bottom-most layer holds 3 to the N triangles. An older version of this tool labeled this “L-system” because logic.js contained a generateLSystem function that built the Sierpinski L-system string (axiom F-G-G, rules F → F-G+F+G-F and G → GG). That function was never actually called – rendering always used IFS subdivision. The dead code has been removed and the label corrected. Both formalisms yield identical figures, so visually nothing changes.

What is the chaos game?

The chaos game is a randomised algorithm that converges onto the Sierpinski triangle. Place 3 vertices in a triangle. Start at any point. Pick one of the 3 vertices uniformly at random. Move halfway toward it. Plot the new point. Repeat. Despite the randomness, the points fall onto the Sierpinski attractor. It was popularised by Michael Barnsley in his 1988 book “Fractals Everywhere” as the canonical demonstration that an IFS attractor can be sampled by random iteration. This tool skips the first 100 iterations as “warm-up” so the starting position does not leave outlier points.

What is the fractal dimension?

The similarity dimension is log(3) divided by log(2), about 1.5850. It is computed from 3 self-similar copies at scale 1/2: dim = log(N) / log(1/r) = log(3) / log(2). At iteration 0 the rendered figure is a single solid triangle (genuinely 2D); at higher iterations the figure approaches the attractor, whose dimension is the value displayed. The stats line marks this as “asymptotic” so the value is not mistaken for the dimension of the finite drawing.

Why does the area approach zero?

At each iteration, 1/4 of the area of every triangle is removed (the central sub-triangle), leaving 3/4 of the parent area. After N iterations the remaining area is (3/4) to the N times the original. (3/4)^9 ≈ 0.075 – about 7.5% of the starting area remains after 9 iterations. The limit is 0 as N goes to infinity. The perimeter, meanwhile, scales by 3/2 per iteration and goes to infinity.

Why does the chaos game need a warm-up?

The starting point can be anywhere (random), including outside the triangle. The first few iterations bring it onto the attractor (the Sierpinski set), but those early points are not on the fractal yet. Skipping the first 100 prevents stray “outlier” points from being plotted. After 100 iterations the point is effectively on the attractor – every subsequent plot is genuine Sierpinski.

Why do both algorithms produce the same figure?

The Sierpinski triangle is the unique fixed point (attractor) of the IFS with three contractions, each scaling by 1/2 toward one of the triangle’s vertices. Recursive subdivision applies all three contractions at every step in lockstep (deterministic); the chaos game picks one of them randomly at every step (stochastic). Either way the trajectory converges to the same attractor – a result formalised in Barnsley’s IFS theorems.

Is anything sent to a server?

No. The tool loads three static files (HTML, CSS, JS) and then runs entirely in your browser – recursion, chaos game iteration, drawing, PNG export, clipboard copy. You can disconnect from the internet after the page loads. No analytics, no tracking, no cookies.

Is this tool free?

Yes – free, unlimited, no signup, no watermark. Use the PNGs in lectures, papers, blog posts, or art freely. Attribution to is appreciated but not required.