
Sketchy Traingle to Square
By:
Matthen on
Nov 8th, 2011 | syntax:
None | size: 1.56 KB | hits: 1,936 | expires: Never
Clear[line];
width = 50;
yskip = 1;
contract = 0.99;
line[k_]["line"][0] = Table[{i, 0}, {i, width}];
line[k_]["square"][0] = Map[# - {width/2, width/2} &, Reverse@Join[
Table[{i, 0}, {i, width}],
Table[{width, i}, {i, width}],
Table[{width - i, width}, {i, width}],
Table[{0, width - i}, {i, width}]
]];
line[k_]["triangle"][0] = Map[# - {width/2, Sqrt[3] width/4} &, Join[
Table[{i/2, i Sqrt[3]/2}, {i, 0, width, 3/4}],
Table[{width/2, width Sqrt[3]/2} + {i/2, -i Sqrt[3]/2}, {i, 0,
width, 3/4}],
Table[{width - i, 0}, {i, 1, width, 3/4}]
]];
WavyCopy[line_, transform_] :=
Map[transform,
line + RandomReal[NormalDistribution[0, 0.1], Dimensions[line]]];
line[k_]["line"][n_] :=
line[k]["line"][n] =
WavyCopy[line[k]["line"][n - 1], # - {0, yskip} &];
line[k_]["square"][n_] :=
line[k]["square"][n] =
WavyCopy[line[k]["square"][n - 1], # contract &];
line[k_]["triangle"][n_] :=
line[k]["triangle"][n] =
WavyCopy[line[k]["triangle"][n - 1], # contract &];
nlines = 25;
type1 = "square";
type2 = "triangle";
f[nlines_, n_, "line"][{x_, y_}] := {x, yskip nlines - y}
f[nlines_, n_, "square"][{x_, y_}] := ({x, y}) contract^(3 n - nlines)
frame[nmin_] := Graphics[{FaceForm[], EdgeForm[Black],
Table[Polygon[
MovingAverage[((nlines - n)/nlines) line[0][type1][
n] + (n/nlines) Map[f[nlines, n, "square"],
line[1][type2][nlines - n]], 2]
]
, {n, nmin, nlines}]
}, PlotRange -> 25, ImageSize -> 300];
Manipulate[frame[nmin],{nmin,0,nlines}]