local obj = nil
local light = nil
local hue = 0.0

function HSVtoRGB(h, s, v)
    local i = math.floor(h * 6)
    local f = h * 6 - i
    local p = v * (1 - s)
    local q = v * (1 - f * s)
    local t = v * (1 - (1 - f) * s)
    i = i % 6

    if i == 0 then return Vector3(v, t, p) end
    if i == 1 then return Vector3(q, v, p) end
    if i == 2 then return Vector3(p, v, t) end
    if i == 3 then return Vector3(p, q, v) end
    if i == 4 then return Vector3(t, p, v) end
    if i == 5 then return Vector3(v, p, q) end
end


function OnInit()
    obj = Engine.GetObjectByTag("Light")
    if obj then
        light = obj:GetComponent("LightComponent")
    end
end

function OnUpdate(dt)
    if not light then return end

    hue = (hue + dt * 0.2) % 1.0
    light:SetColor(HSVtoRGB(hue, 1.0, 1.0))
end
