Skip to content

Instantly share code, notes, and snippets.

@bwinton
Created October 15, 2014 20:27
Show Gist options
  • Select an option

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

Select an option

Save bwinton/a616da940a9736fedbea 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 rv = Math.round(phase * 8) % 8;
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, phases[stepPhase(phase, 1)]);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment