Created
December 16, 2016 03:03
-
-
Save cezarsmpio/18fc7b3caefcb2dbceaa4f756d85f999 to your computer and use it in GitHub Desktop.
Color temperature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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