Created
October 2, 2023 21:16
-
-
Save cvasqxz/37593530c2f5b31532a86d2cd82b2937 to your computer and use it in GitHub Desktop.
moon phase calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
def moon(): | |
MOON_DURATION = 29.53058770576 | |
KNOWN_NEW_MOON_EPOCH = 947116800 | |
SECONDS_IN_A_DAY = 86400 | |
PHASES = ["π", "π", "π", "π", "π", "π", "π", "π", "π"] | |
moonphase = (time() - KNOWN_NEW_MOON_EPOCH)/SECONDS_IN_A_DAY | |
moonphase %= MOON_DURATION | |
moonphase /= MOON_DURATION | |
moonphase = round(moonphase*8) | |
return PHASES[moonphase] | |
if __name__ == '__main__': | |
moonphase = moon() | |
print(moonphase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment