Thursday, 6 February 2014

Sierpinski Carpet

Returning to the world of fractals, we travel back nearly 100 years to the Sierpinski Carpet which was first described in 1916. Wacław Sierpinski was a Polish mathematician who made a great contribution to Set Theory. Not just carpets - the Sierpinski Curve and Sierpinski Triangle are the the other two famous fractals that carry his name.

This recursive function is quite intensive involving dividing the X,Y values repeatedly until they hit a multiple of 3 or 0. At this point X,Y can be determined to be Carpet or non-Carpet. As this blog requires it's demo's to be colourful, the colour is determined based on the raw X,Y values rather than the Carpet factor! To add some interactivity, the colour can be shifted and the size of the output adjusted.

Live example is visible here and you can get the Dart code on GitHub.