2017-12-24Click to launch
The phase angle of the Moon is defined as zero for a Full Moon, positive for the waning phase, -180° for a New Moon, and negative for the waxing phase.
We draw a disk, a limb (half-circle) and a terminator (half-ellipse), and color the areas according to the phase.
The next step is to compute the phase from the date. As always, my reference is Jean Meeus' book Astronomical Algorithms.