For geolocation IP address maps we needed to convert (lon, lat) to color in HSL and RGB color schemes.
We proivde implementations of our model in:
These scripts provide functions that convert world coordinates (longtitude, latitude) into HSL color space, and then to RGB values. If we used this function on all coordinates in the world, we’d end up with this rainbow map of the world.
Our formula is:
given (lon, lat):
# measured in degrees, positive is north and east
compute (hue, saturation, luminance) as:
# hue in degrees, saturation constant at 1, luminance range (0, 1)
hue = lon_in_degrees
saturation = 1
# not much south of 80 degrees, and invert it so north is negative
inverted_cappped_lat = -MAX(-80, lat)
# scale over a range that makes the land look distinct
LATL = -115
LATH = 80
luminance = (inverted_capped_lat - LATL) / (LATH-LATL)