Color scaling function

后端 未结 8 1506
北荒
北荒 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条回答
  •  天命终不由人
    2020-12-08 12:04

    Pick a green that you like (RGB1 = #00FF00, e.g.) and a Red that you like (RGB2 = #FF0000, e.g.) and then calculate the color like this

    R = R1 * (200-i)/200 + R2 * i/200
    G = G1 * (200-i)/200 + G2 * i/200
    B = B1 * (200-i)/200 + B2 * i/200
    

提交回复
热议问题