/** 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. This demonstrates the Equal Earth projection: https://en.wikipedia.org/wiki/Equal_Earth_projection https://www.equal-earth.com/equal-earth-projection.html Original paper: https://sci-hub.se/https://doi.org/10.1080/13658816.2018.1504949 */ use Country.frink g = new graphics g.stroke[0.001] g.font["SansSerif", "bold", 1 degree] // Iterate through all countries. for [code, country] = Country.getCountryList[] { cc = new color[randomFloat[0,1], randomFloat[0,1], randomFloat[0,1], .8] first = true 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 { [x,y] = latLongToXYEqualEarth[lat degree, long degree, 0 degree] p.addPoint[x, -y] po.addPoint[x, -y] } // Draw filled countries g.color[cc] g.add[p] // The polygons in Country.frink are sorted so the first polygon is the // largest. Just label the largest. if first { [cx, cy] = p.getCentroid[] g.color[0,0,0] g.text[code, cx, cy] } // Draw country outlines g.color[0.2, 0.2, 0.2, 0.8] g.add[po] first = false } } g.invertGrays[].show[] g.write["EqualEarth.svg", 2048, undef] g.write["EqualEarth.png", 2048, undef] g.write["EqualEarth.html", 1000, 500] /** Convert a latitude, longitude, and optional center longitude (long0) into x,y coordinates. returns [x ,y] */ latLongToXYEqualEarth[lat, long, long0 = 0 degrees] := { // The EqualEarth projection uses an "auxiliary angle" theta where theta is // given by // sin[theta] = sqrt[3]/2 sin[lat] // or, solving for theta: // theta = arcsin[1/2 3^(1/2) sin[lat]] theta = arcsin[1/2 3^(1/2) sin[lat]] A1 = 1.340264 A2 = -0.081106 A3 = 0.000893 A4 = 0.003796 long1 = (long - long0) x = (2 sqrt[3] long1 cos[theta]) / ( 3 (9 A4 theta^8 + 7 A3 theta^6 + 3 A2 theta^2 + A1)) y = A4 theta^9 + A3 theta^7 + A2 theta^3 + A1 theta return [x,y] }