mithengemoon.frink


// Program to calculate moon crossing of the Infinite Corridor at MIT
// known as "MIThenge"
//
// More info at also http://web.mit.edu/planning/www/mithenge.html
// Thanks to Keith Winstein, Ken Olum, Lenny Foner, and Matthias Huerlemann
// for various data and surveying assistance.
//
// For worked predictions, see http://futureboy.us/mithenge/
//
// Alan Eliasen, eliasen@mindspring.com

use mithengecorridor.frink
use sun.frink

sep = "\t"
preamble = ""

if length[ARGS] > 0 && ARGS@0 == "--html"
{
   sep = "<TD>"
   preamble = "<TR><TD>"
}

date = #2009-04-01#
dateOut = ### yyyy-MM-dd hh:mm:ss a zzz ###

while (date < #2009-05-01#)
{
   date = moonSecantAzimuth[date, lat, long, corridorAzimuthMeeus, temperature, pressure]
   
   // Generate date key suitable for use in looking up in "mean" dictionary
   dateKey = date -> ###M-d###

   // Comment out this line to use hardcoded temperature in mithengecorridor
   temperature = mean@dateKey
   
   [azimuth, altitude] = refractedMoonAzimuthAltitude[date, lat, long, temperature, pressure]
   print[preamble]
   print[(date -> [dateOut, "Eastern"]) + "$sep"]
   print[format[JD[date],day,5] + "$sep"]
   print[format[altitude,degrees,2] + "$sep"]
   iFrac = moonIlluminatedFraction[date]
   print[format[iFrac, percent, 1] + "$sep"]
   radiusAngle = moonRadiusAngle[date]
   print[format[F[temperature],1,0]]
   if altitude < (1.16 degrees + radiusAngle) and altitude > -radiusAngle
   {
      print["$sep*"]
      drawMoons[date, lat, long, temperature, pressure, corridorAzimuth]
   }
   println[]
   
   date = date + 1 day
}

// Function to draw the path of the moon as it crosses the corridor.
drawMoons[date, lat, long, temperature, pressure, corridorAzimuth] :=
{
   g = new graphics
   g.font["SansSerif", .05 deg]

   d1 = date - 2 min
   do
   {
      [az, alt] = refractedMoonAzimuthAltitude[d1, lat, long, temperature, pressure]
      drawMoon[g, d1, lat, long, temperature, pressure]
      d1 = d1 - 2 min
   } while alt < 1.2 degrees

   d1 = date + 2 min
   do
   {
      [az, alt] = refractedMoonAzimuthAltitude[d1, lat, long, temperature, pressure]
      drawMoon[g, d1, lat, long, temperature, pressure]
      d1 = d1 + 2 min
   } while alt > 0 degrees
   
   drawMoon[g, date,         lat, long, temperature, pressure]

   g.color[0,0,0,.7]
   g.drawRectSides[corridorAzimuth - .5 degrees, 0 degrees, corridorAzimuth + .5degrees, -.91 degrees]
   
   g.line[corridorAzimuth, 0 degrees, corridorAzimuth, -.91 degrees]

   // Draw floor
   g.fillRectSides[corridorAzimuth - 1 degree, 0 degrees, corridorAzimuth + 1 degree, .5 degrees]

   // Text description
   g.color[1,1,1]
   df = ###yyyy-MM-dd hh:mm:ss a zzz###
   g.font["SansSerif", "bold", .1 degrees]
   g.text[(date->[df,"Eastern"]), corridorAzimuth, .2 degrees]
   g.text["Illuminated fraction: " + format[moonIlluminatedFraction[date], percent, 1] + "%", corridorAzimuth, .3 degrees]

   // Render files
   sd = ###yyyy-MM-dd###
   g.write["moon" + (date->[sd, "Eastern"]) + ".png", 640, 480]
   g.write["moonthumb" + (date->[sd, "Eastern"]) + ".png", 100, 80]
   g.write["moon" + (date->[sd, "Eastern"]) + ".svg", 640, 480]
   g.show[]
}

// Draw a single moon image with time/date stamp.
drawMoon[g, date, lat, long, temperature, pressure] :=
{
   shortDate = ###hh:mm:ss a###
   [azimuth, altitude] = refractedMoonAzimuthAltitude[date, lat, long, temperature, pressure]
   
   trueAz = (azimuth + 180 degrees) mod circle
//   println["True azimuth at $date is " + (trueAz->degrees)]
   ra = moonRadiusAngle[date]
//   println["Radius angle is " + (ra->"degrees")]

   // Draw vertical
   g.color[.7,.7,.7]
   g.line[trueAz - ra - 0.02 degree, -altitude, trueAz, -altitude]
   g.fillRectCenter[trueAz, -altitude, .02 degree, .02 degree]

   // Draw the moon
   g.color[0,0,0]
   g.add[drawMoonPolygonRelativeToZenith[date, lat, long, trueAz, -altitude, ra , false]]
   g.text[(date -> [shortDate, "Eastern"]), trueAz - ra - .03 degree, -altitude, "right", "center"]

//    g.text[(date -> [shortDate, "Eastern"]), trueAz, -altitude]
}


View or download mithengemoon.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 14704 days, 22 hours, 32 minutes ago.