By · Updated

Sierpinski Triangle Generator

Recursive Subdivision or Chaos Game Points, Custom Colours and Wallpaper-Size PNG

No ratings yet

Loading…

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the Sierpinski Triangle Generator works

This Sierpinski triangle generator draws the fractal to any depth. The Sierpinski triangle is the fractal you get by cutting the middle out of a triangle and then doing the same to the three that remain, forever. This page draws it two ways: by subdividing to a chosen depth, or by the chaos game, which lands on the same shape from random dice throws. Save the result as a PNG at wallpaper size.

Sierpinski triangle generator: getting a good result

Subdivision is the textbook construction. Take an equilateral triangle, join the midpoints of its sides to split it into four, discard the middle one, and repeat on the three corners. Depth is the number of times this is repeated. Each level triples the triangle count, so depth 6 draws 729 small triangles and depth 9 draws 19,683. Beyond depth 9 the triangles are smaller than a pixel on most exports, which is why the slider stops there.

Chaos game is the surprising construction. Fix three corners. Start anywhere, pick a corner at random, move halfway toward it, and put a dot there. Repeat. After the first few dots, every point you land on is in the Sierpinski triangle, and the dots fill it in evenly no matter which corner sequence the dice give you. The reason is that "halfway toward a corner" maps the whole triangle onto one of its three sub-triangles, so a point that is already in the set stays in it, and a point that is not gets closer every step. The Points slider sets how many dots are thrown; 50,000 gives a clear picture, 200,000 a dense one. Each dot is coloured by which corner it came from, so the three sub-triangles show as three tints and the smaller triangles inside them carry the mix.

Colour. Rainbow in subdivision mode sweeps the hue across the big triangle so each region gets a different colour; Single uses one hue chosen from the seed. Regenerate changes the hue, and in chaos game mode also throws a fresh set of dice.

Export. Both methods redraw from scratch at the export size, so points are not upscaled and subdivision triangles stay sharp. The triangle is fitted to the shorter side of the canvas and centred, so a square 2048 × 2048 export fills the frame while a widescreen one leaves ground colour either side.

FAQ

What is the fractal dimension?

log 3 / log 2, about 1.585. Each halving of scale gives three copies rather than the four a solid triangle would give, and the dimension is the logarithm of that ratio.

Why does the chaos game work when the start point is outside the triangle?

Every step halves the distance to the set, so after twenty steps a start a metre away is within a micrometre. The page skips the first ten dots so they never show.

Why does it look slightly different each time in chaos game mode?

The dice sequence comes from the seed. The shape is the same; the exact dots are not. Enter the same seed for the same picture.

Does this relate to Pascal's triangle?

Yes: colour the odd numbers in Pascal's triangle and you get the Sierpinski pattern. It also appears in the Towers of Hanoi state graph and in cellular automaton rule 90.

See also: all Generative Art tools, Images, Audio, Video & Screen, PDF, SVG, Simulations & Screensavers, Chart Makers, 3D Model Viewers, Drawing Pads, Mockups & 3D Making, Diagram Makers, 3D Science, Tracker Music.

Related tools