Created
October 17, 2014 18:10
-
-
Save bwinton/abd1d037c8a2eeb7afc7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/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