The following is an example of the Mathematica iteration function:
1. The triangle rotates along a certain point.
verticse = {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}};tri = Line[verticse /. {a_, b__}->{a, b, a}];Graphics[tri]
rotation[gr_] := Rotate[gr, Pi/13, {1, 1}];Graphics[NestList[rotation, tri, 30]]
2. Draw the triangle after iterative Translation
translation[gr_] := Translate[gr, verticse];Graphics[{RGBColor[0.32, 0.77, 1.], NestList[translation, tri, 5]}]
3. Sierpinski triangle
SierpinskiTriangle[iter_, opts : OptionsPattern[Graphics]] :=Module[{vertics, vecs},vertics = N[{{0, 0}, {1, 0}, {1/2, 1}}];vecs = 0.5 vertics;Graphics[{Blue, Nest[{Blue, Translate[Scale[#, 0.5, {0., 0.}], vecs]} &,Polygon[vertics], iter]}, opts]] SierpinskiTriangle[8, ImageSize -> 512]
References:
- Http://reference.wolfram.com/mathematica/ref/NestList.html
- Http://reference.wolfram.com/mathematica/ref/Rotate.zh.html
- Http://reference.wolfram.com/mathematica/ref/Translate.html
- Http://reference.wolfram.com/mathematica/ref/Module.html
- Http://en.wikipedia.org/wiki/Sierpinski_triangle
- Http://mathworld.wolfram.com/SierpinskiSieve.html
Mathematica iteration Functions