MercuryTransit.frink

Download or view MercuryTransit.frink in plain text format


// This program animates the transit of Mercury across the sun

use planets.frink
use sun.frink

timezone = "US/Mountain"
lat = 40 degrees North
long = 105 degrees West

df = ### yyyy-MM-dd-HH:mm ###
datef = ### yyyy-MM-dd ###
tf = ### HH:mm ###

// This graphics object is the animated version
g = new graphics
g.font["Monospaced", .008 degree]
g.antialiasedText[false]
anim = new Animation[.3 s]
win = g.show[800,800]

//for planet = [Planet.Mercury, Planet.Venus]
planet = Planet.Mercury
startdate = #2019-11-11 08:00 AM#
startdate = sunrise[startdate, lat, long]
enddate = sunset[startdate, lat, long]

println["Sunrise is " + (startdate->timezone)]
println["Sunset  is " + (enddate->timezone)]

frame = 0
staticsteps = 5
g2 = new graphics
g2.font["Monospaced", .008 degree]
g2.backgroundColor[.8, .8, 1]
// Draw the sun
g2.color[1,1,0]  // Yellow
sunRadius =   sunRadiusAngle[startdate]
g2.fillEllipseCenter[0, 0, 2 sunRadius, 2 sunRadius]

for d = startdate to enddate step 5 min
{
   [azsun, altsun] = refractedSunAzimuthAltitude[d, lat, long]
   [azp, altp]     = planet.refractedAzimuthAltitude[d, lat, long]

   separation = angularSeparation[azsun, altsun, azp, altp]

   sunRadius =   sunRadiusAngle[d]
   mercuryRadius = planet.radiusAngle[d]
   //println[mercuryRadius -> [0, "deg", "arcmin", "arcsec"]]

   flag = ""
   if separation < sunRadius + mercuryRadius // Touching sun?
   {
      flag = "*"
      
      if separation < sunRadius - mercuryRadius  // Fully inside sun?
         flag = "**"

      g = new graphics
      [skyr,skyg,skyb] = skyDarkness[d, lat, long, [[.1,.1,.1], [.1,.1,.2], [.1,.1,.3], [.1,.1,.4], [.8,.8,1]]]
      g.backgroundColor[skyr, skyg, skyb]
      
      // Draw the sun
      g.color[1,1,0]  // Yellow
      g.fillEllipseCenter[(azsun-azsun) cos[-altsun], -(altsun-altsun), 2 sunRadius, 2 sunRadius]

      // Draw Mercury
      // How much more black could it be?  The answer is none.  None more black.
      g.color[0,0,0]
      g.fillEllipseCenter[(azp-azsun) cos[-altp], -(altp-altsun), 2 mercuryRadius, 2 mercuryRadius]
//      g.add[planet.drawPolygonRelativeToZenith[d, lat, long, azp, -altp, mercuryRadius, true]]
      g.text[d->[tf, timezone], (azp-azsun) cos[-altp], -(altp-altsun), "center", "top"]
      win.replaceGraphics[g]
      anim.add[g]
      
      if frame mod staticsteps == 0  OR  flag == "*"   // Step every 5 steps or when just touching
      {
         g2.color[0,0,0]
         g2.fillEllipseCenter[(azp-azsun) cos[-altp], -(altp-altsun), 2 mercuryRadius, 2 mercuryRadius]
         g2.text[d->[tf, timezone], (azp-azsun) cos[-altp], -(altp-altsun), "center", "top"]
      }
   }
   
   println[(d->timezone) + "\t" + format[separation,"deg", 5] + "\t$flag" ]

   frame = frame + 1
}

g2.show[]
filename = "mercurytransit" + (startdate -> datef) + "_$timezone"
filename =~ %s/\//_/g  // Turn slashes into underscores in filemane.
print["Rendering animation..."]
anim.write["$filename.gif", 700, 700]
println["done."]

g2.write["$filename.png", 1024, 1024]
g2.write["$filename.svg", 1024, 1024]
g2.write["$filename.html", 1024, 1024]
browse["file:$filename.gif"]


Download or view MercuryTransit.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 19944 days, 13 hours, 20 minutes ago.