local function normal( a, b, c )
  local norm = a*a+b*b+c*c
  if norm < 0.0001 then return p end
  norm = 1.0 / math.sqrt( norm )
  return norm *a, norm *b, norm *c
end

local light = {}
light[1], light[2], light[3] = normal( 1.0, 1.0, 0.0 ) --direction TO the light btw
light.target = 1

local targets = {}
local c, s, p = math.cos, math.sin, 2*math.pi
do
  local c, s = c( p * 2 / 7 ), s( p * 2 / 7 )
  local x, y, z = 1, 1, 0
  for i = 1, 7 do
    x, z = c*x-z*s,s*x+z*c
    y = 1 + 0.5 * s
    targets[i] = { x, y, z }
  end
end

function light.setTarget( i )
  light.target = i
end

function light.update( enteringCircle )
  if enteringCircle then light.setTarget( enteringCircle ) end
  if not light.target then return end
  for i = 1, 3 do
    light[i] = 0.999 * light[i] + 0.001 * targets[ light.target ][i]
  end
  light[1], light[2], light[3] = normal( light[1], light[2], light[3] )
end


return light