Skip to content

Instantly share code, notes, and snippets.

@wemakeweb
Created September 8, 2013 21:25
Show Gist options
  • Save wemakeweb/6488534 to your computer and use it in GitHub Desktop.
Save wemakeweb/6488534 to your computer and use it in GitHub Desktop.
Color codes temperature
function temp( temperature, element ){
var norm = function(x){ return x - 10; },
cold = function(x){
return 'rgba(0, 131, 253,'+ Math.abs(norm(x) / 25) + ')';
},
warm = function(x){
return 'rgba(253,'+ Math.floor((200 - x*3)) +',0,'+ norm(x)/15 + ')';
};
if( temperature >= 10 ){
element.style.backgroundColor = warm(temperature);
} else {
element.style.backgroundColor = cold(temperature);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment