Sierpinski gasket and Koch snowflake from random walks

Looking at the PHP GD manual for imagesetpixel, I was reminded of something I programmed on a BBC Micro machine many years ago.

I had read some stuff about fractals and programmed creating a Sierpinski gasket. I used the random walk method as it was so easy to program. You start at one point of a triangle, chose one of the triangle points and move half way towards it, plot that point, and iterate. (Back then generating a good image on the BBC Micro took tens of seconds, at least as I programmed it.) I then played around with the method and found I could create a Koch snowflake as the inside of a gasket made froma hexagon and a step move of 2/3.

So here is the same program, written in PHP and GD, which plots 1 million points on a 1000×1000 pixel output. I have included the colouring options I did back then too. You can colour by the point moved to, or delay the colour a few steps.

You can play around with the inputs below.  To generate a Sierpinski gasket use 3 points and a Step Fraction of 1/2. Using 6 points and a 2/3 Step Fraction will generate a pattern with Koch snowflakes at the centre.  You need to use a number for the Step Fraction – the input form does not understand fractions.

Number of Points:

Step fraction:

Colour delay: