[comp.graphics] Colors of the Rainbow

schwarze@isaak.uucp (Jochen Schwarze) (01/03/90)

Hello,

I want to display the color spectrum of a rainbow. The wavelengths
of visible light approximately run from 400 nm to 800 nm. So I'm
looking for a function that maps a wavelength to the appropriate RGB
triple. Has anybody done this? Any pointers appreciated.

Thanks in advance.

Jochen Schwarze                     Domain: schwarze@isaak.isa.de
ISA GmbH, Stuttgart, West Germany   UUCP:   schwarze@isaak.uucp
                                    Bang:   ...!uunet!unido!isaak!schwarze

forsythe@convex.com (Charles Forsythe) (01/04/90)

schwarze@isaak.uucp (Jochen Schwarze) writes:
>I'm looking for a function that maps a wavelength to the appropriate RGB
>triple. Has anybody done this? Any pointers appreciated.

This is actually very easy to do.

R = M * sin(T) + N
G = M * sin(T + phi) + N
B = M * sin(T + theta) + N

T goes from 0 to 360 degress.
phi is 120 degrees
theta is 240 degrees

M and N are just adjustment constants, typically M=128 and N=128 to swing
over an entire unsigned 8-bit value.  I haven't done this for a while, but
I know that the sine waves should be evenly phase-shifted across an interval.
I'm pretty sure it's 360 degrees, but it might be 180 -- try and see.  This
should go dark_red-->purple with all of the colors inbetween in their proper
order.

One problem with this color set is that it's luminosity is constant.  While
the colors are vibrant, there is no contrast and hence an image using just these
colors can be a little boring.  If it's important, you may want to experiment
with some functions that add or subtract luminoisity and saturation to add
a little more diversity to the hues.

-Charles
========================
Send comments/flames to: forsythe@convex.com
Convex does not filter outgoing posts and is not responsible for the contents
	therein.

markv@gauss.Princeton.EDU (Mark VandeWettering) (01/04/90)

In article <2284@isaak.isa.de> schwarze@isaak.uucp (Jochen Schwarze) writes:

>I want to display the color spectrum of a rainbow. The wavelengths
>of visible light approximately run from 400 nm to 800 nm. So I'm
>looking for a function that maps a wavelength to the appropriate RGB
>triple. Has anybody done this? Any pointers appreciated.

	Nope.  Nobody has done this. :-)

Okay, okay.  If I wasn't going to help, I wouldn't post.  Dusting off
some of my books on the shelf, I see the traditional (if a text that
was only published last year can be traditional) solution for me.

Roy Hall, "Illumination and Color in Computer Generated Imagery"
1989 Springer-Verlag, ISBN 0-387-96774-5

Hall presents source code to precisely what you wish.  I believe that
you can even ftp the source from freedom.graphics.cornell.edu. (Yup, 
I just checked, in pub/Hall)

Mark VandeWettering