Sign in to follow this  
JakeM

Rainbow gradient

Recommended Posts

mike25025    494
Here is some code that will find the hue on a color wheel. Values are in degrees.
	def getHue(self,hue):
h = hue/60.0
i = int(math.floor(h))
f = (h-i)*255
q = 255-f

if i is 0:
r=255;g=f;b=0
elif i is 1:
r=q;g=255;b=0
elif i is 2:
r=0;g=255;b=f
elif i is 3:
r=0;g=q;b=255
elif i is 4:
r=f;g=0;b=255
elif i is 5:
r=255;g=0;b=q

return [r,g,b]


The language is Python but it should be easy to rewrite it in a different language.

To get the colors for a rainbow loop through the hues.

Share this post


Link to post
Share on other sites
timw    598
you wanna make sure it starts and ends at the right color. real rainbows always start and end at the same colors, I just can't remember which ones.

Share this post


Link to post
Share on other sites
PixelPhil    218
real rainbows cycle colors this way :

ultraviolet (not visible), blue, indigo, purple, green, yellow, orange, red, infrared (not visible)

it really doesn't cycle like the hue wheel.

Phil.

Share this post


Link to post
Share on other sites
Troll    246
An easy (and accurate) way to do a rainbow would be to do a walk across the visible light spectrum, i.e. just step a variable from 700 to 400 and then map that number into RGB values using standard cone response curves.

Share this post


Link to post
Share on other sites
Eelco    301
Quote:
Original post by PixelPhil
real rainbows cycle colors this way :

ultraviolet (not visible), blue, indigo, purple, green, yellow, orange, red, infrared (not visible)

it really doesn't cycle like the hue wheel.

Phil.


purple between indigo and green? not with my eyes, but your mileage may vary.

Share this post


Link to post
Share on other sites
Kalidor    1087
Quote:
Original post by Eelco
Quote:
Original post by PixelPhil
ultraviolet (not visible), blue, indigo, purple, green, yellow, orange, red, infrared (not visible)
purple between indigo and green? not with my eyes, but your mileage may vary.
Yeah, purple (violet) and blue should be switched. Roy G. Biv to the rescue! [grin]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this