right=1024
bottom=768
set display mode right,bottom,32
backdrop on
color backdrop 0
sync on
echo_max=50
dim boomx#(100)
dim boomy#(100)
dim vx#(100)
dim vy#(100)
dim echo#(echo_max,3)
count=0
echo_r=15
boom=0
gravity#=0.01
mag_max#=250.0
mag#=mag_max#
angle_offset=0
angle_step=45
quit=0
while not quit
  movex=mousemovex()
  movey=mousemovey()
  if movey<>0 then mag#=mag_max#
  if movey=0 and movex=0
    if timer()-t > 100
      gosub star
      mag#=mag#-2.0
      if mouseclick()=0
        if mag#<0.0
          mag#=mag_max#
          gosub set_boom
        endif
        if mag#<15.0 then mag#=15.0
      else
        mag#=mag#-0.01
        if mag#<1.0 then mag#=1.0
      endif
      inc angle_offset
      if angle_offset>angle_step then angle_offset=0
      s=timer()
    endif
  else
    t=timer()
  endif
  if timer()-s > 300
    distance=sqrt((mousex()-echo#(count,1))^2+(mousey()-echo#(count,2))^2)
    if distance>echo_r*5
      inc count
      if count>echo_max then count=0
      echo#(count,1)=mousex()
      echo#(count,2)=mousey()
      echo#(count,3)=255
      s=timer()
    endif
  endif
  if boom>0 then gosub go_boom
  gosub show_echo
  sync
endwhile
end
set_boom:
  ink 0,0
  for i=1 to 100
    x#=(rnd(30)-15)
    y#=sqrt(225-x#^2)
    vy#(i)=(rnd(y#*2)-y#)/20.0
    vx#(i)=x#/20.0
    dot boomx#(i),boomy#(i)
    boomx#(i)=mousex()
    boomy#(i)=mousey()
  next i
  boom=255
return
go_boom:
  ink rgb(boom,0,0),0
  for i=1 to 100
    dot boomx#(i),boomy#(i)
    boomx#(i)=boomx#(i)+vx#(i)
    boomy#(i)=boomy#(i)+vy#(i)
    if boomx#(i)<0 or boomx#(i)>right or boomy#(i)<0 or boomy#(i)>bottom
      boomx#(i)=-1
      boomy#(i)=-1
      vx#(i)=0
      vy#(i)=0
    else
      vy#(i)=vy#(i)+gravity#
      dot boomx#(i),boomy#(i)
    endif
  next i
  dec boom
return
show_echo:
  lasti=echo_max
  for i=0 to echo_max
    if echo#(i,3)>0
      ink echo#(i,3),0
      circle echo#(i,1),echo#(i,2),int(echo#(i,3)/echo_r)
      dec echo#(i,3)
      if echo#(lasti,3)>0
        line echo#(i,1),echo#(i,2),echo#(lasti,1),echo#(lasti,2)
        echo#(lasti,1)=echo#(lasti,1)+(echo#(i,1)-echo#(lasti,1))/200.0
        echo#(lasti,2)=echo#(lasti,2)+(echo#(i,2)-echo#(lasti,2))/200.0
      endif
    endif
    lasti=i
  next i
return
star:
  c#=mag_max#-mag#
  ink rgb(c#,0,0),0
  for angle=angle_offset to 359 step angle_step
    xpoint=cos(angle)*mag#
    ypoint=sin(angle)*mag#
    xoffset=cos(angle)*10
    yoffset=sin(angle)*10
    line mousex()+xpoint,mousey()+ypoint,mousex()+xpoint+xoffset,mousey()+ypoint+yoffset
  next angle
return