Reputation:
I am currently coding a colorpicker and trying to create a function that takes 3 integers between 0 and 255 (RGB).
If you look at the image linked above, you can see that there is a rainbow-gradient in the center. All RGB values on there contain at least one integer that is 0 and one that is 255. The other one can be anything between 0 and 255. Then you have a square on the left in the image that contains a gradient of all "sub-colors" of this "rainbow-color".
The function should take the RGB values of this sub-color (for example R = 112, G = 158, B = 73 which is a kind of greenish color) and get me the rainbow-color (R = 116, G = 255, B = 0 notice the 255, 0 and the value in between).
I really tried to develop an algorythm to solve this problem for me but im just getting really rough estimations of the rainbow-color. I know that its not possible to, for example, get the rainbow-color by R = 19, G = 19, B = 18 because there are a lot of rainbow-colors that contain these values. But there should be a way to get this about right.
Upvotes: 0
Views: 1373
Reputation: 80187
That gradient corresponds to color attribute hue
or chroma
value in HSL/HSV color model.
So to build needed picture, you can make gradient bar with hue varying in range 0..360 and max saturation.
When user picks hue value, fill a square with colors using same hue but all possible saturation
and luminance
values.
Linked page also gives formulas for HSL-RGB (and backward) converting. Note that some graphics libraries and frameworks already contain functions for such convertation.
Upvotes: 1