Download or view daylight.frink in plain text format
// Calculates duration of daylight over the course of a year. It now also
// graphs sunrise and sunset times over the course of a year, including offsets
// for daylight saving times.
// Requires the sun.frink high-precision astronomical library.
// Requires the Grid.frink grid-drawing library.
use sun.frink
use Grid.frink
lat = DMS[40, 0, 0] North
long = DMS[105, 0, 0] West
tz = "US/Mountain"
out = ### yyyy-MM-dd ###
time = ### HH:mm:ss ###
temp = F[64]
pressure = 29.90 inHg
g = new graphics
pRise = new polyline
pSet = new polyline
date = beginningOfYear[now[], tz]
enddate = beginningOfYearPlus[date, 1, tz]
while date < enddate
{
sunrise = sunrise[date+6 hours, lat, long, temp, pressure]
sunset = sunset[date+18 hours, lat, long, temp, pressure]
daylength = sunset - sunrise
print[(date -> [out, tz]) + "\t" + (daylength -> [hour, min, sec, 0])]
println["\t" + (sunrise -> [time, tz]) + "\t" + (sunset-> [time, tz])]
// println["date is $date"]
pRise.addPoint[JD[date], (sunrise - date)/s]
pSet.addPoint[JD[date], (sunset - date)/s]
// println[(sunrise-date)/s]
// println[(sunset-date)/s]
date = beginningOfNextDay[date, tz]
}
g.add[pRise]
g.add[pSet]
grid = new Grid
grid.font["Monospaced", 20 min/s]
grid.color[0,0,0,.4]
grid.makeVerticalCalendarLines[g, Grid.MONTH, false, tz]
grid.makeVerticalCalendarLabels[g, Grid.MONTH, false, tz]
grid.makeHorizontalLines[g, hour/s, false]
grid.makeHorizontalLabels[g, hour/s, hour/s, false, {|x| floor[x*second /hours] + ":00"}]
grid.color[0,0,0,.2]
grid.makeVerticalCalendarLines[g, Grid.DAY_OF_MONTH, false, tz]
grid.makeHorizontalLines[g, 10 min/s, false]
g.add[grid.getGrid[]]
g.show[]
tz2 = tz
tz2 =~ %s/\//_/g;
g.write["daylight_$tz2.png", 2000, 680]
Download or view daylight.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, eliasen@mindspring.com