'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+              Spinning Stars by Gareth Bailey          +
'+                       July 2002                       +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +

gosub setup
gosub fadein

label loop
  clear window
  gosub drawcube
  gosub rotate
  gosub rotatestars
gosub db


goto loop

label drawcube
setrgb 1,65,125,145
 
fill triangle xx(1),yy(1) to xx(2),yy(2) to xx(3),yy(3)
fill triangle xx(1),yy(1) to xx(3),yy(3) to xx(4),yy(4)
fill triangle xx(5),yy(5) to xx(6),yy(6) to xx(7),yy(7)
fill triangle xx(5),yy(5) to xx(7),yy(7) to xx(8),yy(8)
fill triangle xx(3),yy(3) to xx(6),yy(6) to xx(7),yy(7)
fill triangle xx(2),yy(2) to xx(3),yy(3) to xx(6),yy(6)
fill triangle xx(1),yy(1) to xx(2),yy(2) to xx(5),yy(5)
fill triangle xx(2),yy(2) to xx(5),yy(5) to xx(6),yy(6)
fill triangle xx(1),yy(1) to xx(4),yy(4) to xx(8),yy(8)
fill triangle xx(1),yy(1) to xx(5),yy(5) to xx(8),yy(8)

'if size>0.3 
gosub drawstars

setrgb 1,0,0,0
for a=1 to 4:line xx(a),yy(a) to xx(a+4),yy(a+4):next a
line xx(1),yy(1) to xx(2),yy(2)
line xx(2),yy(2) to xx(3),yy(3)
line xx(3),yy(3) to xx(4),yy(4)
line xx(4),yy(4) to xx(1),yy(1)
line xx(5),yy(5) to xx(6),yy(6)
line xx(6),yy(6) to xx(7),yy(7)
line xx(7),yy(7) to xx(8),yy(8)
line xx(8),yy(8) to xx(5),yy(5)

return

label drawstars
for a=1 to star
 col   = ((100-sz(a))*2)
 sz(a) = (sz(a)-2)
 setrgb 1,65+col,125+col,146+col
 fill rect sxx(a),syy(a) to sxx(a)+2,syy(a)+2
 
 if sz(a)<-95 then
   sx(a)=-105+ran(190)
   sy(a)=-105+ran(190)
   sz(a)=100
 fi
next a 
return


label rotate

 if size<1 then 
  sz=sz+.5
  size=sin(sz*(pi/180))
 fi

xr=xr+2
if xr>360 xr=xr-360
if xr<0   xr=xr+360
yr=yr+3
if yr>360 yr=yr-360
if yr<0   yr=yr+360
zr=zr+1
if zr>360 zr=zr-360
if zr<0   zr=zr+360

for a=1 to points
 x1=x(a)
 y1=y(a)
 z1=z(a)
 xx=x1
 yy=y1*cosi(xr)+z1*sine(xr)
 zz=z1*cosi(xr)-y1*sine(xr)
 y1=yy
 x1=xx*cosi(yr)-zz*sine(yr)
 z1=xx*sine(yr)+zz*cosi(yr)
 zz=z1
 xx=x1*cosi(zr)-y1*sine(zr)
 yy=x1*sine(zr)+y1*cosi(zr)
 dx(a)=xx
 dy(a)=yy
 dz(a)=zz
 xx(a)=size*(dx(a)/((dz(a)/focus)+1))+320
 yy(a)=size*(dy(a)/((dz(a)/focus)+1))+256
next a
return

label rotatestars
for a=1 to star
 x1=sx(a)
 y1=sy(a)
 z1=sz(a)
 xx=x1
 yy=y1*cosi(xr)+z1*sine(xr)
 zz=z1*cosi(xr)-y1*sine(xr)
 y1=yy
 x1=xx*cosi(yr)-zz*sine(yr)
 z1=xx*sine(yr)+zz*cosi(yr)
 zz=z1
 xx=x1*cosi(zr)-y1*sine(zr)
 yy=x1*sine(zr)+y1*cosi(zr)
 sdx(a)=xx
 sdy(a)=yy
 sdz(a)=zz
 sxx(a)=size*(sdx(a)/((sdz(a)/focus)+1))+320
 syy(a)=size*(sdy(a)/((sdz(a)/focus)+1))+256
next a
return

label db
setdispbuf draw
draw = 1 - draw
setdrawbuf draw
return

label fadein
setrgb 0,0,0,0
for a=1 to 255
clear window
setrgb 0,a,a,a
gosub db
next a

for a=1 to 105 step .5
clear window
col=255-a
setrgb 0,col,col,col
gosub db
next a

return

'=========================================================
'=========================================================
label setup
setrgb 0,150,150,150
open window 640,512

star=20: xr=1: yr=1: zr=1: points=8: focus=500
dim sine(361),cosi(361)
dim sx(star),sy(star),sz(star),sxx(star),syy(star)
dim sdx(star),sdy(star),sdz(star)
dim x(points),y(points),z(points),xx(points),yy(points)
dim dx(points),dy(points),dz(points)

for a=0 to 361
  cosi(a)=cos(a*(pi/180))
  sine(a)=sin(a*(pi/180))
next

for a=1 to star
  sx(a)=-105+ran(190)
  sy(a)=-105+ran(190)
  sz(a)=-105+ran(190)
next a

for a=1 to points 
  read x(a)
  read y(a)
  read z(a)
next a
return

data  100, 100, 100
data -100, 100, 100
data -100, 100,-100
data  100, 100,-100

data  100,-100, 100
data -100,-100, 100
data -100,-100,-100
data  100,-100,-100







