aUCBLogo Demos and Tests / testdrawspaceship
to testdrawspaceship
clearScreen
perspective
orthographic
turtle0=Turtle
scale=1
normalShipRad=100*scale
setShipSize 100
shipFadeStart=20 ;steps until the glowing ship starts to fade again
shipGlow=0
blink=0
exploding=false
thrust=0
leaveStep=0
numLeaveSteps=0
leaving=0
drawShip 0 0 0 "draw
end
to setShipSize rad
shipRad=rad
shipSide=((Sin 22.5)*shipRad*2)
shipRad3=shipRad/3
shipRad6=shipRad/6
shipRad6Diag=shipRad/6*1.414
end
to drawShip x y d action
setMaterialSpecular HSB 70 0.5 0.5
setMaterialShininess 10
setLightSpotExponent 2
setTurtle turtle0
setPenSize(List
round(1*scale*shipRad/normalShipRad)
round(1*scale*shipRad/normalShipRad))
r=((255-138)/shipFadeStart*shipGlow+138)/255
g=((255-60)/shipFadeStart*shipGlow+60)/255
b=((255-255)/shipFadeStart*shipGlow+255)/255
if shipGlow > shipFadeStart [r=1 g=1 b=1]
if action == "draw
[blink=blink+1
if blink == 41 [blink=0] ;blink cyles through two seconds, then resets (there are 20 fps)
]
if (or action == "draw action == "redraw) [setPC RGB r g b]
if action == "erase [setPC 0]
ifElse exploding == false
[;draw right side of nose
setPos List x y
setH d
fd shipRad
pos1=Pos
bk shipRad*1.8
(Cylinder shipRad*1.8 shipRad*0.3 0)
fd shipRad*0.8
rt 67.5
fd shipRad3
pos2=Pos
PD
Tesselation
[
fd shipRad3*2
bk 1*scale
light1Pos=Pos
fd 1*scale
rt 112.5
fd shipSide
; if (or leaveStep < numLeaveSteps/3*2 leaving == false)
; [drawShip_light light1Pos]
;draw back of ship, trace back over it partway, draw engine if thrusting, then trace forward again--
;this keeps the engine over top of all the other lines
rt 45
fd shipSide-1.414*scale
rt 45
if(or thrust == true action == "erase)
[setPenSize(List
round(2*scale*shipRad/normalShipRad)
round(2*scale*shipRad/normalShipRad))
]
if(and (leaveStep < numLeaveSteps/5*4) (thrust == true)
(or action == "draw action == "redraw))
[setPC RGB 1 .9 .5
]
fd shipSide+2*scale
rt 45
fd shipSide-1.414*scale
if (or action == "draw action == "redraw) [setPC RGB r g b]
setPenSize(List
round(1*scale*shipRad/normalShipRad)
round(1*scale*shipRad/normalShipRad))
rt 45
fd shipSide
;draw left side of nose
rt 112.5
fd scale
light2Pos=Pos
bk scale
fd shipRad3*2
if (or leaveStep < numLeaveSteps/3*2 leaving == false)
[drawShip_light light2Pos]
lt 93.06
fd scale*shipSide*1.2
rt 141.11
fd scale*shipSide*1.2
]
PU
setPos List x y
setH d
;draw cockpit begin
rt 180
setPC RGB 0 0.5 1
(Cylinder shipRad*0.4 shipRad*0.18 shipRad*0.25)
lt 90
up 90 fd 1 down 90
PD
setPC RGB 0.7 0.5 1
Tesselation
[ fd shipRad6/2
rt 45 fd shipRad6Diag
rt 45 fd shipRad3
rt 90 rt 45 fd shipRad6Diag
lt 45 fd shipRad6
lt 45 fd shipRad6Diag rt 45
rt 90 fd shipRad3
rt 45 fd shipRad6Diag
rt 45 fd shipRad6/2
lt 90 PU
]
;draw cockpit end
]
[ ;explosion--random numbers for the fragment attribute lists are picked in playLoop
if action == "draw [expLen=expLen-shipRad/numExpSteps]
repeat numFrags
[ setPos List x y setH d
rt 360/numFrags*repCount
fal=Item repCount fragments ;fal stands for fragment attribute list
fd shipRad*(Item 1 fal)+expStep*(Item 2 fal)
rt (Item 3 fal)+expStep*(Item 4 fal)
PD
fd expLen*(Item 5 fal)*scale
rt 180
fd expLen*(Item 6 fal)*scale
if (Item 7 fal) == 1
[ rt (Item 8 fal) fd expLen*(Item 9 fal)*scale
]
PU
]
]
if and(shipGlow > 0) (action == "draw)
[ shipGlow=shipGlow-1
]
erase_=false
end
to drawShip_light lightPos
PU
h_=Heading
pos3=Pos
setPos lightPos
setH 225 fd 1.414*scale
;draw light if it is on, erase it if it is off
if and (blink > 19) (or action == "draw action == "redraw) [
setFC RGB .8 .2 .2
; sbitblock round(2.4*scale/(leaveStep+1)) round(2.4*scale/(leaveStep+1))
setFC 0
]
if (action == "erase) [
; sbitblock round(2.4*scale) round(2.4*scale)
]
setPos pos3
setH h_
PD
end