Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Thursday January 23, 2003
01:34 AM

Phases of the moon

[ #10134 ]

I am adding to my almanac. Tonight, it is phases of the moon.

I calculate the current lunation cycle (k), then use that to get the dates of the New Moon (0), First Quarter Moon (0.25), Full Moon (0.50), and Last Quarter Moon (0.75). Each of those has a date I want to know.

use Astro::MoonPhase;
package Astro::MoonPhase;
use Date::Format;
my $lunation = lunation();
my @dates =
    map { time2str( "%h %e", $_ ) }
    map { jdaytosecs( truephase( $lunation, $_ ) ) }
        ( 0, 0.25, 0.5, 0.75 );
printf "N: %s   1: %s   F: %s   3: %s\n", @dates;
sub lunation
    my $sdate = jtime( shift || time );
    my $k = undef;
    my $ndate1 = meanphase( $sdate, 0.0, \$k );
    $k++ if $ndate < $sdate;
    return $k;

I add the output to my weather script. Soon I can make pretty pictures with this sort of script, and then I will not even need to go outside. It would not matter much if I did go outside because the lights of the big city pretty much wash out any astrological object. Maybe it is different out near Crystal Lake.