Skip to content

Instantly share code, notes, and snippets.

@louismeunier
Created May 5, 2024 12:49
Show Gist options
  • Save louismeunier/74ab6e2062666e158fad80e43d3fcd14 to your computer and use it in GitHub Desktop.
Save louismeunier/74ab6e2062666e158fad80e43d3fcd14 to your computer and use it in GitHub Desktop.
precision := 1000
bakers[x_, y_] := Piecewise[{
{
{2 x, y/2}, 0 <= x <= 1/2},
{
{2 - 2 x, 1 - y/2}, 1/2 <= x <= 1}
}
]
ColorUtil[x_] := Piecewise[{
{Red, 0 <= x <= 1/6},
{Orange, 1/6 < x <= 2/6},
{Yellow, 2/6 < x <= 3/6},
{Green, 3/6 < x <= 4/6},
{Blue, 4/6 < x <= 5/6},
{Purple, 5/6 < x <= 6/6}
}]
(*original points*)
UnitSquare :=
SortBy[Table[{RandomReal[], RandomReal[]}, {i, 1, precision}],
First]
BakeTheSquare[sq_] := Table[bakers[c[[1]], c[[2]]], {c, sq}]
SquareSize := Length[UnitSquare]
(*is this part necessary?*)
(*gen data*)
For[n = 0, n < 30, n++,
Export["bakers_iteration_" <> ToString[n] <> ".mx",
Nest[BakeTheSquare, UnitSquare, n]
]
]
(*import*)maps :=
Table[Import["bakers_iteration_" <> ToString[n] <> ".mx"], {n, 0, 29}]
(*draw points*)
coloured = Table[
Table[
{
ColorUtil[c/SquareSize],
Point[
maps[[n]][[c]]
]
},
{c, 1, Length[maps[[n]]]}
],
{n, 1, Length[maps]}
]
coloures := Table[
ColorUtil[maps[[1]][[c]][[1]]],
{c, 1, Length[maps[[1]]]}
]
retraction[start_, end_, t_] := end*t + (1 - t) start
(*The final guy tm*)
frames := Table[
Graphics[
{
Text["Iteration: " <> ToString[Floor[n]], {0.5, -.05}],
PointSize -> Large,
{Black , Rectangle[{-0.02, -0.02}, {1.02, 1.02}]},
Point[
retraction[maps[[Floor[n]]], maps[[Floor[n + 1]]], Mod[n, 1]],
VertexColors -> coloures
]
}],
{n, 1, 29, .05}
(*{t,0,1}*)
]
gif = ListAnimate[frames, 60] /.
HoldPattern[
AppearanceElements -> _] -> (AppearanceElements -> None)
Table[
Export["bakers/bakers_" <> ToString[i] <> ".svg", frames[[i]]],
{i, 1, Length[frames]}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment