aUCBLogo Demos and Tests / spirograph_rc
to spirograph_rc
;Inspired by Mike Sandy and Robert James Carter (posted 25 June 2007)
WindowMode
setPenColor RGB 0.4 0 0.3
setScreenColor RGB 1 1 1
hideTurtle
setPenSize 0
setUpdateGraph false
r1=300
num =1
den =2
num2=1
den2=2
dphi=1
i=0
io=false
mainFrame=(Frame [][Spirograph]
wxdefault_frame_style+wxfull_repaint_on_resize
[0 500][300 499])
WindowSetBackgroundColor mainFrame RGB 1 0.92 0.86
slnum =(Slider mainFrame [numerator1] 1 num 200 [num =SliderValue change] wxsl_labels)
slden =(Slider mainFrame [denominator1] 1 den 200 [den =SliderValue change] wxsl_labels)
slnum2=(Slider mainFrame [numerator2] 1 num2 200 [num2=SliderValue change] wxsl_labels)
slden2=(Slider mainFrame [denominator2] 1 den2 200 [den2=SliderValue change] wxsl_labels)
sldphi=(Slider mainFrame [(dphi in degrees)/100] 100 dphi 2000
[dphi=SliderValue/100 change] wxsl_labels)
sphimax_=(StaticText mainFrame [phiMax=] wxalign_right)
sphimax =(StaticText mainFrame [0])
sphi_=(StaticText mainFrame [phi=] wxalign_right)
sphi =(StaticText mainFrame [0])
bclose=(Button mainFrame [Close]
[ io=true
clearScreen
::running=false
])
bs=BoxSizer wxvertical
sbs1=StaticBoxSizer wxvertical mainFrame [ratio1]
BoxSizerAdd sbs1 slnum 100 wxexpand 0
BoxSizerAdd sbs1 slden 100 wxexpand 0
BoxSizerAdd bs sbs1 140 wxexpand 0
sbs2=StaticBoxSizer wxvertical mainFrame [ratio2]
BoxSizerAdd sbs2 slnum2 100 wxexpand 0
BoxSizerAdd sbs2 slden2 100 wxexpand 0
BoxSizerAdd bs sbs2 140 wxexpand 0
sbs3=StaticBoxSizer wxvertical mainFrame [drawingspeed]
BoxSizerAdd sbs3 sldphi 100 wxexpand 0
BoxSizerAdd bs sbs3 80 wxexpand 0
sbs=StaticBoxSizer wxvertical mainFrame [Display]
bsh=BoxSizer wxhorizontal
BoxSizerAdd bsh sphi_ 100 wxexpand 0
BoxSizerAdd bsh sphi 100 wxexpand 0
BoxSizerAdd sbs bsh 100 wxexpand 0
bsh2=BoxSizer wxhorizontal
BoxSizerAdd bsh2 sphimax_ 100 wxexpand 0
BoxSizerAdd bsh2 sphimax 100 wxexpand 0
BoxSizerAdd sbs bsh2 100 wxexpand 0
BoxSizerAdd bs sbs 60 wxexpand 0
BoxSizerAdd bs bclose 25 wxexpand 0
WindowSetSizer mainFrame bs
WindowFit mainFrame
change
running=true
while [running]
[ if not io
[ spiroloop
]
dispatchMessages
waitMS 100
]
WindowDestroy mainFrame
end
to setphimax x
phimax=x
StaticTextSetLabel sphimax x
end
to change
clearScreen
phi =0
phi2=0
r2=r1*num /den
r3=r2*num2/den2
lastpos=(list 0 r1-r3)
setphimax 360*(lcm num den)/den
io=false
end
to spiroloop
; if io [stop]
oldPos=PosXYZ
oldOri=Heading
left phi forward r1-r2
right phi2 forward r2-r3
newPos=Pos
setPC HSBA 360*phi/phimax 1 1 1
PenDown setPos lastPos PenUp
lastPos=newPos
setPosXYZ oldPos
setHeading oldOri
phi =phi +dphi
phi2=phi2+dphi*r1/r2
i=i+1
if phi>phimax
[
StaticTextSetLabel sphi phi
if not io
[ updateGraph
]
io=true
stop
]
spiroloop
end