Interactive interface for browsing global, full-resolution satellite imagery
Comparison of HSL/RGB gradients
Mike McGann1dabe715e400
diff --git a/css/palette.css b/css/palette.cssindex 032b10b0f..48d3d6cec 100644--- a/css/palette.css+++ b/css/palette.css@@ -1,5 +1,5 @@.palette {width: 100px;height: 14px;- border: 1px solid #aaaaaa;+ border: 3px solid #aaaaaa;}diff --git a/dev/palette/dev.js b/dev/palette/dev.jsindex bc0946fa3..803cada98 100644--- a/dev/palette/dev.js+++ b/dev/palette/dev.js@@ -15,6 +15,23 @@ $(function() {]};+ r2g_rgb = {+ method: "rgb",+ stops: [+ { at: 0.0, r: 0xff, g: 0x00, b: 0x00 },+ { at: 1.0, r: 0x00, g: 0xff, b: 0x00 }+ ]+ };++ r2g_hsl = {+ method: "hsl",+ stops: [+ { at: 0.0, r: 0xff, g: 0x00, b: 0x00 },+ { at: 1.0, r: 0x00, g: 0xff, b: 0x00 }+ ]+ };++g2r = {stops: [{ at: 0.0, r: 0x00, g: 0xff, b: 0x00 },@@ -81,6 +98,51 @@ $(function() {bins: 100,palette: r2g});++ /** Red to Green, RGB */+ new ColorBar({+ selector: "#r2g-rgb-2",+ bins: 2,+ palette: r2g_rgb+ });+ new ColorBar({+ selector: "#r2g-rgb-3",+ bins: 3,+ palette: r2g_rgb+ });+ new ColorBar({+ selector: "#r2g-rgb-10",+ bins: 10,+ palette: r2g_rgb+ });+ new ColorBar({+ selector: "#r2g-rgb-100",+ bins: 100,+ palette: r2g_rgb+ });++ /** Red to Green, HSL */+ new ColorBar({+ selector: "#r2g-hsl-2",+ bins: 2,+ palette: r2g_hsl+ });+ new ColorBar({+ selector: "#r2g-hsl-3",+ bins: 3,+ palette: r2g_hsl+ });+ new ColorBar({+ selector: "#r2g-hsl-10",+ bins: 10,+ palette: r2g_hsl+ });+ new ColorBar({+ selector: "#r2g-hsl-100",+ bins: 100,+ palette: r2g_hsl+ });+/** Green to Red */new ColorBar({diff --git a/dev/palette/index.html b/dev/palette/index.htmlindex 46ee8e832..c00af466a 100644--- a/dev/palette/index.html+++ b/dev/palette/index.html@@ -84,6 +84,76 @@</td></tr>+ <tr>+ <td>+ <div class="layer">+ <span class="name">Red to Green, RGB: 2 Bins</span>+ <div>+ <canvas class="palette" id="r2g-rgb-2"></canavs>+ </div>+ </div>+ </td>+ <td>+ <div class="layer">+ <span class="name">Red to Green, RGB: 3 Bins</span>+ <div>+ <canvas class="palette" id="r2g-rgb-3"></canavs>+ </div>+ </div>+ </td>+ <td>+ <div class="layer">+ <span class="name">Red to Green, RGB: 10 Bins</span>+ <div>+ <canvas class="palette" id="r2g-rgb-10"></canavs>+ </div>+ </div>+ </td>+ <td>+ <div class="layer">+ <span class="name">Red to Green, RGB: 100 Bins</span>+ <div>+ <canvas class="palette" id="r2g-rgb-100"></canavs>+ </div>+ </div>+ </td>+ </tr>++ <tr>+ <td>+ <div class="layer">+ <span class="name">Red to Green, HSL: 2 Bins</span>+ <div>+ <canvas class="palette" id="r2g-hsl-2"></canavs>+ </div>+ </div>+ </td>+ <td>+ <div class="layer">+ <span class="name">Red to Green, HSL: 3 Bins</span>+ <div>+ <canvas class="palette" id="r2g-hsl-3"></canavs>+ </div>+ </div>+ </td>+ <td>+ <div class="layer">+ <span class="name">Red to Green, HSL: 10 Bins</span>+ <div>+ <canvas class="palette" id="r2g-hsl-10"></canavs>+ </div>+ </div>+ </td>+ <td>+ <div class="layer">+ <span class="name">Red to Green, HSL: 100 Bins</span>+ <div>+ <canvas class="palette" id="r2g-hsl-100"></canavs>+ </div>+ </div>+ </td>+ </tr>+<tr><td><div class="layer">diff --git a/js/palette.js b/js/palette.jsindex f9eb2f4b8..b5df6397a 100644--- a/js/palette.js+++ b/js/palette.js@@ -49,33 +49,49 @@ $(function() {var segmentLength = end.at - begin.at;var segmentDistance = (segmentLength !== 0) ?(distance - begin.at) / segmentLength : 0;-- var hsvEnd = util.rgbToHsv(end.r, end.g, end.b);- var hsvBegin = util.rgbToHsv(begin.r, begin.g, begin.b);-- var h = hsvBegin.h + (segmentDistance * (hsvEnd.h - hsvBegin.h));- var s = hsvBegin.s + (segmentDistance * (hsvEnd.s - hsvBegin.s));- var v = hsvBegin.v + (segmentDistance * (hsvEnd.v - hsvBegin.v));-- var rgb = util.hsvToRgb(h, s, v);-- lut.push(rgb);-- /*- lut.push({- r: Math.floor(begin.r + (segmentDistance * (end.r - begin.r))),- g: Math.floor(begin.g + (segmentDistance * (end.g - begin.g))),- b: Math.floor(begin.b + (segmentDistance * (end.b - begin.b))),- });- */++ if ( palette.method === "rgb" ) {+ lut.push(ns.rgbInterpolate(segmentDistance, begin, end));+ } else if ( palette.method == "hsl" ) {+ lut.push(ns.hslInterpolate(segmentDistance, begin, end));+ } else {+ lut.push(ns.hsvInterpolate(segmentDistance, begin, end));+ }}return lut;}- var init = function() {- drawCheckerboard();++ ns.rgbInterpolate = function(percent, begin, end) {+ return {+ r: Math.round(begin.r + (percent * (end.r - begin.r))),+ g: Math.round(begin.g + (percent * (end.g - begin.g))),+ b: Math.round(begin.b + (percent * (end.b - begin.b))),+ }}+ ns.hsvInterpolate = function(percent, rgbBegin, rgbEnd) {+ var hsvBegin = util.rgb2hsv(rgbBegin.r, rgbBegin.g, rgbBegin.b);+ var hsvEnd = util.rgb2hsv(rgbEnd.r, rgbEnd.g, rgbEnd.b);++ var h = hsvBegin.h + (percent * (hsvEnd.h - hsvBegin.h));+ var s = hsvBegin.s + (percent * (hsvEnd.s - hsvBegin.s));+ var v = hsvBegin.v + (percent * (hsvEnd.v - hsvBegin.v));++ return util.hsv2rgb(h, s, v);+ }++ ns.hslInterpolate = function(percent, rgbBegin, rgbEnd) {+ var hslBegin = util.rgb2hsl(rgbBegin.r, rgbBegin.g, rgbBegin.b);+ var hslEnd = util.rgb2hsl(rgbEnd.r, rgbEnd.g, rgbEnd.b);++ var h = hslBegin.h + (percent * (hslEnd.h - hslBegin.h));+ var s = hslBegin.s + (percent * (hslEnd.s - hslBegin.s));+ var l = hslBegin.l + (percent * (hslEnd.l - hslBegin.l));++ return util.hsl2rgb(h, s, l);+ }+var drawCheckerboard = function() {var size = 7;@@ -96,6 +112,10 @@ $(function() {ns.CHECKERBOARD = g.createPattern(canvas, "repeat");}+ var init = function() {+ drawCheckerboard();+ }+init();});diff --git a/js/util.js b/js/util.jsindex 6d4954405..5342f1e78 100644--- a/js/util.js+++ b/js/util.js@@ -200,7 +200,7 @@ SOTE.util.clampIndex = function(array, index) {}/**- * Function: rgbToHsv+ * Function: rgb2hsv** Converts an RGB color value to HSV. Conversion formula* adapted from http://en.wikipedia.org/wiki/HSV_color_space.@@ -225,7 +225,7 @@ SOTE.util.clampIndex = function(array, index) {* Object { h=0.5833333333333334, s=0.6666666666666666, v=0.23529411764705882}* (end code)*/-SOTE.util.rgbToHsv = function(r, g, b){+SOTE.util.rgb2hsv= function(r, g, b){r = r/255, g = g/255, b = b/255;var max = Math.max(r, g, b), min = Math.min(r, g, b);var h, s, v = max;@@ -248,7 +248,7 @@ SOTE.util.rgbToHsv = function(r, g, b){}/**- * Function: hsvToRgb+ * Function: hsv2rgb** Converts an HSV color value to RGB. Conversion formula* adapted from http://en.wikipedia.org/wiki/HSV_color_space.@@ -273,7 +273,7 @@ SOTE.util.rgbToHsv = function(r, g, b){* Object { r=20, g=40, b=60}* (end code)*/-SOTE.util.hsvToRgb = function(h, s, v){+SOTE.util.hsv2rgb = function(h, s, v){var r, g, b;var i = Math.floor(h * 6);@@ -298,6 +298,94 @@ SOTE.util.hsvToRgb = function(h, s, v){};}+/**+ * Function rgb2hsl+ *+ * Converts an RGB color value to HSL. Conversion formula+ * adapted from http://en.wikipedia.org/wiki/HSL_color_space.+ * Assumes r, g, and b are contained in the set [0, 255] and+ * returns h, s, and l in the set [0, 1].+ *+ * See Also:+ * http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript+ *+ * Parameters:+ * r - The red color value+ * g - The green color value+ * b - The blue color value+ *+ * Returns:+ * The HSL representation as an object with h, s, and l properties.+ */+SOTE.util.rgb2hsl = function(r, g, b) {+ r /= 255, g /= 255, b /= 255;+ var max = Math.max(r, g, b), min = Math.min(r, g, b);+ var h, s, l = (max + min) / 2;++ if(max == min){+ h = s = 0; // achromatic+ }else{+ var d = max - min;+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);+ switch(max){+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;+ case g: h = (b - r) / d + 2; break;+ case b: h = (r - g) / d + 4; break;+ }+ h /= 6;+ }++ return {h: h, s: s, l: l};+}++/**+ * Function: hsl2rgb+ *+ * Converts an HSL color value to RGB. Conversion formula+ * adapted from http://en.wikipedia.org/wiki/HSL_color_space.+ * Assumes h, s, and l are contained in the set [0, 1] and+ * returns r, g, and b in the set [0, 255].+ *+ * See Also:+ * http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript+ *+ * Parameters:+ * h - The hue+ * s - The saturation+ * l - The lightness+ *+ * Returns:+ * The RGB representation as an object with r, g, and b properties.+ */+SOTE.util.hsl2rgb = function(h, s, l) {+ var r, g, b;++ if(s == 0){+ r = g = b = l; // achromatic+ }else{+ function hue2rgb(p, q, t){+ if(t < 0) t += 1;+ if(t > 1) t -= 1;+ if(t < 1/6) return p + (q - p) * 6 * t;+ if(t < 1/2) return q;+ if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;+ return p;+ }++ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;+ var p = 2 * l - q;+ r = hue2rgb(p, q, h + 1/3);+ g = hue2rgb(p, q, h);+ b = hue2rgb(p, q, h - 1/3);+ }++ return {+ r: Math.round(r * 255),+ g: Math.round(g * 255),+ b: Math.round(b * 255)+ };+}+/*** Generates an array of OpenLayers layers for the specified product: one for each* day starting from the current day, working backwards for a total of numDays.