Sierpinski triangle/Graphical: Difference between revisions

Content added Content deleted
Line 1,255: Line 1,255:
Show[Graphics[{Opacity[1], Black, Map[Polygon, Sierpinski[8], 1]}, AspectRatio -> 1]]</lang>
Show[Graphics[{Opacity[1], Black, Map[Polygon, Sierpinski[8], 1]}, AspectRatio -> 1]]</lang>
Another faster version
Another faster version
<lang Mathematica>cf=Compile[{{A,_Real,2}},
<lang Mathematica>cf = Compile[{{A, _Real, 2}},
With[{a=A[[1]],b=A[[2]],c=A[[3]]},
With[{a = A[[1]], b = A[[2]], c = A[[3]]},
With[{ab=(a+b)/2,bc=(b+c)/2,ca=(a+c)/2},
With[{ab = (a + b)/2, bc = (b + c)/2, ca = (a + c)/2},
{{a,ab,ca},{ab,b,bc},{ca,bc,c}}]],
{{a, ab, ca}, {ab, b, bc}, {ca, bc, c}}]],
RuntimeAttributes->{Listable}
RuntimeAttributes -> {Listable}
];
];


n=3;
n = 3;
pts=Flatten[Nest[cf,N@{{{0,0},{1,0},{1/2,√3/2}}},n],n];
pts = Flatten[Nest[cf, N@{{{0, 0}, {1, 0}, {1/2, √3/2}}}, n], n];
Graphics[Polygon/@pts]</lang>
Graphics[Polygon /@ pts]</lang>


[[File:MmaSierpinski.png]]
[[File:MmaSierpinski.png]]