Programming Project: Sierpinski’s Triangle
December 2nd, 2008 — ChristianI heard about this today in my physics class, it’s called Sierpinski’s Triangle, and there is an easy way to make this impressive looking figure. It’s called the “Chaos Game.”
The chaos game works like this: First, draw three points, which will become the three points of the largest outside triangle. Assign a value to each of the points so that you will be able to pick them with any sort of random number generator, like dice or a ‘random’ number procedure on a computer. Now, draw a point anywhere inside the triangle, and randomly select one of the three points on the triangle. Draw a line between your first point, and the selected point on the triangle, and then draw another point half way between the two points on the line. Repeat this process for many more iterations, with each iteration starting from the point that you last drew, and Sierpinski’s Triangle will be formed.
After about 100 points drawn, the shape begins to take form. As more points are drawn, the figure becomes clearer. I don’t suggest doing this by hand, though. It’s much faster with the use of a computer program.
I wanted to see a program draw the triangle, so I decided to write one. The source code is really quite simple, and I used the Allegro game programming library to make adding the graphics easy. If you’d like to download the program, along with the source code (and necessary libraries), please click here.


