Skip to content

Instantly share code, notes, and snippets.

@bwinton
Created October 17, 2014 18:10
Show Gist options
  • Select an option

  • Save bwinton/abd1d037c8a2eeb7afc7 to your computer and use it in GitHub Desktop.

Select an option

Save bwinton/abd1d037c8a2eeb7afc7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var suncalc = require('suncalc');
var phase = suncalc.getMoonIllumination(new Date()).phase;
var phases = [
"πŸŒ‘",
"πŸŒ’", "πŸŒ’", "πŸŒ’", "πŸŒ’", "πŸŒ’", "πŸŒ’", "πŸŒ’",
"πŸŒ“",
"πŸŒ”", "πŸŒ”", "πŸŒ”", "πŸŒ”", "πŸŒ”", "πŸŒ”", "πŸŒ”",
"πŸŒ•",
"πŸŒ–", "πŸŒ–", "πŸŒ–", "πŸŒ–", "πŸŒ–", "πŸŒ–", "πŸŒ–",
"πŸŒ—",
"🌘", "🌘", "🌘", "🌘", "🌘", "🌘", "🌘",
"🌚",
"🌝"
];
stepPhase = function (phase, randomVal) {
if (randomVal === undefined) {
randomVal = 0.1;
}
var len = phases.length - 2;
var rv = Math.round(phase * len) % len;
if (Math.random() <= randomVal && rv === 0) {
rv = 8;
} else if (Math.random() <= randomVal && rv === 4) {
rv = 9;
}
return rv;
}
console.log(phases[stepPhase(phase)]);
function test() {
for (var i = 1; i <= 31; i++) {
var phase = suncalc.getMoonIllumination(new Date(2014, 9, i)).phase;
console.log("2014-09-" + i, phase, phases[stepPhase(phase)]);
};
}
// test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment