You can express color using two dimensions:
var max_temp = 50, // set maximum expected temperature min_temp = -10, // set minimum temperature temp_range = max_temp - min_temp, // calculate range temp_rating = ((temp - min_temp) / temp_range) * 255 // express value in terms of the range multiplied by 255 red = temp_rating, // more temp = more red blue = 255 - temp_rating; // more temp = less blue
Then your CSS color will be as follows:
rgb(red, 0, blue)
I donβt know if this will please, though :-)
source share