aUCBLogo Demos and Tests / 3dbutterfly
be 3dbutterfly
ifelse Name? "framenr
[ singleshot=true
][ singleshot=false
]
ifElse (not singleshot) or2 not name? "dphi
[ setUpdateGraph false
perspective
eye=Array 3
eye.2=200
center={0 0 0}
upvector={0 1 0}
phi=0
dphi=0.3
bphi=90
cS hT
setPenColor "white
setPenSize [1 1]
down 90 fd 100 rt 90
o=Orientation
bmpiris=loadImage "iris.png
texIris=Texture bmpiris
pr [press + or - to change the flying speed]
][ phi=10*framenr
]
forever
[ clean
Texture texIris
eye.1=500*Sin phi
eye.3=500*Cos phi
setEye eye center upvector
uP 20*Cos 1*phi
butterfly 100 bphi
setOrientation o
updateGraph
phi=phi+dphi
bphi=70*Sqr Cos 5*phi
if singleshot [break]
if Key?
[ c=readChar
if c==Char 27 [stop]
if c=="+ [dphi=dphi+0.2]
if c=="- [dphi=dphi-0.2]
if c==Char 255
[ c=readCharExt
if c==wxk_numpad_add [dphi=dphi+0.2]
if c==wxk_numpad_subtract [dphi=dphi-0.2]
]
]
]
end
be butterfly size bphi
local [o]
pos0=PosXYZ
o=Orientation
fdist=1
phi=0
x=0
y=0
sphi=1
home
if not name? "grRightWing
[ grRightWing=Graphic [rightwing size]
]
sphi=-1
home
if not name? "grLeftWing
[ grLeftWing=Graphic [leftwing size]
]
setPosXYZ pos0
setOrientation o
body size
butterfly_reset
rightantenna size
butterfly_reset
leftantenna size
butterfly_reset
fd2 size/2
leftRoll bphi
drawGraphic grRightWing
butterfly_reset
fd2 size/2
rightRoll bphi
drawGraphic grLeftWing
butterfly_reset
be body size
PD Ellipsoid size/8 size size/8
end
be butterfly_reset
PU setPosXYZ pos0 setOrientation o
end
be rightwing size
PenDown
Tesselation
[ fdist=1
phi=0
x=0.2
y=0.2
repeat 22 [fd2 size/100 rt2 2]
fd2 size*1.6
repeat 67 [fd2 size/100 rt2 2]
fd2 size*1.2
repeat 43 [fd2 size/100 rt2 2]
fd2 size*1.4
fdist=0.6
phi=0
x=0
y=0
lt2 165 fd2 size/1.2
repeat 60 [fd2 size/100 rt2 1.5]
fd2 size/8
repeat 70 [fd2 size/100 rt2 1.5]
fd2 size/1.4
]
end
be leftwing size
PenDown
Tesselation
[ fdist=1
phi=0
x=0.2
y=0.2
repeat 22 [fd2 size/100 lt2 2]
fd2 size*1.6
repeat 67 [fd2 size/100 lt2 2]
fd2 size*1.2
repeat 43 [fd2 size/100 lt2 2]
fd2 size*1.4
fdist=0.6
phi=0
x=0
y=0
rt2 165 fd2 size/1.2
repeat 60 [fd2 size/100 lt2 1.5]
fd2 size/8
repeat 70 [fd2 size/100 lt2 1.5]
fd2 size/1.4
]
end
be rightantenna size
fd size
rt 90 fd 2 lt 90
make "ANG 1
repeat 16 [PD fd size/25 rt ANG make "ANG ANG+1]
end
be leftantenna size
fd size
lt 90 fd 2 rt 90
make "ANG 1
repeat 16 [PD fd size/25 lt ANG make "ANG ANG+1]
end
be fd2 dist
x=x+dist/fdist/250*sin phi*sphi
y=y+dist/fdist/250*cos phi*sphi
setTexXY x y
forward dist
end
be rt2 ang
phi=phi+ang
right ang
end
be lt2 ang
phi=phi-ang
left ang
end
end