Mike Fitz
Mike Fitz

Reputation: 101

Converting 3 RGB ints to one 0-1 double

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?

Upvotes: 1

Views: 833

Answers (1)

alirabiee
alirabiee

Reputation: 1306

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.

Upvotes: 2

Related Questions