Hello
I am looking for a better understanding of the behavior of Manipulate when using a Module. I know this is a larger topic but I have a specific question.
I will post my code at the end for reference.
I have a function defined inside Manipulate and all is working as expected however Mathematica pegs one of my CPUs to 100% even after the results are calculated and returned.
I read an article saying a function inside Manipulate will be continuously reevaluated even when sliders are not being changed. The article suggested placing the function inside a Module to prevent reevaluation by Manipulate unless something changes like a Slider value.
My question is Why is this necessary? Why does Mathematica loop the function causing constant CPU usage? I almost understand why using Module resolves the problem but am I confused why this is the default behavior of Manipulate.
If I remove the Module below the CPU loop returns.
Code is below. This is a SpiroGraph emulator I am fooling around with.
Manipulate[Module[{Cx,Cy,Fx,Fy},
l=p/r; (* Drawing hole radius as a percent of drawing disk radius *)
k=r/R0;(* Drawing disk radius as a percent of stationary outer ring radius *)
Cx[t_]:=R0*Sin[t]; (* X coordinate of stationary outer ring *)
Cy[t_]:=R0*Cos[t];(* Y coordinate of stationary outer ring *)
Fx[t_]:=R0*((1-k)*Cos[t]+(l*k*Cos[((1-k)/k)*t]));
Fy[t_]:=R0*((1-k)*Sin[t]-(l*k*Sin[((1-k)/k)*t]));
ParametricPlot[{{Fx[t1],Fy[t1]},{Cx[t1],Cy[t1]}},{t1,0,R Pi}]],
{{R0,32,"Stationary ring inner radius"},10,200,10,Appearance->"Labeled"},
{{r,IntegerPart[R0/2]-1,"Drawing disk radius"},1,R0,1,Appearance->"Labeled"},
{{p,IntegerPart[r/2]-1,"Drawing hole radius"},1,r,1,Appearance->"Labeled"},
{{R,30,"Number of rotations"},1,100,10,Appearance->"Labeled"}
]