• Advertisement
Sign in to follow this  

Rainbow gradient

This topic is 4522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would you create a rainbow gradient, like in Photoshop, that goes from red to blue?

Share this post


Link to post
Share on other sites
Advertisement
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
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
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
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
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
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
Sign in to follow this  

  • Advertisement