Created
April 1, 2020 09:57
-
-
Save gustafe/3696d6c694e9b8bfdda3dd688a6c3b45 to your computer and use it in GitHub Desktop.
This file contains 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/perl -I /home/gustaf/perl5-OLD/lib/perl5/ | |
use strict; | |
use warnings; | |
use Astro::MoonPhase; | |
binmode( STDOUT, ":utf8" ); | |
sub moon_info { | |
my ($epoch) = @_; | |
my ( $MoonPhase, $MoonIllum, $MoonAge, $MoonDist, | |
$MoonAng, $SunDist, $SunAng ) = phase($epoch); | |
return [ $MoonPhase, $MoonIllum, $MoonAge ]; | |
} | |
sub phase_name { | |
my ( $phase, $illum ) = @_; | |
my $string = ''; | |
if ( $phase < 0.25 ) { $string = 'WaxC' } | |
elsif ( $phase >= 0.25 and $phase < 0.5 ) { $string = 'WaxG' } | |
elsif ( $phase >= 0.5 and $phase < 0.75 ) { $string = 'WanG' } | |
elsif ( $phase >= 0.75 ) { $string = 'WanC' } | |
if ( $illum <= 0.01 ) { return 'NewM' } | |
if ( $illum >= 0.99 ) { return 'Full' } | |
if ( abs( $illum - 0.5 ) <= 0.01 and $string =~ m/Wax/ ) { return "1Q" } | |
if ( abs( $illum - 0.5 ) <= 0.01 and $string =~ m/Wan/ ) { return "3Q" } | |
return $string; | |
} | |
sub phase_emoji { | |
# https://gist.github.com/ddrscott/5339084 | |
# phases = π π π π π π π π | |
# U+1F311 π NEW MOON SYMBOL | |
# U+1f312 π WAXING CRESCENT MOON SYMBOL | |
# U+1f313 π FIRST QUARTER MOON SYMBOL | |
# U+1f314 π WAXING GIBBOUS MOON SYMBOL | |
# U+1f315 π FULL MOON SYMBOL | |
# U+1f316 π WANING GIBBOUS MOON SYMBOL | |
# U+1f317 π LAST QUARTER MOON SYMBOL | |
# U+1f318 π WANING CRESCENT MOON SYMBOL | |
my ( $phase, $illum ) = @_; | |
my $string = ''; | |
my $curr_phase; | |
if ( $phase < 0.25 ) { | |
$string = "\x{1f312}"; # Waxing crescent - π | |
$curr_phase = 'Wax'; | |
} | |
elsif ( $phase >= 0.25 and $phase < 0.5 ) { | |
$string = "\x{1f314}"; # Waxing gibbous - π | |
$curr_phase = 'Wax'; | |
} | |
elsif ( $phase >= 0.5 and $phase < 0.75 ) { | |
$string = "\x{1f316}"; # Waning gibbous - π | |
$curr_phase = 'Wan'; | |
} | |
elsif ( $phase >= 0.75 ) { | |
$string = "\x{1f318}"; # Waning crescent - π | |
$curr_phase = 'Wan'; | |
} | |
if ( $illum <= 0.01 ) { | |
$string = "\x{1f311}"; # new moon - π | |
$curr_phase='Wax'; | |
} | |
if ( $illum >= 0.99 ) { | |
$string= "\x{1f315}"; # full moon - π | |
$curr_phase = 'Wan'; | |
} | |
if ( abs( $illum - 0.5 ) <= 0.01 and $curr_phase =~ m/Wax/ ) { | |
$string = "\x{1f313}"; # first quarter - π | |
} | |
if ( abs( $illum - 0.5 ) <= 0.01 and $curr_phase =~ m/Wan/ ) { | |
$string = "\x{1f317}"; # 3rd quarter - π | |
} | |
return $string; | |
} | |
my $now = shift || time; | |
my $info = moon_info($now); | |
#my $name = phase_name($info->[0],$info->[1]); | |
my $name = phase_emoji( $info->[0], $info->[1] ); | |
my $illum = $info->[1]; | |
my $age = $info->[2]; | |
printf( "%s %.0f%% %.2f\n", $name, $illum * 100, $age ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment