\(Sierpinski[n_Integer] := 
      Module[\ {a, start, np, more, more2}, 
a[1] = {0, 0}; a[2] = {1, 0}; 
        a[3] = {.5, .5  Tan[π/3]}; 
        start = Graphics[{AbsolutePointSize[7], Red, Point[a[1]], 
              Point[a[2]], Point[a[3]]}]; 
np = a[Random[Integer, {1, 3}]]; 
        
more = 
          Graphics[
            Join[{Red, AbsolutePointSize[7]}, 
              Map[Function[s, Point[s]], 
                Table[np = .5 \((np + a[Random[Integer, {1, 3}]])\), {n}]]]]; 
        
Show[start, more, AspectRatio -> Automatic]; ]\)

Sierpinski[4]

\(SierpinskiRatio[n_Integer, ratio_] := 
      Module[\ {a, start, np, more, more2}, 
a[1] = {0, 0}; a[2] = {1, 0}; 
        a[3] = {.5, .5  Tan[π/3]}; 
        start = Graphics[{AbsolutePointSize[3], Blue, Point[a[1]], 
              Point[a[2]], Point[a[3]]}]; 
np = a[Random[Integer, {1, 3}]]; 
        
more = 
          Table[np = \((1 - ratio)\) np + ratio\ a[Random[Integer, {1, 3}]], {
              n}]; 
more2 = 
          Graphics[
            Prepend[Prepend[Map[Function[s, Point[s]], more], Blue], 
              AbsolutePointSize[3]]]; 

        Show[start, more2, AspectRatio -> Automatic]; ]\)

SierpinskiRatio[40000, .15]

\(SierpinskiPolygon[n_Integer, nr_Integer] := 
      Module[\ {a, np, more, more2}, 

        a[i_Integer] = {N[Cos[i\ 2  π/nr]], N[Sin[i\ 2  π/nr]]}; 

        np = a[Random[Integer, {1, nr}]]; 

        more = Table[
            np = 3/\((3 + nr)\)\ \ np + 
                \((1 - 3/\((3 + nr)\))\)\ a[Random[Integer, {1, nr}]], {n}]; 
        
more2 = 
          Graphics[
            Prepend[Prepend[Map[Function[s, Point[s]], more], Blue], 
              AbsolutePointSize[3]]]; 

        Show[more2, AspectRatio -> Automatic]; ]\)

Do[SierpinskiPolygon[10000, k], {k, 3, 7}]

■  Check out more information about fractals and a Java version of these fractals on the internet.