Sierpinski triangle/Graphical: Difference between revisions

Content added Content deleted
Line 1,378: Line 1,378:
[[File:Love2D-Sierpinski.jpg]]
[[File:Love2D-Sierpinski.jpg]]


=={{header|Mathematica}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>Sierpinski[n_] :=
<lang Mathematica>Sierpinski[n_] :=
Nest[Join @@ Table[With[{a = #[[i, 1]], b = #[[i, 2]], c = #[[i, 3]]},
Nest[Join @@ Table[With[{a = #[[i, 1]], b = #[[i, 2]], c = #[[i, 3]]},
{{a, (a + b)/2, (c + a)/2}, {(a + b)/2, b, (b + c)/2}, {(c + a)/2, (b + c)/2, c}}],
{{a, (a + b)/2, (c + a)/2}, {(a + b)/2, b, (b + c)/2}, {(c + a)/2, (b + c)/2, c}}],
{i, Length[#]}] &, {{{0, 0}, {1/2, 1}, {1, 0}}}, n]
{i, Length[#]}] &, {{{0, 0}, {1/2, 1}, {1, 0}}}, n]

Graphics[{Black, Polygon /@ Sierpinski[8]}]</lang>
Graphics[{Black, Polygon /@ Sierpinski[8]}]</lang>
Another faster version
Another faster version
Line 1,392: Line 1,391:
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];