Inspired by a beautiful spirograph animation on Instagram, I recreated it in the Wolfram Language. While the original used a single color (green), I also created a multicolored pen version.
Parameter
Parameter
Set the parameters of a letter U and a gear.
w=3/2;(*thicknessofU*)l=3Pi;(*lengthofstraightlineofU*)r0=4;(*radiusofthesmallersemicircleofU*)r1=67/26;(*radiusofgeardrawingspirogpraph*)d=2;(*distancefromthecentreofthegearonwhichapenisplaced*)interval=Pi/40;(*intervalbetweendrawings*)
initial position
initial position
When drawing a spirograph, get the positions of point on the letter U and center of the gear.
In[]:=
basepts[w_,l_,r0_,r1_,d_,interval_]:=Block[{line,center1,center2,rightp,rightc,leftp,leftc,p1,p2,p3,p4,p5,c1,c2,c3,c4,c5,p,c},(*arcs*)center1={0,r0+w};center2={r0+w/2,r0+w+l};p1=Table[r0*{Cos[i],Sin[i]},{i,3Pi/2,2Pi,interval/r0}]+Threaded@center1;c1=Table[(r0-r1)*{Cos[i],Sin[i]},{i,3Pi/2,2Pi,interval/r0}]+Threaded@center1;p2=Table[(r0+w)*{Cos[i],Sin[i]},{i,Pi,3/2*Pi,interval/(r0+w)}]+Threaded@center1;c2=Table[(r0+w+r1)*{Cos[i],Sin[i]},{i,Pi,3/2*Pi,interval/(r0+w)}]+Threaded@center1;p3=Table[w/2*{Cos[i],Sin[i]},{i,0,Pi,interval/(w/2)}]+Threaded@center2;c3=Table[(w/2+r1)*{Cos[i],Sin[i]},{i,0,Pi,interval/(w/2)}]+Threaded@center2;(*lines*)line=Table[{0,i},{i,0,l,interval}];p4=line+Threaded[{r0,r0+w}];c4=p4-Threaded[{r1,0}];p5=line+Threaded[{r0+w,r0+w}];c5=p5+Threaded[{r1,0}];(*base*)rightp=Join[p1,p2,p3,p4,p5];rightc=Join[c1,c2,c3,c4,c5];leftp=rightp/.{x_,y_}:>{-x,y};leftc=rightc/.{x_,y_}:>{-x,y};(*sortitng*)p=Join[rightp,leftp];c=Join[rightc,leftc];{p,c}=DeleteDuplicates/@{p,c};{p,c}=#[[Last[FindShortestTour@#]]]&/@{p,c};Most/@{p,c}];
In[]:=
(*initialposition*){p,c}=basepts[w,l,r0,r1,d,interval];letter=ListLinePlot[p,PlotStyle->LightGray,AspectRatio->Automatic,Axes->None];gear=Graphics[{LightGray,Circle[c[[1]],r1]}];gearcenter=Graphics[{PointSize[0.02],Black,Point@c[[1]]}];col=RGBColor@@({0,100,0}/255);pen=Graphics[{PointSize[0.03],col,Point[{0,r1+w-d}]}];Show[letter,gear,gearcenter,pen,ImageSize->Small]
Out[]=
Draw in a single color pen
Draw in a single color pen
In[]:=
(*predrawingpointp:pointonletter,c:centerofgear,d:distancefromthecentreofthegearonwhichapenisplaced*)getq[p_,c_,w_,d_]:=Block[{result,slope,intercept,sol,sol1,sol2,x,y},result=If[c[[1]]-p[[1]]!=0,slope=(c[[2]]-p[[2]])/(c[[1]]-p[[1]]);intercept=p[[2]]-slope*p[[1]];(*sol=NSolveValues[EuclideanDistance[{x,y},c]==r&&y==slope*x+intercept,{x,y}];*)Off[FindRoot::jsing];sol1=FindRoot[{EuclideanDistance[{x,y},c]==d,y==slope*x+intercept},{{x,c[[1]]},{y,c[[2]]}}];sol2=FindRoot[{EuclideanDistance[{x,y},c]==d,y==slope*x+intercept},{{x,p[[1]]},{y,p[[2]]}}];On[FindRoot::jsing];sol={{x,y}/.sol1,{x,y}/.sol2};Nearest[sol,p,1][[1]],If[c[[2]]>w,c-{0,d},c+{0,d}]];result];(*drawingpointq:predrawingpoint,c:centerofgear,r1:radiusofgear,m:lengthofgearmoved*)(*gett[q_,c_,r1_,m_]:=RotationTransform[-m/r1,c][q];*)gett[q_,c_,r1_,m_]:=Module[{θ,cosθ,sinθ,qShifted,rotated},θ=m/r1;cosθ=Cos[-θ];sinθ=Sin[-θ];qShifted=q-c;rotated={cosθ*qShifted[[1]]-sinθ*qShifted[[2]],sinθ*qShifted[[1]]+cosθ*qShifted[[2]]};rotated+c];spirograph[w_,l_,r0_,r1_,d_,interval_,lapcnt_]:=Block[{p,c,px,cx,mx,qx,tx},{p,c}=basepts[w,l,r0,r1,d,interval];px=Flatten[Table[p,{lapcnt}],1];(*centerofgear*)cx=Flatten[Table[c,{lapcnt}],1];(*lengthofgearmoved*)mx=Table[interval*i,{i,0,Length@px-1}];(*predrawingpoints*)qx=ParallelMap[getq[px[[#]],cx[[#]],w,d]&,Range[Length@px]];(*drawingpoints*)tx=ParallelMap[gett[qx[[#]],cx[[#]],r1,mx[[#]]]&,Range[Length@px]];{cx,tx}];
On how many laps does a gear return to their initial position?
In[]:=
lap=2Pi(w/2+r0/2+(r0+w)/2)+4l;lapcnt=LCM[lap/Pi,2*r1]/(lap/Pi)
Out[]=
67
Get the positions of the center of the gear and the drawing point.
Connect the start and end points.
Get its animation.
Draw in a multicolored pen
Draw in a multicolored pen
Use Spirographs with Mathematica–Wolfram Library Archive as a reference to draw a spirograph with a multi-coloured pen.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Spirograph design in the form of letter
by Kotaro Okazaki
Wolfram Community, STAFF PICKS, February 25, 2025
https://community.wolfram.com/groups/-/m/t/3400312
by Kotaro Okazaki
Wolfram Community, STAFF PICKS, February 25, 2025
https://community.wolfram.com/groups/-/m/t/3400312