aUCBLogo Demos and Tests / clockwork
be clockwork
singleshot=Name? "framenr
t=solvetooths
r0=1.6 r=array 4
foreach t
[ r.#=r0*?
]
f1=1 f2=-t.1/t.2 f3=f2 f4=-f2*t.3/t.4
(pr f1 f2 f3 f4)
phi2=-90+(t.1/t.2)*(90-(int t.1/4)*360/t.1)+360/t.2/2
phi4= 90-(t.3/t.4)*(90-(int t.3/4)*360/t.3)+360/t.4/2
t2=reverse (solvetooths 12 20)
r0=2 r2=array 4
foreach t2
[ r2.#=r0*?
]
f21=1 f22=-t2.1/t2.2 f23=f22 f24=-f22*t2.3/t2.4
(pr f21 f22 f23 f24)
phi22= 90+(t2.1/t2.2)*(-90-(int t2.1/4)*360/t2.1)+360/t2.2/2
phi24=-90-(t2.3/t2.4)*(-90-(int t2.3/4)*360/t2.3)+360/t2.4/2
d=3.5*r0
ifelse singleshot [phi=FrameNr][phi=0]
dphi=1/10 ; 1/60
ddphi=dphi/3
anti=0.3
WindowMode
setUpdateGraph false
setPenSize [5 5]
ht
pr [+ - changes speed, ESC stops]
forever
[ cs
setpc hsba 200 1 1 .3
(toothedwheel r.1 t.1 phi)
(toothedwheel r.1 t.1 phi+anti)
rt 90
pu fd r.1+r.2+d pd
lt 90
(toothedwheel r.2 t.2 phi2+f2*phi)
(toothedwheel r.2 t.2 phi2+f2*phi+anti)
setpc hsba 0 1 1 .3
(toothedwheel r.3 t.3 f3*phi)
(toothedwheel r.3 t.3 f3*phi+anti)
lt 90
pu fd r.3+r.4+d pd
rt 90
(toothedwheel r.4 t.4 phi4+f4*phi)
(toothedwheel r.4 t.4 phi4+f4*phi+anti)
setpc hsba 100 1 1 .3
(toothedwheel r2.1 t2.1 phi)
(toothedwheel r2.1 t2.1 phi+anti)
lt 90
pu fd r2.1+r2.2+d pd
rt 90
(toothedwheel r2.2 t2.2 phi22+phi*f22)
(toothedwheel r2.2 t2.2 phi22+phi*f22+anti)
setpc hsba 300 1 1 .3
(toothedwheel r2.3 t2.3 phi*f23)
(toothedwheel r2.3 t2.3 phi*f23+anti)
rt 90
pu fd r2.3+r2.4+d pd
lt 90
(toothedwheel r2.4 t2.4 phi24+phi*f24)
(toothedwheel r2.4 t2.4 phi24+phi*f24+anti)
if singleshot [break]
updateGraph
if keyP
[ ch=readChar
if ch==char 27 [stop]
if ch=="+ [dphi=dphi+ddphi]
if ch=="- [dphi=dphi-ddphi]
]
phi=phi+dphi
gc
]
end
be solvetooths [f 60][mintooths 10]
for [t3 mintooths 200]
[ for [t4 mintooths 100]
[
t1=f*t4*(t3+t4)/(t3+f*t4)
t2=t3*(t3+t4)/(t3+f*t4)
if (and
(int t1)==t1
(int t4)==t4
t1>=mintooths
t2>=mintooths
t1+t2==t3+t4
(t1/t2)*(t3/t4) == f)
[
(pr [Tooths:] t1 t2 t3 t4)
output (list t1 t2 t3 t4)
]
]
]
pr [Tooths not found!]
output [1 1 1 1]
end