Phases of the moon

brian_d_foy on 2003-01-23T06:34:11

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.

#!/usr/bin/perl

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.