Skip to content

Instantly share code, notes, and snippets.

@cezarsmpio
Created December 16, 2016 03:03
Show Gist options
  • Save cezarsmpio/18fc7b3caefcb2dbceaa4f756d85f999 to your computer and use it in GitHub Desktop.
Save cezarsmpio/18fc7b3caefcb2dbceaa4f756d85f999 to your computer and use it in GitHub Desktop.
Color temperature
import colr from 'colr';
let colorTemperature = function(t)
{
// Map the temperature to a 0-1 range
var a = (t + 30)/60;
a = (a < 0) ? 0 : ((a > 1) ? 1 : a);
// Scrunch the green/cyan range in the middle
var sign = (a < .5) ? -1 : 1;
a = sign * Math.pow(2 * Math.abs(a - .5), .35)/2 + .5;
// Linear interpolation between the cold and hot
var h0 = 259;
var h1 = 12;
var h = (h0) * (1 - a) + (h1) * (a);
return colr.fromHsv(h, 75, 90).toHex();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment