Version 1 of moon phase

Updated 2004-09-13 11:26:46 by suchenwi

Richard Suchenwirth 2004-09-13 - http://www.faqs.org/faqs/astronomy/faq/part3/ (item C.11) describes John Horton Conway's approximation for the moon phase of a given date. Here it is in Tcl:

 proc moonphase date {
    set y [clock format $date -format %Y]
    set delta [expr {$y/100==19? 4: 8.3}]
    scan [clock format $date -format %m] %d m
    set m [expr {$m==1? 3: $m==2? 4: $m}]
    scan [clock format $date -format %d] %d d
    set t [expr ($y%100)%19]
    if {$t>9} {incr t -19}
    puts y:$y,delta:$delta,m:$m,d:$d,t:$t
    expr {(round(($t*11)%30+$m+$d-$delta)%30)}
 }

Testing:

 % moonphase [clock scan "June 6, 1944"]
 14

which matches the FAQ's example and stands for (almost) full moon.


Arts and crafts of tcl-Tk programming