Created
January 21, 2020 20:26
-
-
Save jakebathman/0e6f71662fbad769e8e68049f0e83c03 to your computer and use it in GitHub Desktop.
Get the current phase of the moon, and adjust a sprite for it
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
const phases=[ | |
{"sprite-x":123, "sprite-y":987, phase:"new"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-crescent-1"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-crescent-2"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-crescent-3"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-crescent-4"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-crescent-5"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-crescent-6"}, | |
{"sprite-x":123, "sprite-y":987, phase:"quarter-1"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-gibbous-1"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-gibbous-2"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-gibbous-3"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wax-gibbous-4"}, | |
{"sprite-x":123, "sprite-y":987, phase:"full"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-gibbous-1"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-gibbous-2"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-gibbous-3"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-gibbous-4"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-gibbous-5"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-gibbous-6"}, | |
{"sprite-x":123, "sprite-y":987, phase:"quarter-3"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-crescent-1"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-crescent-2"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-crescent-3"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-crescent-4"}, | |
{"sprite-x":123, "sprite-y":987, phase:"wane-crescent-5"}, | |
{"sprite-x":123, "sprite-y":987, phase:"new"} | |
] | |
let newMoonBaseline = new Date('November 26, 2019 15:05:00') | |
let millisecondsInADay = 86400000 | |
let lunarSynodicPeriod = 29.53049 | |
let daysSinceNewMoon = ((new Date()) - newMoonBaseline) / millisecondsInADay | |
let pctOfCurrentCycle = (daysSinceNewMoon % lunarSynodicPeriod) / lunarSynodicPeriod | |
var phaseIndex = Math.round((phases.length - 1) * pctOfCurrentCycle) | |
console.log(phases[phaseIndex].phase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment