1

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?

Mike Fitz
  • 101
  • 1
  • 9
  • 1
    Have you tried to calculate it on paper? Since it would make your life much easier when you recreate what you have written on paper. – n247s Aug 26 '17 at 18:13

1 Answers1

2

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.

alirabiee
  • 1,286
  • 7
  • 14