Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1.   LIGHT_LEVEL_DAY = 250
  2.     LIGHT_LEVEL_NIGHT = 40
  3.     LIGHT_STATE_NIGHT = -1
  4.     LIGHT_STATE_DAY = 1
  5.     LIGHT_STATE_SUNRISE = 1
  6.     LIGHT_STATE_SUNSET = -1
  7.    
  8.     lightLevel = LIGHT_LEVEL_NIGHT
  9.     lightState = LIGHT_STATE_NIGHT
  10.  
  11.  
  12.     SUNSET = 18 * 3600
  13.     SUNRISE = 6 * 3600
  14.     dayCycle = 24 * 3600
  15.     lightHourDelta = 10--1440 * 10 / dayCycle;
  16.     lightHour = (SUNRISE - (SUNSET - SUNRISE) / 2) + (5 * 60)
  17.  
  18. function checkLight()  
  19.   lightHour = lightHour + lightHourDelta
  20.   print(string.format("%.2f",lightHour/3600))
  21.  
  22.     if (lightHour > dayCycle) then
  23.         lightHour = lightHour - dayCycle
  24.     end
  25.    
  26.     if math.abs(lightHour - SUNRISE) < 2 * lightHourDelta then
  27.         lightState = LIGHT_STATE_SUNRISE
  28.     elseif math.abs(lightHour - SUNSET) < 2 * lightHourDelta then
  29.         lightState = LIGHT_STATE_SUNSET
  30.     end
  31.  
  32.  
  33.   newLightLevel = lightLevel
  34.     lightChange = false
  35.  
  36.   if lightState == LIGHT_STATE_SUNRISE then
  37.             newLightLevel = newLightLevel + (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30
  38.             lightChange = true
  39.     elseif lightState == LIGHT_STATE_SUNSET then
  40.         newLightLevel = newLightLevel - (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30
  41.         lightChange = true
  42.   end
  43.  
  44.  
  45.  
  46.     if (newLightLevel <= LIGHT_LEVEL_NIGHT) then
  47.         lightLevel = LIGHT_LEVEL_NIGHT
  48.         lightState = LIGHT_STATE_NIGHT
  49.     elseif (newLightLevel >= LIGHT_LEVEL_DAY) then
  50.         lightLevel = LIGHT_LEVEL_DAY
  51.         lightState = LIGHT_STATE_DAY
  52.     else
  53.         lightLevel = newLightLevel
  54.     end
  55.    
  56.     print("lightLevel: "..lightLevel)
  57. end
  58.    
  59.    
  60. for i = 1, 86400/lightHourDelta do
  61.   checkLight()
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement