Convert frequency to RGB

Dar Scott dsc at swcp.com
Mon Aug 11 23:34:00 EDT 2003


On Monday, August 11, 2003, at 09:24 PM, Jim Hurley wrote:

> But I have had a thought about how to simulate a continuous variation 
> in frequency of emerging light rays. So I would like a formula which 
> allows for a continuous variation in color of the graphic lines.

> But I'll bet that someone has worked out a reasonable least squares 
> fit (or whatever) of the tables you spoke of to reduce them to a nice 
> simple algebraic formula.

Even though it is not right, what you have should look OK.  I'd use 
127,127,0 for mid between red and green, not 255,255,0.  I'd put only a 
small purple tail.  I'm not sure why that looks bad.  It will also be 
off because the wavelengths should be compressed near the ends, but 
that is easily fixed.  It should also be darker near the ends.

If you can read C, look at this:

http://www.fourmilab.ch/documents/specrend/specrend.c

It has black body sources, wavelength to xyz (CIE), xyz constrained to 
rgb and maybe others.  The xyz to rgb uses a method I mentioned and is 
described here:

http://www.fourmilab.ch/documents/specrend/

Also, for anybody interested, the pictures explain what I was not able 
to, because, well, partly because this kind of thing needs pictures.  
Sorry about the gobblygook.

An interpolation table and a function to work with it is not so bad.  
I'm sure folks here would be glad to help.  There are ways to make the 
table inline.  (This means I know of no formula.)

I think you can make sunlight from a blackbody of the right temperature.

If the C code example does no good at all, I'll provide some short 
tables.

I'm still baffled by why the colors look bad.  How are you setting the 
colors?

Dar Scott







More information about the use-livecode mailing list