Sierpinski Triangle

Click the triangle to begin.

Your browser doesn't support HTML5, which is required for this web page to work properly. Please consider trying again with the latest version of a HTML5 capable browser, such as Firefox, Chrome, Safari or IE9.

 

The year 2010 will be known for a long time as the year Benoit Mandelbrot died. He was, as I'm sure you already know, the founder of the science of Fractals. So, what better, or more fitting, way is there to commemorate his life and work than through a program to generate a fractal image. The program above does just that, building up a Sierpinski Triangle using very simple Processing.js code. Once you click the empty triangle to begin, you should see the Sierpinski Triangle start to form within a few seconds. If you leave it running for a while it should start looking quite a good representation. To restart the process, just click the triangle again.

The code is based on the random method described in the excellent book 'Introducing Fractals' by Nigel Lesmoir-Gordon, Will Rood and Ralph Edney (Icon Books Ltd, London, 2009). Basically, you click on the triangle and the position is used to calculate a start coordinate (point A). The code then randomly chooses one of the three triangle vertices, and draws a dot at the midpoint between the vertex and point A (point B). For the purposes of the next dot, point B becomes point A, and the process is repeated over and over again. If you look at the code it shouldn't be too difficult to understand, as it's very short.