Algorithm to convert any positive integer to an RGB value

后端 未结 10 1315
没有蜡笔的小新
没有蜡笔的小新 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:28

    A little late, but I was trying to do the same and found I can modify HSV to RGB to get a similar result. It's similar to the wavelength approach but by passes the need to convert to wavelength first. Just substitute H with your value (assuming a value between 0 and 1), and fix S and V to 1. I found the HSVtoRGB example here to be very helpful:

    http://www.cs.rit.edu/~ncs/color/t_convert.html

    However, I had to change the lines

    h /= 60;
    i = floor ( h );
    

    to

    h *= 5;
    i = (int) h;
    

    to get an output that goes through the whole spectrum.

    Additional resource: http://www.easyrgb.com/index.php?X=MATH&H=21#text21

提交回复
热议问题