03.04.2019, 07:27
Use this:
You can use ph number as object value and set custom values according to phases table (0..7).
Code:
local date = os.date('*t')
local y, m, d = date.year, date.month, date.day
if m < 3 then
y = y - 1
m = m + 12
end
local a = math.floor(y / 100)
local b = math.floor(a / 4)
local c = 2 - a + b
local e = math.floor(365.25 * (y + 4716))
local f = math.floor(30.6001 * (m + 1))
local jd = c + d + e + f - 1524.5
local dn = jd - 2451550.1
local nm = dn / 29.530588853
local dc = (nm % 1) * 29.530588853
local ph
if dc < 1.84566 then
ph = 0
elseif dc < 5.53699 then
ph = 1
elseif dc < 9.22831 then
ph = 2
elseif dc < 12.91963 then
ph = 3
elseif dc < 16.61096 then
ph = 4
elseif dc < 20.30228 then
ph = 5
elseif dc < 23.99361 then
ph = 6
elseif dc < 27.68493 then
ph = 7
else
ph = 0
end
local phases = {
[0] = 'new moon',
[1] = 'evening crescent',
[2] = 'first quarter',
[3] = 'waxing gibbous',
[4] = 'full moon',
[5] = 'waning gibbous',
[6] = 'last quarter',
[7] = 'morning crescent',
}
text = phases[ ph ]
log(ph, text)
You can use ph number as object value and set custom values according to phases table (0..7).