I am generating heatmap style colours in JavaScript based on the values from cold to hot. But for some reason I am getting some pinks and some purples.
There are lots of answers on stackoverflow but they mostly relate to generating using HSL, and unfortunately for Google Earth I need RGBA format (backwards as ABGR)
1 = red = hot
0.5 = green = middle
0 = blue = cold
function generateColor(value) {
var r = Math.round(value * 255),
g = Math.round((1 - Math.abs(0.5 - value)) * 255),
b = Math.round((1 - value) * 255);
r = r.toString(16);
g = g.toString(16);
b = b.toString(16);
if (r.length < 2) {
r += r;
}
if (g.length < 2) {
g += g;
}
if (b.length < 2) {
b += b;
}
return 'ff' + b + g + r;
}
There's a bug in here somewhere!! Here's a fiddle I've been using to try and work out the problem: