Skip to content

Instantly share code, notes, and snippets.

@schwehr
Created October 4, 2019 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schwehr/3d72e09263e2341167b12f619ca5d4b2 to your computer and use it in GitHub Desktop.
Save schwehr/3d72e09263e2341167b12f619ca5d4b2 to your computer and use it in GitHub Desktop.
ee.Color notes for Earth Engine
// Copyright 2019 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Author: Kurt Schwehr
// ee.Color
// See also:
// https://github.com/gee-community/ee-palettes
// https://code.earthengine.google.com/?accept_repo=users/gena/packages
// https://earthengine.googlesource.com/users/gena/packages/
// https://earthengine.googlesource.com/users/gena/packages/+/refs/heads/master/palettes
// https://mobile.twitter.com/leafwax/status/1167356045251006465
// - http://colorbrewer2.org
// - http://soliton.vm.bytemark.co.uk/pub/cpt-city/
// - https://coolors.co
// - http://hclwizard.org/
// https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html
//
// "W3C compatible color string or a list of RGBA values in the range of [0:1]"
// https://www.w3.org/wiki/CSS/Properties/color/keywords
var colorTable = {
'#000000': 'black', // 0,0,0
'#C0C0C0': 'silver', // 192,192,192
'#808080': 'gray', // 128,128,128
'#FFFFFF': 'white', // 255,255,255
'#800000': 'maroon', // 128,0,0
'#FF0000': 'red', // 255,0,0
'#800080': 'purple', // 128,0,128
'#FF00FF': 'fuchsia', // 255,0,255
'#008000': 'green', // 0,128,0
'#00FF00': 'lime', // 0,255,0
'#808000': 'olive', // 128,128,0
'#FFFF00': 'yellow', // 255,255,0
'#000080': 'navy', // 0,0,128
'#0000FF': 'blue', // 0,0,255
'#008080': 'teal', // 0,128,128
'#00FFFF': 'aqua', // 0,255,255
'#f0f8ff': 'aliceblue', // 240,248,255
'#faebd7': 'antiquewhite', // 250,235,215
// '#00ffff': 'aqua', // 0,255,255
'#7fffd4': 'aquamarine', // 127,255,212
'#f0ffff': 'azure', // 240,255,255
'#f5f5dc': 'beige', // 245,245,220
'#ffe4c4': 'bisque', // 255,228,196
'#ffebcd': 'blanchedalmond', // 255,235,205
'#0000ff': 'blue', // 0,0,255
'#8a2be2': 'blueviolet', // 138,43,226
'#a52a2a': 'brown', // 165,42,42
'#deb887': 'burlywood', // 222,184,135
'#5f9ea0': 'cadetblue', // 95,158,160
'#7fff00': 'chartreuse', // 127,255,0
'#d2691e': 'chocolate', // 210,105,30
'#ff7f50': 'coral', // 255,127,80
'#6495ed': 'cornflowerblue', // 100,149,237
'#fff8dc': 'cornsilk', // 255,248,220
'#dc143c': 'crimson', // 220,20,60
'#00ffff': 'cyan', // 0,255,255
'#00008b': 'darkblue', // 0,0,139
'#008b8b': 'darkcyan', // 0,139,139
'#b8860b': 'darkgoldenrod', // 184,134,11
'#a9a9a9': 'darkgray', // 169,169,169
'#006400': 'darkgreen', // 0,100,0
// '#a9a9a9': 'darkgrey', // 169,169,169
'#bdb76b': 'darkkhaki', // 189,183,107
'#8b008b': 'darkmagenta', // 139,0,139
'#556b2f': 'darkolivegreen', // 85,107,47
'#ff8c00': 'darkorange', // 255,140,0
'#9932cc': 'darkorchid', // 153,50,204
'#8b0000': 'darkred', // 139,0,0
'#e9967a': 'darksalmon', // 233,150,122
'#8fbc8f': 'darkseagreen', // 143,188,143
'#483d8b': 'darkslateblue', // 72,61,139
'#2f4f4f': 'darkslategray', // 47,79,79
// '#2f4f4f': 'darkslategrey', // 47,79,79
'#00ced1': 'darkturquoise', // 0,206,209
'#9400d3': 'darkviolet', // 148,0,211
'#ff1493': 'deeppink', // 255,20,147
'#00bfff': 'deepskyblue', // 0,191,255
'#696969': 'dimgray', // 105,105,105
// '#696969': 'dimgrey', // 105,105,105
'#1e90ff': 'dodgerblue', // 30,144,255
'#b22222': 'firebrick', // 178,34,34
'#fffaf0': 'floralwhite', // 255,250,240
'#228b22': 'forestgreen', // 34,139,34
'#ff00ff': 'fuchsia', // 255,0,255
'#dcdcdc': 'gainsboro', // 220,220,220
'#f8f8ff': 'ghostwhite', // 248,248,255
'#ffd700': 'gold', // 255,215,0
'#daa520': 'goldenrod', // 218,165,32
// '#808080': 'gray', // 128,128,128
// '#008000': 'green', // 0,128,0
'#adff2f': 'greenyellow', // 173,255,47
// '#808080': 'grey', // 128,128,128
'#f0fff0': 'honeydew', // 240,255,240
'#ff69b4': 'hotpink', // 255,105,180
'#cd5c5c': 'indianred', // 205,92,92
'#4b0082': 'indigo', // 75,0,130
'#fffff0': 'ivory', // 255,255,240
'#f0e68c': 'khaki', // 240,230,140
'#e6e6fa': 'lavender', // 230,230,250
'#fff0f5': 'lavenderblush', // 255,240,245
'#7cfc00': 'lawngreen', // 124,252,0
'#fffacd': 'lemonchiffon', // 255,250,205
'#add8e6': 'lightblue', // 173,216,230
'#f08080': 'lightcoral', // 240,128,128
'#e0ffff': 'lightcyan', // 224,255,255
'#fafad2': 'lightgoldenrodyellow', // 250,250,210
'#d3d3d3': 'lightgray', // 211,211,211
'#90ee90': 'lightgreen', // 144,238,144
// '#d3d3d3': 'lightgrey', // 211,211,211
'#ffb6c1': 'lightpink', // 255,182,193
'#ffa07a': 'lightsalmon', // 255,160,122
'#20b2aa': 'lightseagreen', // 32,178,170
'#87cefa': 'lightskyblue', // 135,206,250
'#778899': 'lightslategray', // 119,136,153
// '#778899': 'lightslategrey', // 119,136,153
'#b0c4de': 'lightsteelblue', // 176,196,222
'#ffffe0': 'lightyellow', // 255,255,224
'#00ff00': 'lime', // 0,255,0
'#32cd32': 'limegreen', // 50,205,50
'#faf0e6': 'linen', // 250,240,230
// '#ff00ff': 'magenta', // 255,0,255
// '#800000': 'maroon', // 128,0,0
'#66cdaa': 'mediumaquamarine', // 102,205,170
'#0000cd': 'mediumblue', // 0,0,205
'#ba55d3': 'mediumorchid', // 186,85,211
'#9370db': 'mediumpurple', // 147,112,219
'#3cb371': 'mediumseagreen', // 60,179,113
'#7b68ee': 'mediumslateblue', // 123,104,238
'#00fa9a': 'mediumspringgreen', // 0,250,154
'#48d1cc': 'mediumturquoise', // 72,209,204
'#c71585': 'mediumvioletred', // 199,21,133
'#191970': 'midnightblue', // 25,25,112
'#f5fffa': 'mintcream', // 245,255,250
'#ffe4e1': 'mistyrose', // 255,228,225
'#ffe4b5': 'moccasin', // 255,228,181
'#ffdead': 'navajowhite', // 255,222,173
// '#000080': 'navy', // 0,0,128
'#fdf5e6': 'oldlace', // 253,245,230
// '#808000': 'olive', // 128,128,0
'#6b8e23': 'olivedrab', // 107,142,35
'#ffa500': 'orange', // 255,165,0
'#ff4500': 'orangered', // 255,69,0
'#da70d6': 'orchid', // 218,112,214
'#eee8aa': 'palegoldenrod', // 238,232,170
'#98fb98': 'palegreen', // 152,251,152
'#afeeee': 'paleturquoise', // 175,238,238
'#db7093': 'palevioletred', // 219,112,147
'#ffefd5': 'papayawhip', // 255,239,213
'#ffdab9': 'peachpuff', // 255,218,185
'#cd853f': 'peru', // 205,133,63
'#ffc0cb': 'pink', // 255,192,203
'#dda0dd': 'plum', // 221,160,221
'#b0e0e6': 'powderblue', // 176,224,230
'#ff0000': 'red', // 255,0,0
'#bc8f8f': 'rosybrown', // 188,143,143
'#4169e1': 'royalblue', // 65,105,225
'#8b4513': 'saddlebrown', // 139,69,19
'#fa8072': 'salmon', // 250,128,114
'#f4a460': 'sandybrown', // 244,164,96
'#2e8b57': 'seagreen', // 46,139,87
'#fff5ee': 'seashell', // 255,245,238
'#a0522d': 'sienna', // 160,82,45
'#c0c0c0': 'silver', // 192,192,192
'#87ceeb': 'skyblue', // 135,206,235
'#6a5acd': 'slateblue', // 106,90,205
'#708090': 'slategray', // 112,128,144
// '#708090': 'slategrey', // 112,128,144
'#fffafa': 'snow', // 255,250,250
'#00ff7f': 'springgreen', // 0,255,127
'#4682b4': 'steelblue', // 70,130,180
'#d2b48c': 'tan', // 210,180,140
// '#008080': 'teal', // 0,128,128
'#d8bfd8': 'thistle', // 216,191,216
'#ff6347': 'tomato', // 255,99,71
'#40e0d0': 'turquoise', // 64,224,208
'#ee82ee': 'violet', // 238,130,238
'#f5deb3': 'wheat', // 245,222,179
'#ffffff': 'white', // 255,255,255
'#f5f5f5': 'whitesmoke', // 245,245,245
'#ffff00': 'yellow', // 255,255,0
'#9acd32': 'yellowgreen', // 154,205,50
};
// var toColorName = func()
var clr = ee.Color(null);
// print(clr); // Color (Error) Parameter 'input' is required
// Color (Error)
// Color: The type of input must be a list of Number, found type String at position 0
// print(ee.Color(['a', 0, 0])); // FF0000FF
var zero = ee.Number(0.0);
var one = ee.Number(1.0);
var neg_one = ee.Number(-1.0);
var nan = ee.Number.parse('NaN');
var inf = ee.Number.parse('Infinity');
var neg_inf = ee.Number.parse('-Infinity');
// print(ee.Color([one, 0, 0])); // FF0000FF
// print(ee.Color([neg_one, 0, 0])); // 000000FF
// print(ee.Color([nan, 0, 0])); // 000000FF
// print(ee.Color([inf, 0, 0])); // #FF0000FF
// print(ee.Color([neg_inf, 0, 0])); // #000000FF
// print(ee.Color([zero, 0, 0])); // #000000FF
// print(ee.Color([-1, 0, 0])); // #000000FF
// print(ee.Color([-0.2, 0, 0])); // 000000FF
// print(ee.Color([-1, -1, -1, -1])); // WAT? #00000000
var white = ee.Color('white'); // print(white); // #FFFFFFFF
var black = ee.Color('black'); // print(black); // #000000FF
var red = ee.Color('red'); // print(red); // #FF0000FF
var green = ee.Color('green'); // print(green); // #008000FF Really?
var lime = ee.Color('lime'); // print(lime); // #00FF00FF
var blue = ee.Color('blue'); // print(blue); // #0000FFFF
if(0){
var transparentWhite = ee.Color([1.0, 1.0, 1.0, 0.0]);
print(transparentWhite); // #FFFFFF00
// Full green. a.k.a. "Lime"
var lime = ee.Color('#00FF00'); print(lime); // #00FF00FF
// https://en.wikipedia.org/wiki/HSL_and_HSV
var clr = ee.Color.fromHsl([1.0, 1.0, 1.0]); print(clr); // #FFFFFFFF
var clr = ee.Color.fromHsl([0.0, 1.0, 1.0]); print(clr); // #FFFFFFFF
var clr = ee.Color.fromHsl([0.5, 0.5, 0.5]); print(clr); // #40BFBFFF
var clr = ee.Color.fromHsl([1.0, 1.0, 0.5]); print(clr); // #FF0000FF
var clr = ee.Color.fromHsl([0.6666667, 1.0, 0.5, 0.5]); print(clr); // #0000FF80
print(white.toHsl()); // [0,0,1,1]
print(black.toHsl()); // [0,0,0,1]
print(red.toHsl()); // [0,1,0.5,1]
print(green.toHsl()); // [0.3333333333333333,1,0.25098039215686274,1]
print(blue.toHsl()); // [0.6666666666666666,1,0.5,1]
print(lime.toHsl()); // [0.3333333333333333,1,0.5,1]
print(ee.Color.fromHsv([0,0,1,1])); // #FFFFFFFF
print(ee.Color.fromHsv([0,0,1,0.5])); // #FFFFFF80
print(ee.Color.fromHsv([0,0,0,1])); // 000000FF
print(ee.Color.fromHsv([0,1,1,1])); // #FF0000FF
print(ee.Color.fromHsv([0.3333333333333333,1,0.5019607843137255,1])); // #008000FF
print(ee.Color.fromHsv([0.6666666666666666,1,1,1])); // #0000FFFF
print(ee.Color.fromHsv([0.3333333333333333,1,1,1])); // #00FF00FF
print(white.toHsv()); // [0,0,1,1]
print(black.toHsv()); // [0,0,0,1]
print(red.toHsv()); // [0,1,1,1]
print(green.toHsv()); // [0.3333333333333333,1,0.5019607843137255,1]
print(blue.toHsv()); // [0.6666666666666666,1,1,1]
print(lime.toHsv()); // [0.3333333333333333,1,1,1]
}
// ee.Color.fromLab(lab)
// ee.Color.fromLch(lch)
// ee.Color.gray(value, alpha)
// brighter(scale)
// darker(scale)
// mix(end, ratio, colorspace)
// toHexString()
// toHsv()
// toLab()
// toLch()
// toRGB()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment