FANDOM


local centerX = display.contentCenterX
local centerY = display.contentCenterY
 
local moonText = display.newText("Moon phase.",centerX, centerY, nil, 40)
moonText:setFillColor(1,0,0)
 
local function julianDate(d, m, y) 
local mm, yy, k1, k2, k3, j        
        yy = y - math.floor((12 - m) / 10)
        mm = m + 9
        if (mm >= 12) then
            mm = mm - 12
        end
        k1 = math.floor(365.25 * (yy + 4712))
        k2 = math.floor(30.6001 * mm + 0.5)
        k3 = math.floor(math.floor((yy / 100) + 49) * 0.75) - 38
        j = k1 + k2 + d + 59
        if (j > 2299160) then
            j = j - k3  
        end
        return j
    end 
 
    local function  moonAge(d, m, y)
        local j, ip, ag
        j = julianDate(d, m, y)
        ip = (j + 4.867) / 29.53059
        ip = ip - math.floor(ip)
        if (ip < 0.5) then
            ag = ip * 29.53059 + 29.53059 / 2
        else
            ag = ip * 29.53059 - 29.53059 / 2
        end
        print(ag)
        return ag
    end
 
 
local theMoon = moonAge(22,02,2016)
print(theMoon)
if  theMoon >=  29  then 
    moonText.text = "New Moon"
    elseif theMoon < 29 and theMoon > 23 then 
    moonText.text = "Waning Crescent"
    elseif theMoon < 23 and theMoon > 22 then 
    moonText.text = "Last Quarter"
    elseif theMoon < 22 and theMoon > 15 then 
    moonText.text = "Waning gibbous"
    elseif theMoon < 15 and theMoon > 13 then 
    moonText.text = "Full Moon"
    elseif theMoon < 13 and theMoon > 8 then 
    moonText.text = "Waxing gibbous"
    elseif theMoon < 8 and theMoon > 6 then 
    moonText.text = "First Moon"
    elseif theMoon < 6 and theMoon > 1 then 
    moonText.text = "Waxing crescent"
    else                     
    moonText.text = "New Moon"
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.