Skip to content
Math Background Studioby GordonKit
Open Studio

Sierpiński

The Sierpiński triangle, carpet and cross fractals, tiled across the canvas with each level removing a fixed fraction of the shape.

Open Sierpiński in Studio

Sierpiński background example

Start with a triangle and cut out the middle, leaving three smaller triangles. Cut the middle out of each of those, and keep going. Every part looks like the whole: this is a self-similar fractal.

How the maths works

n = 0n = 1n = 2
The first three steps of the Sierpinski triangle: n = 0 is one triangle, n = 1 cuts out the middle and leaves 3, and n = 2 cuts each again and leaves 9.
Formula
Dimension of a self-similar fractal: N pieces, each scaled by s
D = log N / log(1 / s)
Triangle: 3 pieces at 1/2
D = log 3 / log 2 ≈ 1.585
Carpet: 8 pieces at 1/3
D = log 8 / log 3 ≈ 1.893
Cross: 5 pieces at 1/3
D = log 5 / log 3 ≈ 1.465

Each step replaces every piece with N copies of itself scaled by s. The triangle uses 3 copies at 1/2; the carpet uses 8 copies at 1/3, a 3 × 3 grid without the centre; the cross (the Vicsek fractal) uses 5 copies at 1/3, the centre plus up, down, left and right.

The dimension of such a fractal is D = log N / log(1 / s): about 1.585 for the triangle, 1.893 for the carpet and 1.465 for the cross. All lie between a line (1) and a filled area (2), and the less you remove, the closer it gets to 2.

After n steps the triangle has 3ⁿ pieces and (3/4)ⁿ of its original area. With infinitely many steps the area goes to 0, yet the total length of all the edges keeps growing toward infinity.

Parameters

Fractal
Which fractal to draw: the triangle, the carpet or the cross.
Triangle · Carpet · Cross
Depth
How many steps of cutting. Each step multiplies the pieces by N; it stops by itself once they are too small to see.
1 to 6
Tiles per short edge
How many fractals across the short side; one fractal repeats to fill the canvas.
1 to 8
Gap
How much each smallest piece shrinks toward its own centre, so the levels stand apart. 0 makes the pieces touch.
0 to 0.3
Colouring
By part gives the same position (say, the bottom-left corner) the same colour; By tile gives each fractal one hue; By distance shades outward from the centre.
By part · By tile · By distance

Examples

Each example opens in the studio with these settings.

Using it as a background

A depth of 4 to 5 looks the most fractal; beyond that the detail is too small to see. The carpet and cross make good grid-like tech backgrounds.

Add a small gap and colour by part to make the self-similarity, every part like the whole, easy to see. It is a good way to teach fractals.