aUCBLogo Demos and Tests / testphaselocking
to testphaselocking
;lockit stop
setUpdateGraph "false
forever
[ clearScreen
;pr repcount
catch "error [ignore runResult [lockit]]
err=Error
if :err != []
[ clearText
print :err.2
for [k 1 100]
[ waitms 10
dispatchmessages
]
]
updategraph
updateVars
dispatchMessages
if Key? [stop]
]
end
to lockit
imax=100
f=10
t=rseq 0 f imax
x=rseq -400 400 imax
Ur=(sin t*360+random 360)*100+rnd*10
clearScreen
setpc 0
pu setx -400 pd
setXY x Ur
i=2
while [i<imax]
[
while [Ur.i>=0 and2 i<imax]
[ i=i+1
]
while [Ur.i<=Ur.(i-1) and2 i<imax]
[ i=i+1
]
while [Ur.i<0 and2 i<imax]
[ i=i+1
]
i1=i-1
while [Ur.i<=0 and2 i<imax]
[ i=i+1
]
i2=i+1
if i2 > imax [break]
ifelse Ur.i2 != Ur.i1
[ r=abs Ur.i1/(Ur.i2-Ur.i1)
][ r=0.5
]
im=i1+(i2-i1)*r
izero=mod im f
xm=im/imax*800-400
xzero=izero/imax*800-400
setpc 1
pu setxy x.i1 -200 pd
setXY x.i1 200
setpc 2
pu setxy x.i2 -200 pd
setXY x.i2 200
setpc 4
pu setxy xm -200 pd
setXY xm 200
setpc HSBA 300 1 0.5 0.2
pu setxy xzero -200 pd
setXY xzero 200
i=i+1
]
updateGraph
for [k 1 100]
[ waitms 10
dispatchmessages
]
end