Fractals & coloring
Koch Snowflake and Sierpinski Triangle
Repeated changes to a triangle produce the Koch snowflake, whose perimeter grows without limit while its area approaches a fixed value. Build it and the Sierpinski triangle and carpet in the browser.
The Koch snowflake and Sierpinski triangle begin with simple shapes and a rule repeated on every new part. Each round leaves smaller copies of the same pattern. The snowflake's boundary grows longer; the Sierpinski triangle loses area.
The snowflake below shows five iterations of the Koch curve. Colored bands mark equal distances from its outline. Change Iterations to redraw the field.
◆ Open in StudioOpen the Koch snowflake at 5 iterationsIn Geometry, drag Iterations between 1 and 7 and watch every edge sprout smaller bumps.What Are Fractals? explains self-similarity and dimension more broadly. Here, the focus is on the Koch snowflake, the Sierpinski triangle and the Sierpinski carpet.
How the Koch curve is built
Swedish mathematician Helge von Koch described the curve in 1904. Start with one straight segment:
- Divide the segment into three equal parts.
- Remove the middle part.
- Replace it with two sides of an equilateral triangle that points outward.
One segment becomes four, each one third as long. Applying the rule again makes sixteen. Every round multiplies the segment count by four while making each bump smaller.
Join three Koch curves around an equilateral triangle to make the Koch snowflake. Its first iteration is a six-pointed star. At the second, each star edge gains its own points:
◆ Open in StudioCompare the snowflake at 2 iterations48 segments. Set Iterations to 1 for the six-pointed star made by the first step.The Studio's Iterations slider runs from 1 to 7. At 7, the snowflake has 49,152 segments; the shortest is 1/2187 of the original triangle's side. That is finer than a screen pixel at normal zoom. The image stops changing visibly even though the mathematical construction continues without end.
Infinite perimeter, finite area
Every round replaces each segment with four, each a third as long. The perimeter grows by a factor of 4/3 each time. After n rounds it is (4/3)ⁿ times the starting perimeter. It passes 3 times the starting length by round four and 7 times by round seven.
Each round adds one small triangle per existing segment. The added area shrinks. If the starting triangle has area A, the first round adds three triangles, each with area A/9. Later rounds add four times as many triangles at one ninth the previous size, so each round adds 4/9 as much area as the one before. The geometric series converges to:
area = A × (1 + 3/5) = 8/5 × A
| Iteration | Segments | Perimeter (× start) | Area (× start) |
|---|---|---|---|
| 0 | 3 | 1 | 1 |
| 1 | 12 | 1.333 | 1.333 |
| 2 | 48 | 1.778 | 1.481 |
| 3 | 192 | 2.370 | 1.547 |
| 4 | 768 | 3.160 | 1.577 |
| 7 | 49,152 | 7.492 | 1.598 |
| limit | infinite | infinite | 1.6 |
The region has finite area and an infinitely long boundary because every stretch of the boundary keeps gaining bends. The curve is continuous everywhere, yet has no tangent line anywhere.

Self-similarity at every scale
One side of the snowflake contains four copies of itself at one third the size. Each copy contains four more. Magnify a piece by 3 and it matches the whole exactly. The Mandelbrot set also has miniature copies, though they are distorted and never exactly match the full set.
The Sierpinski triangle
Polish mathematician Wacław Sierpiński described his triangle in 1915. Its rule removes a piece at each step:
- Start with a solid equilateral triangle.
- Join the midpoints of its sides and remove the middle triangle.
- Repeat on each of the three triangles that remain.
Each round keeps 3/4 of the area. The remaining area approaches zero, leaving a set of three half-size copies of itself.
◆ Open in StudioOpen the Sierpinski triangle at 6 iterationsLower Iterations to 1 or 2 to see the first holes, then raise it to 10.The same pattern appears if you color the odd numbers in Pascal's triangle. It also appears in the "chaos game": repeatedly jump halfway toward a randomly chosen corner of a triangle, and the points you land on fill in the Sierpinski figure.
The Sierpinski carpet
The carpet, from 1916, starts with a square. Divide it into a 3 × 3 grid, remove the center cell and repeat on the eight remaining cells. Each round keeps 8/9 of the area. That area also tends to zero, much more slowly than the triangle's.
In the Studio, switch on Carpet (squares) in the Sierpinski source:
◆ Open in StudioOpen the Sierpinski carpet, set up for reliefThe Carpet toggle switches triangles to squares. Relief is preset to Terraces for heightmap and SVG export.Fractal dimension
Scale a line segment by 3 and it contains 3 copies of the original. A square gives 9 copies, or 3²; a cube gives 27, or 3³. The exponent gives the dimension.
Apply the same test to these fractals. Scaling the Koch curve by 3 gives 4 copies, so its dimension D satisfies 3ᴰ = 4:
| Fractal | Copies | Scale factor | Dimension | Value |
|---|---|---|---|---|
| Koch curve | 4 | 1/3 | log 4 / log 3 | ≈ 1.2619 |
| Sierpinski triangle | 3 | 1/2 | log 3 / log 2 | ≈ 1.585 |
| Sierpinski carpet | 8 | 1/3 | log 8 / log 3 | ≈ 1.8928 |
These are similarity dimensions. Because the copies in these shapes do not overlap, each also equals the Hausdorff dimension. Values between 1 and 2 place the sets between an ordinary curve and a filled region. The carpet, near 1.9, comes closer to filling the plane than the Koch curve does.
How the Studio draws them
Most Koch snowflake generators draw the polygon as a line. For every pixel, the Studio computes its distance to the snowflake at the chosen iteration. The distance is negative inside the outline and positive outside it; a gradient maps that value to color.
Each color band is a contour at equal distance from the curve. Near the outline, the bands follow its bumps. Farther out, small bumps blur away and the bands round into hexagons, then near-circles. Band width controls how much distance each band covers.
The Sierpinski source also produces a distance field. It folds each pixel into the nearest of three half-size copies, or eight third-size cells for the carpet. After the selected iterations, it measures the distance to the remaining solid piece.
The smooth field can also be used for physical output:
- Relief · CNC & laser makes a 16-bit heightmap PNG, an 8-bit grayscale PNG for 3D laser engraving at a chosen DPI, an STL or a normal map. Its profiles are Triangle, Cosine, Sawtooth, Terraces and Raw. A tool diameter setting smooths details a router bit could not cut.
- Export → SVG traces contour lines, a layered cut with one layer per terrace, or tile outlines. It sizes them in millimetres from the Relief width. Koch contour lines make nested offset outlines for scoring or pen plotting.
Building a fold fractal (KIFS)
Koch and Sierpinski shapes follow fixed rules. The Fold Fractal (KIFS) source lets you adjust the rule. KIFS stands for kaleidoscopic iterated function system. At each iteration, it:
- Reflects the tested point into one quadrant.
- Folds it across the diagonal.
- Rotates it by Fold angle.
- Scales it by Scale factor around the Offset point.
After the last iteration, the Studio measures the distance to a small bar; that distance becomes the field. Mirror folds produce kaleidoscope symmetry, and scaling makes the pattern self-similar.
◆ Open in StudioDesign your own fold fractal (KIFS)Change Fold angle, Scale factor and Offset to reshape the self-similar pattern.
A Fold angle near zero with Scale factor 3 makes square, carpet-like shapes. Raising the angle twists the arms. Fold angle is also a loop target in Motion, so a full turn of the fold can become a seamless video.
Related reading
The fractal kaleidoscope guide uses repeated reflections with escape-time fractals. Penrose tiling covers a non-repeating tiling built by substitution instead of iteration. Julia sets use a complex polynomial rule to make more organic self-similar shapes.
Frequently asked
How do you make a Koch snowflake?
Start with an equilateral triangle. Split every edge into thirds, replace the middle third with two sides of a smaller equilateral triangle pointing outward, and repeat on every new edge. The Koch snowflake is the limit of that process.
Why does the Koch snowflake have infinite perimeter but finite area?
Each step multiplies the perimeter by 4/3, so it grows without limit. The area added at each step shrinks geometrically, by a factor of 4/9, so the total area converges to 8/5 of the starting triangle.
What is the fractal dimension of the Koch snowflake?
The Koch curve is made of 4 copies of itself at 1/3 scale, so its similarity dimension is log 4 / log 3, about 1.2619. The boundary of the snowflake has the same dimension.
What is the fractal dimension of the Sierpinski triangle and carpet?
The Sierpinski triangle is 3 copies at 1/2 scale, giving log 3 / log 2, about 1.585. The Sierpinski carpet is 8 copies at 1/3 scale, giving log 8 / log 3, about 1.8928.
What is the difference between the Koch curve and the Koch snowflake?
The Koch curve is the fractal built on a single line segment. The Koch snowflake joins three Koch curves around an equilateral triangle, making a closed shape with an inside and an outside.
Can I export a Koch snowflake or Sierpinski carpet for laser cutting or CNC?
Yes. The Studio's Relief section exports a 16-bit heightmap PNG, an 8-bit laser PNG at a set DPI, an STL, or a normal map. The Export section saves SVG contour lines or a layered cut sized in millimetres.
Studio dispatches
New work, new writing — straight to you
Occasional letters from the studio. No spam, unsubscribe anytime.