#!/usr/bin/perl # moonage.pl - Don Yang (uguu.org) # # Everything about the moon -> http://www.moonsystem.to/ # # In comparison, code here are approximations at best, # accurate to at most one day. # # 07/08/03 sub MoonAge { # Synodic period of the moon (days) $syn = 29.530588853; # Age at January 1, 2000, 00:00:00 $a = 23.686; # Get current time. gmtime is independent of system epoch, unlike time. ($sec,$min,$hour,$day,$month,$year,$wday,$yday) = gmtime; # Compute difference between now and January 1, 2000 (days) # The 100/400 leap year adjustments aren't needed, # since perl's time/gmtime functions only go so far. $year -= 100; $d = $yday + $year * 365 + int(($year + 3) / 4) # Leap years (mod 4) - int(($year - 1) / 100) # Non-leap years (mod 100) + int(($year - 1) / 400) # Leap years (mod 400) + ($hour + ($min + $sec / 60) / 60) / 24; # fmod(d + a, syn) $d += $a; $phase = $d - $syn * int($d / $syn); } sub Render { $WIDTH = 48; $HEIGHT = 48; $PI = atan2(0, -1); $w = int($WIDTH); $h = int($HEIGHT * 2/3); # Moon scanlines for($y = -$h; $y <= $h; $y++) { $x = $w * sqrt(1 - ($y * $y) / ($h * $h)); if( $phase < $syn / 2 ) { $left = $x * (1 - 4 * ($phase / $syn)); $right = $x; } else { $left = $x * -1; $right = $x * (3 - 4 * ($phase / $syn)); } for($x = -$w; $x <= $w; $x++) { $grid{$x}{$y} = '1' if( $x >= $left && $x <= $right ); } } # Empty outline for($a = 0; $a < 256; $a++) { $grid{int(($w - 0.9) * cos($a * $PI / 128))} {int(($h - 0.9) * sin($a * $PI / 128))} ||= '2'; } # Fill empty space for($y = -$h; $y <= $h; $y++) { for($x = -$w; $x <= $w; $x++) { $grid{$x}{$y} ||= '0'; } } # Render # 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 # 00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11 # 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # `` '' "" - `` '' "" `' '' "" +- +' +` "" # 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 # 00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11 # 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 # ,, ;: :: XX ,, (: |: 7: +. X: X: X: +. <: 8: 9: # 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 # 00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11 # 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 # .. :: :: X: +, |: X: X: .. X: ): P: +, 8: >: P: # 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 # 00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11 # 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 # .. X: X: X: ,, d: X: ): .. X: b: (: o. d: b: 8: $dict1 = q/ `'" `'" `'"+++"/ . q/,;:X,(|7+XXX+<89/ . q/.::X+|XX.X)P+8>P/ . q/.XXX,dX).Xb(odb8/; $dict2 = q/ `'"-`'" ''"-'`"/ . q/,::X,:::.:::.:::/ . q/.:::,:::.:::,:::/ . q/.:::,:::.:::.:::/; for($y = -$h; $y < $h; $y += 3) { for($x = -$w; $x < $w; $x += 2) { $i = $grid{$x + 1}{$y } . $grid{$x}{$y } . $grid{$x + 1}{$y + 1} . $grid{$x}{$y + 1} . $grid{$x + 1}{$y + 2} . $grid{$x}{$y + 2}; for($d = $index1 = $index2 = 0; $d < 6; $d++) { $index1 += (1 << $d) if( substr($i, $d, 1) eq '1' ); $index2 += (1 << $d) if( substr($i, $d, 1) eq '2' ); } if( ($o = substr($dict1, $index1, 1)) eq ' ' ) { $o = substr($dict2, $index2, 1); } print $o; } print "\n"; } print "age = $phase\n"; } MoonAge(); Render();