Algorithm to convert any positive integer to an RGB value

后端 未结 10 1321
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 13:49

We have a heatmap we want to display. The numbers that will make up the values being displayed are unknown (except that they will be positive integers). The range of numbers

10条回答
  •  被撕碎了的回忆
    2020-12-04 14:16

    Going off of the picture provided by Chris H, you can model the rgb values as:

    r = min(max(0, 1.5-abs(1-4*(val-0.5))),1);
    g = min(max(0, 1.5-abs(1-4*(val-0.25))),1);
    b = min(max(0, 1.5-abs(1-4*val)),1);
    

提交回复
热议问题