Skip to content

jack-carling/sierpinski

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sierpiński triangle

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.

Screenshot

Chaos game

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:

  1. Take three points in a plane to form a triangle, you need not draw it.
  2. Randomly select any point inside the triangle and consider that your current position.
  3. Randomly select any one of the three vertex points.
  4. Move half the distance from your current position to the selected vertex.
  5. Plot the current position.
  6. Repeat from step 3.

Numberphile has a great video on this subject! Read more about it on Wikipedia.

Canvas

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.