View or download latitudeComparison.frink in plain text format

/** This program allows you to draw multiple country outlines shifted by
    longitude so you can compare how latitudes in each country compare. */

use Country.frink

drawCountry[g is graphics, code, longitudeOffset] :=
   countries = Country.getCountryList[]
   country = countries@code
   firstPoly = true
   for poly = country.borders
      p = new polygon
      for [x, y] = poly
         p.addPoint[x degrees + longitudeOffset, -y degrees]

      // Label first (which will be the largest) polygon
      if firstPoly
         [cx, cy] = p.getCentroid[]
         g.text[code, cx, cy]
         firstPoly = false;

   return g

g = new graphics
g.font["SansSerif", 1 degree]
g.drawCountry[g, "US", 0 degrees]
g.drawCountry[g, "DE", -120 degrees]
g.drawCountry[g, "GB", -120 degrees]
g.drawCountry[g, "PL", -120 degrees]
g.drawCountry[g, "UG", -120 degrees]
g.drawCountry[g, "JP", -238 degrees]

// Use the bounding box of the graphic to dynamically draw latitude lines
// for only the countries that were actually drawn above.
[west, north, east, south] = getBoundingBox[g]

// Draw primary lines within the mapped area
latStep = 10 degrees
southest = floor[south, latStep]
northest = ceil[north, latStep]
for lat = northest to southest + 1/2 latStep step latStep
   g.line[west, lat, east, lat]
   g.text[format[-lat, degrees, 0], east, lat, "left", "center"]
   g.text[format[-lat, degrees, 0], west, lat, "right", "center"]

// Draw secondary lines that enclose the mapped area
latStep = 1 degree
southest = ceil[south, latStep]
northest = floor[north, latStep]
for lat = northest to southest + 1/2 latStep step latStep
   g.line[west, lat, east, lat][]
g.write["latitudeComparison.png", 1024, 600]

View or download latitudeComparison.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 17747 days, 9 hours, 47 minutes ago.