function fx.init()

 lensflare_flare = sprites_load("lensflare_flare")

 lensflare_halo_1 = sprites_load("lensflare_halo_1")
 lensflare_halo_2 = sprites_load("lensflare_halo_2")
 lensflare_halo_3 = sprites_load("lensflare_halo_3")

 lensflare_burst_1 = sprites_load("lensflare_burst_1")
 lensflare_burst_2 = sprites_load("lensflare_burst_2")
 lensflare_burst_3 = sprites_load("lensflare_burst_3")


 function bindings.afterUpdate()
  lensflare_old = lensflare
  lensflare = {}
 end

 function bindings.viewportRender(viewport, worm)
  local bitmap = viewport:bitmap()
  fx.lensflare_render(bitmap, viewport)
 end
 print("Gus 0.9c FX-lib initialized")

end

function fx.lensflare_render(bitmap, viewport)
 if lensflare_old then
  local i = 1
  while lensflare_old[i] do

--extract elements from list
   local lx = lensflare_old[i]
   local ly = lensflare_old[i+1]
   local strength = lensflare_old[i+2]

--converting to viewport frame

  lx, ly = viewport:from_map(lx,ly)

--Setting up direction vector
   local vx = lx - 160
   local vy = ly - 120

--drawing
   gfx_set_add(strength)
   lensflare_flare:render(bitmap, 0, vx + 160, vy + 120)
 
   lensflare_halo_1:render(bitmap, 0, vx * 0.5 + 160, vy * 0.5 + 120)
   lensflare_halo_2:render(bitmap, 0, vx * 0.125+ 160, vy * 0.125 + 120)
   lensflare_halo_3:render(bitmap, 0, vx * -0.25 + 160, vy * -0.25 + 120)

   lensflare_burst_1:render(bitmap, 0, vx * 0.333 + 160, vy * 0.333 + 120)
   lensflare_burst_2:render(bitmap, 0, vx * -0.5 + 160, vy * - 0.5 + 120)
   lensflare_burst_3:render(bitmap, 0, vx * -0.18 + 160, vy * -0.18 + 120)

--advance through list
   i = i + 3

  end
 end
 gfx_reset_blending()
end

function fx.lensflare(x, y, strength)
 if lensflare then
  table.insert(lensflare, x)
  table.insert(lensflare, y)
  table.insert(lensflare, strength)
 else
  lensflare = {x, y, strength}
 end
end