drawCountries.frink

Download or view drawCountries.frink in plain text format


/** This program demonstrates the use of the country polygons in
    Country.frink to draw a map of the world.  It can be readily altered to
    draw the map in your favorite projection. */


use Country.frink
use geometry.frink

g = new graphics
g.stroke[0.001]
g.font["SansSerif", "bold", 0.5 degree]

// Comment this in to clip to just a part of the world.
//g.clipRectSides[-100 degrees, -40 degrees, -30 degrees, -10 degrees]

// Iterate through all countries.
for [code, country] = Country.getCountryList[]
{
   cc = new color[randomFloat[0,1], randomFloat[0,1], randomFloat[0,1], .8]
   for poly = country.borders  // Iterate through polygons in a country.
   {
      p = new filledPolygon   // This polygon is the filled country
      po = new polygon        // This is the outline of the country
      for [long, lat] = poly  // Iterate through points in polygon
      {
         p.addPoint[long degree, -lat degree]
         po.addPoint[long degree, -lat degree]

         // Comment out the two lines above and use the 2 lines below for
         // a sinusoidal projection.  Also change the line at bottom that
         // writes the country code.
         //    p.addPoint[long degree cos[lat degree], -lat degree]
         //    po.addPoint[long degree cos[lat degree], -lat degree]
      }

      // Comment this in to draw bounding boxes, which is kinda interesting.
      //[left,top,bottom,right] = getBoundingBox[p]
      //g.drawRectSides[left,top,bottom,right]

      // Draw filled countries
      g.color[cc]
      g.add[p]

      // Draw country outlines
      g.color[0.2,0.2,0.2,.8]
      g.add[po]

      // Draw country names.
      [clong, clat] = polygonCentroid[poly]
      g.color[0,0,0]
      g.text[code, clong degree, -clat degree]

      // Use the following line for sinusoidal projection and comment out the
      // line above.
      //   g.text[code, clong degree cos[clat degree], -clat degree]
   }
}

g.show[]
//g.write["world.svg", 1000, 500]


Download or view drawCountries.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 19970 days, 8 hours, 27 minutes ago.