I saw a wonderful JavaScript p5.js animation on X former Twitter and decided to reproduce it in the Wolfram language. But I decided to add a twist and turn it into a puzzle. The puzzle is: how many rotations red pin📍must make to return to initial position? Almost NEVER it lands quite the same after a full rotation. Here is the original tweet:
And here is the corresponding JavaScript p5.js code:
f=0
draw=_=>{
f++||createCanvas(W=500,W)
background(0)
stroke(W)
noFill()
strokeWeight(2)
for(r=100;r<W;r+=50)
for(i=0;i<TAU;i+=PI/10){
line(X=(x=250+r*cos(I=i+f/90))+50*cos(t=i*5+f/50),Y=(y=250+r*sin(I))+50*sin(t),2*x-X,2*y-Y)
circle(X,Y,20)
}
}
draw=_=>{
f++||createCanvas(W=500,W)
background(0)
stroke(W)
noFill()
strokeWeight(2)
for(r=100;r<W;r+=50)
for(i=0;i<TAU;i+=PI/10){
line(X=(x=250+r*cos(I=i+f/90))+50*cos(t=i*5+f/50),Y=(y=250+r*sin(I))+50*sin(t),2*x-X,2*y-Y)
circle(X,Y,20)
}
}
My translation contains a small addition of a single pin colored thread:
In[]:=
Manipulate[Module[{g1=rCos[i+f/90],g2=rSin[i+f/90],g3=50Cos[i*5+f/50],g4=50Sin[i*5+f/50]},Graphics[{White,Thickness[0.003],Opacity[.9],Table[{If[r==150&&i==Pi/10,Directive[Red,Thickness[0.007]],Nothing],Line[{{250+g1+g3,250+g2+g4},{2(250+g1)-(250+g1+g3),2(250+g2)-(250+g2+g4)}}],Circle[{250+g1+g3,250+g2+g4},10]},{r,100,500,50},{i,0,2Pi,Pi/10}]},PlotRange->{{0,500},{0,500}},Background->Black,ImageSize->550]],{f,0,-900Pi},SaveDefinitions->True]
Out[]=
The code below makes an animation:
In[]:=
Parallelize@AnimationVideo[Module[{g1=rCos[i+f/90],g2=rSin[i+f/90],g3=50Cos[i*5+f/50],g4=50Sin[i*5+f/50]},Graphics[{White,Thickness[0.003],Opacity[.9],Table[{If[r==150&&i==Pi/10,Directive[Red,Thickness[0.007]],Nothing],Line[{{250+g1+g3,250+g2+g4},{2(250+g1)-(250+g1+g3),2(250+g2)-(250+g2+g4)}}],Circle[{250+g1+g3,250+g2+g4},10]},{r,100,500,50},{i,0,2Pi,Pi/10}]},PlotRange->{{0,500},{0,500}},Background->Black,ImageSize->1080]],{f,0,-900Pi},RasterSize->550{1,1},DefaultDuration->60];
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Red pin puzzle: tracking patterns in motion with two different frequencies
by Vitaliy Kaurov
Wolfram Community, STAFF PICKS, February 20, 2025
https://community.wolfram.com/groups/-/m/t/3397708
by Vitaliy Kaurov
Wolfram Community, STAFF PICKS, February 20, 2025
https://community.wolfram.com/groups/-/m/t/3397708

