aUCBLogo Demos and Tests / drawasteroids2
be drawasteroids2 [singleshot false][FrameNr 0]
if (not singleshot) or2 FrameNr==0
[ setUpdateGraph false
perspective
allfullscreen
fullscreen
PU hT
setPC RGB .5 .5 .5
setSC 0
GraphicStart
r=50
drawAsteroid r
a=GraphicEnd
size=200
n=40
poss=[]
dpos=[]
ori=[]
dw=[]
w=array n
repeat n
[ i=repCount
do_while
[ setxyz size*(rnd-0.5) size*(rnd-0.5) size*(rnd-0.5)
again=false
for [j 1 i-1 1]
[ if (DistanceXYZ poss.j) < r [again=true]
]
][again]
push "poss PosXYZ
push "dpos (List rnd-0.5 rnd-0.5 rnd-0.5)*4
right random 360
up random 360
push "ori Orientation
push "dw rnd
w.repCount=0
]
poss=Array poss
dpos=Array dpos
ori=Array ori
dw=Array dw
]
while [true]
[ clean
poss=poss+dpos
w=Modulo w+dw 360
repeat n
[ i=repCount
if (maxNorm poss.i) > size
[ for [d 1 3]
[ if (abs poss.i.d) > size
[ ifelse rnd > 0.5
[ setItem d dpos.i -dpos.i.d
][ if (poss.i).d > size
[ setItem d poss.i poss.i.d-2*size
]
if (poss.i).d < -size
[ setItem d poss.i poss.i.d+2*size
]
]
]
]
poss.i=poss.i+dpos.i
]
setPosXYZ poss.i
setOrientation ori.i
rightRoll w.i
drawGraphic a
]
updateGraph
if singleshot [break]
if key? [notFullScreen splitScreen stop]
]
end
be drawAsteroid r
local [s dist d j i]
s=18
dist=array s*2
repeat s*2
[ d=array s
repeat s
[ j=repCount
w=180*j/s
d.j=r*(0.6+rnd*0.3*(Sin w)+0.1*sqr Cos w)
]
dist.repCount=d
]
repeat s*2
[ i=1+Modulo repCount-1 s*2
setItem 1 dist.i (get 1 1)
setItem s dist.i (get 1 s)
setItem 2 dist.i ((get 1 1)*2+(get 1 i))/3
setItem s-1 dist.i ((get 1 s)*2+(get 1 i))/3
]
repeat s*2
[ i=1+Modulo repCount-1 s*2
repeat s
[ j=repCount
setItem j dist.i ((get i j)+(get i+1 j)+(get i j+1))/3
]
]
fd r
SurfaceStart
back r
repeat s*2+1
[ i=1+Modulo repCount-1 s*2
repeat s+1
[ j=1+Modulo repCount-1 s
d=(dist.i).j
setPC hsb i*j 1 1
PD fd d PU
back d
rt 180/s
]
left 180+180/s
SurfaceColumn
rightRoll 180/s
]
SurfaceEnd
be get i j
if i==0 [i=s*2]
if j==0 [j=s]
i=1+Modulo i-1 s*2
j=1+Modulo j-1 s
output (dist.i).j
end
end