The Sierpinski Gasket, introduced in 1915 by W. Sierpinski, is another self-similar fractal. The following cell defines a function called Gasket that illustrates the stages in the gasket's construction.
Input :=
(* Given a level, the function Gasket generates all the
levels up to and including that level in the construction
of the Sierpinski Gasket, starting with level 0.
Code adapted from the code written by Patrick
Haggerty to produce the graphics for the Sierpinski
Gasket in Dr. Richard Crownover's book Fractals and
Chaos. *)
Clear[Gasket,disp,newF,G,F,sierp,i,j,k,w,trans,group1,group2];
Gasket[level_Integer?NonNegative]:=
Module[{newF,G,F,sierp,i,j,k,trans,group1,group2},
(* trans={{a1,b1,c1,d1,e1,f1},
{a2,b2,c2,d2,e2,f2},
{a3,b3,c3,d3,e3,f3}} represents the
coefficients of the affine transformations of
the iterated function system given by
Ti(x)=|ai bi|x + |ei| i=1,2,3
|ci di| |fi|
which produces the Sierpinski Gasket *)
trans={{1/2,0,0,1/2,0,0},{1/2,0,0,1/2,1/2,0},
{1/2,0,0,1/2,1/4,N[Sqrt[3]]/4}};
group1[list_]:={{list[[1]],list[[2]]},{list[[3]],
list[[4]]}};
group2[list_]:={{list[[5]]},{list[[6]]}};
disp[0]=Show[
Graphics[Polygon[{{0,0},{1/2,Sqrt[3]/2},{1,0}}]],
AspectRatio->Automatic];
F={{0,0},{1/2,Sqrt[3.]/2},{1,0},{0,0}};
G=F;
For[k=1,k<level+1,k++,
F=Partition[Flatten[G],2];
G={};
For[i=1,i<(Length[trans]+1),i++,
newF=F;
For[j=1,j<(Length[F]+1),j++,
newF=ReplacePart[newF,
group1[trans[[i]]].F[[j]]+
group2[trans[[i]]],j];];
G=Append[G,newF];];
G=Partition[Partition[Flatten[G],2],4];
sierp=Table[Graphics[Polygon[G[[n]]]],{n,1,Length[G]}];
disp[k]=Show[sierp,AspectRatio->Automatic];];
;]
Construction involves starting with a filled region and successively removing parts of its interior. Let the initial set S0 be a filled equilateral triangle. Subdivide S0 into four smaller triangles by joining the midpoints of the sides of the original triangle. Then remove the interior of the middle triangle. Call the remaining set S1. The next level in the construction of the gasket is obtained by repeating this process of removing the middle triangle for each of the three triangular regions of S1. Continuing this iterative process of removing the middle triangle from each triangle of the previous stage, we obtain a sequence of figures whose intersection is the final gasket S. The following cell displays levels 0-5 in the construction of the Sierpinski Gasket.
Input := Gasket[5]






The following cell displays a table of levels 0-5 of the gasket.
Input :=
Show[GraphicsArray[{Table[disp[n],{n,0,2}],
Table[disp[n],{n,3,5}]}]];
