Color scaling function

后端 未结 8 1497
北荒
北荒 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:13
    red = (float)val / 200 * 255;
    
    green = (float)(200 - val) / 200 * 255;
    
    blue = 0;
    
    return red << 16 + green << 8 + blue;
    
    0 讨论(0)
  • 2020-12-08 12:13

    extending upon @tzot's code... you can also set up a mid-point in between the start and end points, which can be useful if you want a "transition color"!

    //comment: s = start_triplet, m = mid_triplet, e = end_triplet
    function transition3midpoint = (value, maximum, s, m, e):
        mid = maximum / 2
        if value < mid
          return transition3(value, mid, s, m)
        else
          return transition3(value - mid, mid, m, e)
    
    0 讨论(0)
提交回复
热议问题