rem Fire2
rem copyright Marc Gale (Xalthorn) 2001
rem
rem a colour changing fire effect

gosub initialise
gosub main_loop
exit

label main_loop
 repeat
  gosub flip_screen
  clear window

  gosub draw_motes
  gosub cycle

  buttons=peek("port1")

 until (and(buttons,16384)>0)
return

label cycle
 cycle_delay=cycle_delay-1
 if cycle_delay=0 then
  cycle_delay=cycle_reset
  gosub change_color
 fi

 if red<newred then
  red=red+0.01
 fi

 if red>newred then
  red=red-0.01
 fi

 if green<newgreen then
  green=green+0.01
 fi

 if green>newgreen then
  green=green-0.01
 fi

 if blue<newblue then
  blue=blue+0.01
 fi

 if blue>newblue then
  blue=blue-0.01
 fi
return

label change_color
 newred=int(ran(100))/100
 newgreen=int(ran(100))/100
 newblue=int(ran(100))/100
return

label draw_motes
 for a=1 to nummotes
  xpos=motes(a,1)
  ypos=motes(a,2)
  strength=motes(a,3)

  setrgb 1,strength*red,strength*green,strength*blue
  dot xpos,ypos

  strength=strength-2
  if strength<=0 then
   motes(a,1)=sw/2+int(ran(10))
   motes(a,2)=sh/2
   motes(a,3)=int(ran(155))+100
  else
   motes(a,1)=xpos+int(ran(3))-1
   motes(a,2)=ypos-1
   motes(a,3)=strength
  fi
 next a
return

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

label initialise
 sw=640
 sh=512
 curbuf=0
 nummotes=180

 dim motes(nummotes,3)
 rem 1=x
 rem 2=y
 rem 3=strength

 for a=1 to nummotes
  motes(a,1)=sw/2+int(ran(10))
  motes(a,2)=(sh/2)
  motes(a,3)=int(ran(100))
 next a

 red=1
 green=0.5
 blue=0

 newred=1
 newgreen=0.5
 newblue=0

 cycle_reset=200
 cycle_delay=cycle_reset

 open window sw,sh
 clear window
return






