Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clear[p]; Clear[s]; Clear[triangle];
- triangle[s_, {x_, y_}, \[Theta]_] :=
- Table[{x, y} +
- s {Sin[\[Theta] + 2 Pi i/3.0], Cos[\[Theta] + 2 Pi i/3.0]}, {i,
- 3}];
- p[1] = {0, 0};
- s[1] = 1;
- s[n_] := s[n] = s[n - 1]/2 ;
- p[n_] := p[n] =
- p[n - 1] +
- RotationMatrix[-n Pi / 3].{Sqrt[3] s[n]/2.0, s[n - 1] - s[n]/2};
- triangle[n_] := triangle[s[n], p[n], If[Mod[n, 2] == 1, 0, Pi/3]];
- cols = ColorData["Rainbow"] /@ {0.25, 0.5, 0.75};
- Manipulate[
- Graphics[{
- {FaceForm[], EdgeForm[Black], Polygon[triangle[2, {0, -1}, 0]]},
- If[m < 1, {},
- {{
- FaceForm[cols[[1]]], EdgeForm[Darker@cols[[1]]],
- Table[Polygon[triangle[n]], {n, Max[0, Floor[(m - 1)/3]]}]},
- {FaceForm[cols[[2]]], EdgeForm[Darker@cols[[2]]],
- Translate[
- Rotate[Table[Polygon[triangle[n]], {n, Floor[m/3]}],
- 2 Pi/3, {0, 0}], {-Sqrt[3]/2, -1.5}]},
- {FaceForm[cols[[3]]], EdgeForm[Darker@cols[[3]]],
- Translate[
- Rotate[Table[
- Polygon[triangle[n]], {n, Max[0, Floor[(m + 1)/3]]}], -2 Pi/
- 3, {0, 0}], {Sqrt[3]/2, -1.5}]}}
- ]
- }, PlotRange -> All, ImagePadding -> 10],
- {m, 1, 30, 1}
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement