plotCambridgeTemp.frink

Download or view plotCambridgeTemp.frink in plain text format


/** This program plots the average cambridge temperature for any moment of
    the year, based on Fourier analysis of average temperatures. */

use cambridgetempFourier.frink
use Grid.frink

g = new graphics
g.stroke[2 hours]
g.font["SansSerif", 2 degF]
p = new polyline

tz = "US/Eastern"

sd = beginningOfYear[now[], tz]
ed = beginningOfYearPlus[now[], 1, tz]

for d = sd to ed step 30 min
   p.addPoint[JD[d], -cambridgeTemp[d]]

g.add[p]

grid = new Grid
grid.font["Monospaced", .9 degF]
grid.color[0,0,0,.4]
monthFunction = {|date, tz|
                 fmt = ### MMM ###
                 date -> [fmt, tz]
                }

// TODO:  Make this easier in Grid.frink.  We should be able to make lines
// and labels in one call.              
grid.makeVerticalCalendarLines[g, Grid.MONTH, false, tz]
grid.makeVerticalCalendarLabels[g, Grid.MONTH, false, tz, monthFunction]

// Draw degree lines  (Can we make this easier in Grid.frink?  The tricky part
// here is that Fahrenheit lines don't follow a multiplicative offset of any
// unit of temperature like Kelvin.  If you wrote this as a multiple of K,
// the lines would be incorrectly offset.)              
[first, highest, last, lowest] = getBoundingBox[g]

g.font["SansSerif", .9 degF]
for temp = ceil[F[-lowest]] to floor[F[-highest]]
{
   f = F[temp]
   g.line[first, -f, last, -f]
   g.text[temp, first, -f, "right", "center"]
}

g.add[grid.getGrid[]]
g.show[]
g.write["plotCambridgeTemp.svg", 1024, 800]
g.write["plotCambridgeTemp.html", 1024, 800]


Download or view plotCambridgeTemp.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, 10 hours, 59 minutes ago.