It is necessary that the numbers from 0 to 255 correspond to such a color map 
and the result is three numbers of RGB, for example (0,0,255)
This illustration from Wikipedia will help you ( link )
Your example starts at 240 ° and goes left to 0 °.
You need to divide the entire width into 4 areas.
I think with the casting arithmetic you can handle
A little work on your picture. 
If we consider, it is clear that
struct Color { public Color(int r, int g, int b) { R = r; G = g; B = b;} int R,G,B; } Color getColor(int color) { int red = (color >= 128) ? (color - 128)*2 : 0; int green = (color < 128) ? color*2 : 255 - (color - 128)*2; int blue = (color < 128) ? 255 - 2*color : 0; return new Color(red,green,blue); }
Pass a number from 0 to 255 to the function, we get the color in RGB.
PS Possibly poorly handled boundary values (0, 127 or 128 and 255).
Source: https://ru.stackoverflow.com/questions/507380/
All Articles