Hacker News new | ask | show | jobs
by saltcured 700 days ago
Yeah these things are really piles of code and feature integration and can obscure the underlying logic somewhat.

1. Moon phase (or "age") is trivial to compute using modular arithmetic, given an absolute moment in time as an offset relative to a reference full moon time.

2. Converting datetime formats to a reference time can get complicated, particularly if you want to handle historical dates where calendar systems changed.

3. Converting phase into named bins is a pretty trivial lookup table to quantize the continuous phase value.

4. Converting phase into an approximate percent illumination is pretty trivial geometry, using a simplified model of the moon as a circle with an elliptical boundary for the shaded versus lit part.

5. Converting percent illumination into apparent brightness requires much more work to actually compute the positions of the sun, moon, and earthbound observer.

6. Finding moonrise and moonset times requires even more work to repeatedly find the positions and search for horizon crossings.

Edit: and computing practical brightness is even more complex as you need to fuse together the above with meteorological data to consider what light actually reaches the observer!