Convert frequency to RGB
Jim Hurley
jhurley at infostations.com
Mon Aug 11 17:50:01 EDT 2003
>
>Message: 14
>Date: Mon, 11 Aug 2003 12:20:03 -0600
>Subject: Re: Convert frequency to RGB
>From: Dar Scott <dsc at swcp.com>
>To: use-revolution at lists.runrev.com
>Reply-To: use-revolution at lists.runrev.com
>
>
>On Sunday, August 10, 2003, at 10:03 AM, Jim Hurley wrote:
>
>> I am trying to create the effect of gradually running through all
>> colors of the visible spectrum.
>
>Maybe you can scan in a picture you like and then use the imageData as
>your table.
>
>There are several factors: Sun color, eye response tristimulus values
>or chramaticity coordinates (see CIE), phosphor colors and the effect
>of faking colors outside what the phosphors can do. I don't know much
>about phosphors, but I can provide some info on the sun and on CIE data.
>
>For your effect, you might want to see if a simplification works.
>
>You should be fine with straight-line approximations between RGB
>colors. Do this by making a straight-line interpolation of each
>component. Create a table from wavelength (or lightspeed number or
>whatever) to color. Maybe three arrays will work.
>
>If you need help in getting even rough data for your table, let me know.
>
>Dar
Dar,
I think I have found what I need. I had hoped I could find an
algebraic formula for the translation from wavelength to rgb values.
I did a Google search and found the following program; I will see if
I can translate it into Transcript.
Jim
PROCEDURE WavelengthToRGB(CONST Wavelength: Nanometers;
VAR R,G,B: BYTE);
CONST
Gamma = 0.80;
IntensityMax = 255;
VAR
Blue : DOUBLE;
factor : DOUBLE;
Green : DOUBLE;
Red : DOUBLE;
FUNCTION Adjust(CONST Color, Factor: DOUBLE): INTEGER;
BEGIN
IF Color = 0.0
THEN RESULT := 0 // Don't want 0^x = 1 for x <> 0
ELSE RESULT := ROUND(IntensityMax * Power(Color * Factor, Gamma))
END {Adjust};
BEGIN
CASE TRUNC(Wavelength) OF
380..439:
BEGIN
Red := -(Wavelength - 440) / (440 - 380);
Green := 0.0;
Blue := 1.0
END;
440..489:
BEGIN
Red := 0.0;
Green := (Wavelength - 440) / (490 - 440);
Blue := 1.0
END;
490..509:
BEGIN
Red := 0.0;
Green := 1.0;
Blue := -(Wavelength - 510) / (510 - 490)
END;
510..579:
BEGIN
Red := (Wavelength - 510) / (580 - 510);
Green := 1.0;
Blue := 0.0
END;
580..644:
BEGIN
Red := 1.0;
Green := -(Wavelength - 645) / (645 - 580);
Blue := 0.0
END;
645..780:
BEGIN
Red := 1.0;
Green := 0.0;
Blue := 0.0
END;
ELSE
Red := 0.0;
Green := 0.0;
Blue := 0.0
END;
// Let the intensity fall off near the vision limits
CASE TRUNC(Wavelength) OF
380..419: factor := 0.3 + 0.7*(Wavelength - 380) / (420 - 380);
420..700: factor := 1.0;
701..780: factor := 0.3 + 0.7*(780 - Wavelength) / (780 - 700)
ELSE factor := 0.0
END;
R := Adjust(Red, Factor);
G := Adjust(Green, Factor);
B := Adjust(Blue, Factor)
END {WavelengthToRGB};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.runrev.com/pipermail/use-livecode/attachments/20030811/2b6ec9c6/attachment.html>
More information about the use-livecode
mailing list