Set background color based on outdoor temperature

前端 未结 4 538
-上瘾入骨i
-上瘾入骨i 2021-01-31 20:04

Heyoh SO,

I have a temperature widget to implement on a project I am working on. Nothing is specially difficult, I\'ve got a free API to retrieve the datas that I need e

4条回答
  •  佛祖请我去吃肉
    2021-01-31 20:51

    Your colour range looks to be the same as a "hue-only" sweep in "HSL colour space" from 270º (violetish) at -30ºC down to 30º (orange) at +30ºC

    var hue = 30 + 240 * (30 - t) / 60;
    

    If t is out of range, either clamp it before calling the above expression, or clamp h to the desired hue range afterwards.

    On supported browsers you can use an hsl(h, s, l) colour string, or use commonly available "HSL to RGB" functions to convert the HSL colour into RGB.

    See http://jsfiddle.net/V5HyL/

提交回复
热议问题