gosub initialise
gosub main
exit

rem ##########################################
label main
 repeat
  frme=frme+1
  if frme=3 frme=1

  setdispbuf cb
  cb=1-cb
  setdrawbuf cb
  clear window

' draw the fans
  for x=-320 to 320 step 40
   yo=co(ang)*100
   b1=128+si(ang)*63
   b2=128+co(ang)*63
   setrgb 1,0,b2,b1
   setrgb 2,b1,b2,0
   setrgb 3,b2,0,b1
   cc=cos((x+ang)*f)*200
   ss=sin((x+ang)*f)*-200
   gtriangle x-20,cc+yo to x,yo to x+20,ss+yo
  next x

' draw the snakes
  for a=1 to 15
   x=co(bx+a*10)*200
   bs=a*2
   br=bs*5+50
   y=si(by+a*10)*200
   setrgb 1,br,0,0
   rect x-bs,y-bs to x+bs,y+bs
   setrgb 1,0,0,br
   rect -x-bs,-y-bs to -x+bs,-y+bs
  next a
  bx=mod(bx+5,360)
  by=mod(by+3,360)

' draw the text
  b$=mid$(m$(ml),1,tp)
  ss=128+si(ang)*60
  setrgb 1,ss,128+co(ang)*60,0
  if mod(ttp,5)>2 b$=b$+"_"
  text -300,-240,b$
  ttp=ttp-1
  if ttp<0 then
   ttp=5
   if tp=len(m$(ml))-2 ttp=100
   tp=mod(tp+1,len(m$(ml)))
   if tp=0 ml=mod(ml+1,4)
  fi

' draw the picture frame
  for a=1 to nt step 4
   for b=0 to 3
    z(a+b)=co(ang)*200
    x=x(a+b)
    y=y(a+b)
    z=z(a+b)
    gosub cl
    tx(b+1)=x
    ty(b+1)=y
    tz(b+1)=z
    b(b+1)=128-(z/2)
   next b
   if a=5 then
    b(1)=0
    b(2)=0
    b(3)=0
   fi
   setrgb 1,b(1),0,0
   setrgb 2,b(2),0,0
   setrgb 3,b(3),0,0
   gtriangle tx(1),ty(1) to tx(2),ty(2) to tx(3),ty(3)
   gtriangle tx(1),ty(1) to tx(4),ty(4) to tx(3),ty(3)
  next a

' draw the fountain
  for a=frme to np step 2
   pz(a)=co(ang)*200
   px(a)=px(a)+pxv(a)
   py(a)=py(a)+pyv(a)
   x=px(a)
   y=py(a)
   pyv(a)=pyv(a)+0.15
   z=pz(a)

   if y>90 or y<-90 or x<-90 or x>90 then
    py(a)=90
    px(a)=0
    pyv(a)=-int(ran(8))
   fi

   gosub cl
   bri=128-(z/2)
   setrgb 1,0,0,bri+50
   fill rect x,y to x+2,y+2
  next a

  ang=mod(ang+1,360)
  yrot=180+co(ang)*180
 until (1=2)
return

rem ##########################################
label cl
 xx=x*co(yrot)-z*si(yrot)
 zz=x*si(yrot)+z*co(yrot)
 x=xx/((zz/focus)+1)
 y=y/((zz/focus)+1)
return

rem ##########################################
label initialise
 open window 640,512
 window origin "cc"

 dim m$(3)
 m$(0)="The 2D in 3D Demo "
 m$(1)="by Xalthorn "
 m$(2)="A 2D Fountain "
 m$(3)="Spinning in 3D space "

 f=pi/180
 dim co(750),si(750)
 for a=0 to 750
  co(a)=cos(a*f)
  si(a)=sin(a*f)
 next a

 nt=8
 dim x(nt),y(nt),z(nt),tx(4),ty(4),tz(4),b(4)
 for a=1 to nt
  read x(a),y(a)
 next a

 np=80
 dim px(np),py(np),pz(np),pxv(np),pyv(np)
 for a=1 to np
  px(a)=0
  pxv(a)=ran(4)-2
  py(a)=91
 next a

 tp=1
 frme=1
 focus=500
return

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


