rem fans
rem copyright Marc Gale (Xalthorn) 2001

gosub initialise

repeat
  gosub flip_screen
  clear window

  gosub draw_fans
  gosub spin_fans

  buttons=peek("port1")

  if buttons=16 then
    inner=inner+1
    outer=outer+1
  fi 

  if buttons=32 and dispfans < num_fans then
    dispfans=dispfans+1
  fi 

  if buttons=64 then
    inner=inner-1
    outer=outer-1
  fi

  if buttons=128 and dispfans > 1 then
    dispfans=dispfans-1
  fi 

until (buttons=16384)

exit

label spin_fans
  for a=1 to num_fans
    for b=1 to 3
      p(a,b)=p(a,b)+p(a,4)
      if p(a,b)>360 then 
        p(a,b)=p(a,b)-360
      fi

      if p(a,b)<0 then 
        p(a,b)=p(a,b)+360
      fi
    next b
  next a
return

label draw_fans
  setrgb 1,255,0,0
  setrgb 2,0,255,0
  setrgb 3,0,0,255

  for a=1 to dispfans
    px1=cosines(p(a,1))
    py1=sines(p(a,1))
    px2=cosines(p(a,2))
    py2=sines(p(a,2))
    px3=cosines(p(a,3))
    py3=sines(p(a,3))

    gtriangle scx+(inner*px1),scy+(inner*py1) to scx+(outer*px2),scy+(outer*py2) to scx+(outer*px3),scy+(outer*py3)
  next a
return

label flip_screen
  setdispbuf d 
  d=1-d
  setdrawbuf d
return

label initialise
  dim sines(720)
  dim cosines(720)

  for a=0 to 720
    cosines(a)=cos(a*(pi/180))
    sines(a)=sin(a*(pi/180))
  next a

  num_fans=50
  dispfans=num_fans / 2
  fanwidth=20
  inner=20
  outer=120

  dim p(num_fans,4)

  for a=1 to num_fans
    p(a,1)=int(ran(360-(fanwidth*2)))+fanwidth
    p(a,2)=p(a,1)-fanwidth
    p(a,3)=p(a,1)+fanwidth
    while (p(a,4) = 0)
      p(a,4)=int(ran(12))-6
    wend
  next a

  sw=640
  sh=512
  scx=sw/2
  scy=sh/2
  d=1

  open window sw,sh
  clear window
return



