Converting 3 RGB ints to one 0-1 double

Mike Fitz

I'm creating a GUI that has a double slidePos from 0-1 that needs to dictate the color of a setting. The resulting color should always be at full saturation and 50% brightness. I need to convert the number from 0 to 1 into any color(i.e. three ints), where 0 is red, 0.333 is green, and 0.666 is blue. I would also need the reverse operation, taking three integers and turning them into a double from 0-1. How would I go about the math to make this work?

alirabiee

What you are looking for is simply a conversion from HSL to RGB and backwards. Take a look at the answer here. For your case, s=1 and l=0.5.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related