A few years back, I was in some course where they also taught me some Matlab. One of the exercises was to draw the Sierpinski triangle using a method of progressing a point randomly. I was quite surprised at the time, because I thought the Sierpinski triangle was more of an analytical thing: you drew it using inverted triangles.

I wanted to check up on it, and it turns out the method has a name: Chaos Game.

To generate a Sierpinski triangle using this method, one starts with a some point inside the triangle. Then, at each step, the next point is half the distance from the current point to one of the corners selected at random. I think this method of generating the Sierpinski triangle is even easier than the analytical one.

I used pylab (matplotlib) to create this image.

As I usually do, I also wanted to draw it using ascii-art. However, I must confess, I am not satisfied with the result:

%6 6*%8 %8 66 %6%*6%%6 6%' '66 6866' '6%86 %6* 86 '%8 *66 %**%%'***%6***%% 8'6 6*8 6%%*8 %*'*6 6%6'666 86# 86% %%*''**%6 %**''*'%6 *%8' '6%6 668' '#%% %% '6' '#*'6% *% %8' '6''6* %68%#6#*#68*86*%6#%8%8'6%6*6%*

The code isn’t really good, as I didn’t put much thought into it and just hacked it up. Still, I’m putting it up, and I might improve it someday.