sync on
sync rate 0
cls
type particle_type
   color
   x as float
   y as float
   vx as float
   vy as float
   exist as boolean
   creation_time
endtype
global max_particle_amount
max_particle_amount=3000
dim particle(max_particle_amount) as particle_type
global time as float
oldtimer=timer()
global r as float
global last_tick
do
   cls
   time=(timer()-oldtimer)/1000.0
   oldtimer=timer()
   inpt()
   update_particles()
   sync
loop
 
function inpt()
   inc r,12
   h#=r/390.0
   while h#>1
      dec h#
   endwhile
   color=hsl(h#,1,0.5)
   add_particle(mousex(),mousey(),40.0*cos(r),40.0*sin(r),color)
endfunction
 
function update_particles()
   for n=1 to max_particle_amount
      if particle(n).exist
         particle(n).x=particle(n).x+particle(n).vx*time
         particle(n).y=particle(n).y+particle(n).vy*time
         particle(n).vy=particle(n).vy*1.01
         particle(n).vx=particle(n).vx*1.01
         ink particle(n).color,0
         box particle(n).x,particle(n).y,particle(n).x+2,particle(n).y+2
         if timer()>particle(n).creation_time+3000 or particle(n).x<0 or particle(n).x>screen width() or particle(n).y<0 or particle(n).y>screen height()
            particle(n).exist=0
         endif
      endif
   next n
endfunction
 
function add_particle(x#,y#,vx#,vy#,c)
   n=freeparticle()
   particle(n).exist=1
   particle(n).x=x#
   particle(n).y=y#
   particle(n).vx=vx#
   particle(n).vy=vy#
   particle(n).color=c
   particle(n).creation_time=timer()
endfunction
 
function freeparticle()
   n=1
   while particle(n).exist=1 and n<max_particle_amount
      inc n
   endwhile
endfunction n
 
 
function hsl(H#,S#,L#)
 
   local r
   local g
   local b
   if ( S# = 0 )                       `HSL values = 0 ÷ 1
 
      rR# = L# * 255                      `RGB results = 0 ÷ 255
      rG# = L# * 255
      rB# = L# * 255
 
   else
 
         if ( L# < 0.5 )
            var_2# = L# * ( 1 + S# )
         else
 
            var_2# = ( L# + S# ) - ( S# * L# )
         endif
 
         var_1# = (2 * L#) - var_2#
 
         R = 255.0 * Hue_2_RGB( var_1#, var_2#, H# + ( 1.0 / 3.0 ) )
         G = 255.0 * Hue_2_RGB( var_1#, var_2#, H# )
         B = 255.0 * Hue_2_RGB( var_1#, var_2#, H# - ( 1.0 / 3.0 ) )
 
   endif
color=rgb(r,g,b)
endfunction color
 
Function Hue_2_RGB( v1#, v2#, vH# )
 
   if ( vH# < 0 ) then vH# = vH# + 1
   if ( vH# > 1 ) then vH# = vH# - 1
   if ( ( 6 * vH# ) < 1 ) then res#=( v1# + ( v2# - v1# ) * 6.0 * vH# ): exitfunction ( res# )
   if ( ( 2 * vH# ) < 1 ) then exitfunction ( v2# )
   if ( ( 3 * vH# ) < 2 ) then res#=( v1# + ( v2# - v1# ) * ( ( 2.0 / 3.0 ) - vH# ) * 6.0 ):exitfunction ( res# )
 
Endfunction v1#