risesetchart.frink

View or download risesetchart.frink in plain text format


// Calculates moon and sun rise/set times and azimuths.

use sun.frink

start = #2010-02-01#
end =   #2010-02-10#

tz = "Hawaii" // timezone[]

lat  = 20.7 degrees North
long = 156.3 degrees West

time = start
moonrise = moonset = sunrise = sunset = time

g = new graphics
line = 0

while (time < end)
{
   moonrise = moonrise[moonrise, lat, long]
   moonset =  moonset[moonset, lat, long]
   if (moonrise > moonset)
      moonrise = moonrise[moonrise-1 day, lat, long]

   [moonriseaz, alt] = refractedMoonAzimuthAltitude[moonrise, lat, long]
   [moonsetaz, alt] =  refractedMoonAzimuthAltitude[moonset, lat, long]

   moonriseaz = (moonriseaz + 180 degrees) mod circle
   moonsetaz =  (moonsetaz  + 180 degrees) mod circle
   
   sunrise = sunrise[sunrise, lat, long]
   sunset = sunset[sunset, lat, long]
   if (sunrise > sunset)
      sunrise = sunrise[sunrise-1 day, lat, long]

   [sunriseaz, alt] = refractedSunAzimuthAltitude[sunrise, lat, long]
   [sunsetaz, alt] =  refractedSunAzimuthAltitude[sunset, lat, long]

   sunriseaz = (sunriseaz + 180 degrees) mod circle
   sunsetaz =  (sunsetaz  + 180 degrees) mod circle
   
   println["Moonrise: " + (moonrise->tz) + " " + format[moonriseaz, deg, 2]]
   println["Moonset:  " + (moonset->tz)  + " " + format[moonsetaz, deg, 2]]

   println["Sunrise:  " + (sunrise->tz) + " " + format[sunriseaz, deg, 2]]
   println["Sunset:   " + (sunset->tz)  + " " + format[sunsetaz, deg, 2]]

   g.font["SansSerif", 1/4]
   g.color[0,0,0]               // Draw background in black
   g.fillRectCenter[1, line+1/2, .9, .9]
   g.fillRectCenter[2, line+1/2, .9, .9]
   g.color[1,1,1]               // Draw moon in white
   g.add[drawMoonPolygonRelativeToZenith[moonrise, lat, long, 1, line + 1/2, .4, true]]
   g.add[drawMoonPolygonRelativeToZenith[moonset,  lat, long, 2, line + 1/2, .4, true]]

   println[]
   time = time + 1 day
   moonrise = moonrise + 1 day
   moonset = moonset + 1 day
   sunrise = sunrise + 1 day
   sunset = sunset + 1 day
   line = line + 1
}

g.show[]


View or download risesetchart.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 17646 days, 9 hours, 38 minutes ago.