09.10.2019, 19:40
(13.08.2018, 11:24)admin Wrote: Here's my version with linear transition. Values at 0:00 and 24:00 are mandatory, values in between can be added as needed.Could this be adjusted for use with two objects for warm and cold white?
Code:function tomins(hour, min) return hour * 60 + min end points = { { hour = 0, min = 0, value = 2500 }, { hour = 7, min = 30, value = 2500 }, { hour = 8, min = 0, value = 3000 }, { hour = 9, min = 0, value = 5000 }, { hour = 16, min = 0, value = 5000 }, { hour = 17, min = 0, value = 3000 }, { hour = 18, min = 30, value = 2500 }, { hour = 24, min = 0, value = 2500 }, } now = os.date('*t') currmins = tomins(now.hour, now.min) for i, point in ipairs(points) do nextmins = tomins(point.hour, point.min) if nextmins >= currmins then nextpoint = point prevpoint = points[ i - 1 ] or nextpoint prevmins = tomins(prevpoint.hour, prevpoint.min) break end end deltamins = nextmins - prevmins if deltamins > 0 then delta = (nextpoint.value - prevpoint.value) * (currmins - prevmins) / deltamins else delta = 0 end value = math.floor(prevpoint.value + delta) log(now.hour, now.min, value)