Color scaling function

后端 未结 8 1500
北荒
北荒 2020-12-08 11:40

I am trying to visualize some values on a form. They range from 0 to 200 and I would like the ones around 0 be green and turn bright red as they go to 200.

Basicall

8条回答
  •  -上瘾入骨i
    2020-12-08 12:04

    If you use linear ramps for Red and Green values as Peter Parker suggested, the color for value 100 will basically be puke green (127, 127, 0). You ideally want it to be a bright orange or yellow at that midpoint. For that, you can use:

    Red = max(value / 100, 1) * 255
    Green = (1 - max(value / 100, 1)) * 255
    Blue = 0
    

提交回复
热议问题