The Sierpiński triangle (sometimes spelled Sierpinski), also called the Sierpiński gasket or Sierpiński sieve, is a fractal attractive fixed set with the overall shape of an equilateral triangle, subdivided recursively into smaller equilateral triangles.
If one takes a point and applies each of the transformations dA, dB, and dC to it randomly, the resulting points will be dense in the Sierpinski triangle, so the following algorithm will again generate arbitrarily close approximations to it.
Or more simply:
- Take three points in a plane to form a triangle, you need not draw it.
- Randomly select any point inside the triangle and consider that your current position.
- Randomly select any one of the three vertex points.
- Move half the distance from your current position to the selected vertex.
- Plot the current position.
- Repeat from step 3.
Numberphile has a great video on this subject! Read more about it on Wikipedia.
The Sierpiński triangle will render with a maximum of 5000 iterations onto the canvas. Try moving the starting point as well as point A, B and C to see different variations.