Rainbow gradient

Started by
7 comments, last by Kalidor 18 years, 6 months ago
How would you create a rainbow gradient, like in Photoshop, that goes from red to blue?
Advertisement
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.
Actually, I found something even better, with source code:

http://www.codeproject.com/miscctrl/gradient.asp

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. :(
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.
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.
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.
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.
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.
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]

This topic is closed to new replies.

Advertisement