The Serpinski Gasket Fractal

What is the Serpinski Gasket?

This is an interesting pattern. It is created by following these rules:

That last step is the reason this is always done on a computer - it requires thousands of iterations of the instruction. In Excel, we are going to implement this using the Fill Down facility.

You would think that you would end up with a mass of dots within the triangle all joining together eventually to form one large impenetrable mass. Surprisingly, you actually get a complex and recursive pattern.

How the Spreadsheet works

I chose the co-ordinates (0,0), (100,0) and (50,100) for the three fixed points and stored them in the cells E1 to F3. Cells E1 and F1 hold the co-ordinates of the first point, cells E2 and F2 the co-ordinates for the second point, and E3 and F3, the co-ordinates for the third point:

Then I decide on the co-ordinates of a random point (I chose (37,92) but you can choose pretty much any value you like) and put that in cells E4 and F4:

I use column A to choose which fixed point is chosen at each stage. The formulae in column A will all hold random numbers in the range 1 to 3. The formula to pick the first random number goes in cell A5 and looks like this:

=INT(RAND()*3+1)

The function RAND() chooses a random decimal in the range 0 to 1 (including 0 but not including 1). Multiplying this by 3 turns the decimal into one in the range 0 to 3 (including 0 but not including 3). Passing this to INT rounds it down to a whole number, i.e. 0, 1 or 2, and adding 1 turns this into a random number which is 1, 2 or 3.

Cell B5 holds the x co-ordinate of the randomly chosen point. If A5 holds 1, then it holds the x co-ordinate of the first point (in E1). If A5 holds 2, then it holds the x co-ordinate of the first point (in E2). If A5 holds 3, then it holds the x co-ordinate of the first point (in E3). This translates as the following formula in B4:

=IF(A5=1,$E$1,IF(A5=2,$E$2,$E$3))

The formula in cell C5 holds the y co-ordinate of the point similarly. The formula is identical except that the references to column E are changed to references to column F.

The current position, as it moves around the triangle, are stored in columns E and F. This is done by taking the average (the half way position) between the point above it in the column (the "current" current position) and the co-ordinate of the fixed point chosen. For this reason, the value in E5 is half the sum of the values in E4 and B5:

Similarly, the value in F5 is half way between the value in F4 and the value in C5.

To repeat the process many times, I highlighted the values in cells A5 to F5 and filled the column downwards. To get a sufficient number of points, I filled down at least to row 1000. This is the sort of thing that you get:

To get the pattern itself, I selected all the cells in columns E and F. Then I clicked on the Chart Wizard icon and selected the XY (Scatter) option:

This will give you the pattern. I think you will be pleasantly surprised by it. Because each data point is marked with a small diamond, it appears a bit "chunky". You can improve it by clicking on one of the data points, then pressing the right mouse button. This brings up the Format Data Series dialog box:

Reduce the size of the data point to the smallest size possible, size 2. This should have a dramatic effect on the pattern.

Click here to download the Excel 97 spreadsheet

... or click here to return to the menu