heatmap colors
by paulftw
HTML
<div id=out>
</div>
JavaScript
var findcolor = function(x) {
var shft = 5.7 - 4.5 * x;
x = shft + 2 * Math.PI * x;
x = -x;
var scale = 128;
var r = Math.floor((Math.cos(x) + 1) * scale);
var g = Math.floor((Math.cos(x+Math.PI/2) + 1) * scale);
var b = Math.floor((Math.cos(x+Math.PI) + 1) * scale);
return 'rgb(' + r + ',' + g + ',' + b + ')';
};
var colo = function(x) {
console.log('<div>' + x + '</div>', 'backgroundColor', findcolor(x));
$('<div>' + x + '</div>').appendTo('#out').css('backgroundColor', findcolor(x));
};
var N = 4;
for (var i=1;i<=N;i++) {
colo(i/N - 1/N/2);
}