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

## Recommended Posts

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

##### Share on other sites
I will refer you to this thread, which has some great techniques presented. Of course you will need to mmodify it to whatever language you are using, but the ideas are the same.

##### Share on other sites
Actually, I found something even better, with source code:

I can use the color wheel to get a rainbow effect I suppose.

A straight line in 3D color space from red to blue is not very colorful. :(

##### Share on other sites
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 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 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 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 on other sites
Quote:
 Original post by PixelPhilreal 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 on other sites
Quote:
Original post by Eelco
Quote:
 Original post by PixelPhilultraviolet (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]

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011828
• ### Who's Online (See full list)

There are no registered users currently online

×