forked from InertialObservr/twitter_gifs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspirograph.nb
53 lines (38 loc) · 1.4 KB
/
spirograph.nb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Clear[x, y, R, r]
x[\[Theta]_, r_, R_, d_: 1] := (R - r)*Cos[\[Theta]] +
d*Cos[(R - r)/r*\[Theta]]
y[\[Theta]_, r_, R_, d_: 1] := (R - r)*Sin[\[Theta]] -
d*Sin[(R - r)/r*\[Theta]]
\[Theta]max[r_, R_] := 2 \[Pi]*LCM[r, R]/R;
plot[iter_, r_, R_ ] :=
ParametricPlot[{x[\[Theta], r, R], y[\[Theta], r, R]}, {\[Theta], 0,
iter*\[Theta]max[Rationalize[r], Rationalize[R]]},
PlotRange -> {{-6, 6}, {-6, 6}},
PlotStyle -> Hue[(2.75 - r)/2.75] , Background -> Black,
AxesStyle -> White, Ticks -> None, Axes -> False, Frame -> False]
Clear[singlePlot];
singlePlot[r_, R_, BRix_: 0] := Module[ {plots},
If[BRix == 0,
Table[
plot [Rationalize[iter], Rationalize[r], Rationalize[R]], {iter,
0, 1, .05} ][[2 ;;]],
Table[
Show[BRs[[1 ;; i]],
plot [Rationalize[iter], Rationalize[r],
Rationalize[R]] ], {iter, 0, 1, .05} ][[2 ;;]]
]
]
generateBR[r_, R_] := plot[1, r, R];
BRs = Table[generateBR[r, 3], {r, 1, 3, .2}];
plotWBR[rmin_: .25, rmax_: 3, R_: 4, step_: .2] := Module[{anims},
anims = {};
i = 1;
Table[ If[r == rmin,
anims = Append[anims, singlePlot[r, R, 0]]
, anims = Append[anims, singlePlot[r, R, i] ];
i = i + 1 ]
, {r, rmin, rmax, step}];
Return[Join[anims, Table[anims[[-1, -1]] , {i, 0, 1, .2} ]] ]
]
Export["spiro.gif", Flatten[ plotWBR[1, 3, 3, .2]],
"AnimationRepetitions" -> \[Infinity] ]