Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIGHT_LEVEL_DAY = 250
- LIGHT_LEVEL_NIGHT = 40
- LIGHT_STATE_NIGHT = -1
- LIGHT_STATE_DAY = 1
- LIGHT_STATE_SUNRISE = 1
- LIGHT_STATE_SUNSET = -1
- lightLevel = LIGHT_LEVEL_NIGHT
- lightState = LIGHT_STATE_NIGHT
- SUNSET = 18 * 3600
- SUNRISE = 6 * 3600
- dayCycle = 24 * 3600
- lightHourDelta = 10--1440 * 10 / dayCycle;
- lightHour = (SUNRISE - (SUNSET - SUNRISE) / 2) + (5 * 60)
- function checkLight()
- lightHour = lightHour + lightHourDelta
- print(string.format("%.2f",lightHour/3600))
- if (lightHour > dayCycle) then
- lightHour = lightHour - dayCycle
- end
- if math.abs(lightHour - SUNRISE) < 2 * lightHourDelta then
- lightState = LIGHT_STATE_SUNRISE
- elseif math.abs(lightHour - SUNSET) < 2 * lightHourDelta then
- lightState = LIGHT_STATE_SUNSET
- end
- newLightLevel = lightLevel
- lightChange = false
- if lightState == LIGHT_STATE_SUNRISE then
- newLightLevel = newLightLevel + (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30
- lightChange = true
- elseif lightState == LIGHT_STATE_SUNSET then
- newLightLevel = newLightLevel - (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30
- lightChange = true
- end
- if (newLightLevel <= LIGHT_LEVEL_NIGHT) then
- lightLevel = LIGHT_LEVEL_NIGHT
- lightState = LIGHT_STATE_NIGHT
- elseif (newLightLevel >= LIGHT_LEVEL_DAY) then
- lightLevel = LIGHT_LEVEL_DAY
- lightState = LIGHT_STATE_DAY
- else
- lightLevel = newLightLevel
- end
- print("lightLevel: "..lightLevel)
- end
- for i = 1, 86400/lightHourDelta do
- checkLight()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement