Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* init with this:*)
- Needs["MultivariateStatistics`"];
- anim = {};
- mut = 0;
- n = 3;
- Clear[line]; Clear[tree];
- line[1, i_] :=
- line[1, i] = Accumulate[Join[{{0, 0}}, Table[{1, 0}, {10}]]];
- line[n_, i_] :=
- line[n, i] =
- SortBy[line[n - 1, i] +
- Join[{{0, 0}},
- RandomReal[NormalDistribution[0, 0.1], {10, 2}]], #[[1]] &];
- tree[i_] :=
- tree[i] =
- Table[Map[RotationMatrix[0.3 (k - (n + 1)/2)].# &,
- Join[{{0, 0}}, MovingAverage[line[i, k], 2]]], {k, 3}];
- (* then run this a few times:*)
- Cl[n_, rot_, pos_, s_] :=
- ListLinePlot[
- Map[RotationMatrix[rot].(# s) + pos &,
- tree[mut max - mut n + 1], {2}], Joined -> True,
- InterpolationOrder -> 2, PlotRange -> All, AspectRatio -> 1,
- Axes -> None, PlotStyle -> Black];
- Crec[0, pos_, s_, rot_] = {Graphics[]};
- Crec[n_, pos_, s_, rot_] :=
- Module[{endpoints = Map[Last, tree[mut max - mut n + 1]]},
- Join[{Cl[n, rot, pos, s]},
- Crec[n - 1, pos + s RotationMatrix[rot].endpoints[[1]], s/3,
- rot - 0.3],
- Crec[n - 1, pos + s RotationMatrix[rot].endpoints[[2]], s/3, rot],
- Crec[n - 1, pos + s RotationMatrix[rot].endpoints[[3]], s/3,
- rot + 0.3]]
- ];
- max = 5;
- c = Show[Crec[max, {0, 0}, 1, 0], ImageSize -> {300}];
- anim = Append[anim, c];
- mut += 1;
- (* then export: *)
- Export["treemut.gif", Join[anim, Reverse@anim]];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement