<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: Convert frequency to RGB</title></head><body>
<blockquote type="cite" cite><br>
Message: 14<br>
Date: Mon, 11 Aug 2003 12:20:03 -0600</blockquote>
<blockquote type="cite" cite>Subject: Re: Convert frequency to RGB<br>
From: Dar Scott <dsc@swcp.com><br>
To: use-revolution@lists.runrev.com<br>
Reply-To: use-revolution@lists.runrev.com<br>
<br>
<br>
On Sunday, August 10, 2003, at 10:03 AM, Jim Hurley wrote:<br>
<br>
> I am trying to create the effect of gradually running through
all <br>
> colors of the visible spectrum.<br>
<br>
Maybe you can scan in a picture you like and then use the imageData
as <br>
your table.<br>
<br>
There are several factors:  Sun color, eye response tristimulus
values <br>
or chramaticity coordinates (see CIE), phosphor colors and the effect
</blockquote>
<blockquote type="cite" cite>of faking colors outside what the
phosphors can do.  I don't know much <br>
about phosphors, but I can provide some info on the sun and on CIE
data.<br>
<br>
For your effect, you might want to see if a simplification works.<br>
<br>
You should be fine with straight-line approximations between
RGB <br>
colors.  Do this by making a straight-line interpolation of
each <br>
component.  Create a table from wavelength (or lightspeed number
or <br>
whatever) to color.  Maybe three arrays will work.<br>
<br>
If you need help in getting even rough data for your table, let me
know.<br>
</blockquote>
<blockquote type="cite" cite>Dar</blockquote>
<div><br></div>
<div>Dar,</div>
<div><br></div>
<div>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.</div>
<div><br></div>
<div>Jim</div>
<div><br></div>
<div><font color="#000000">PROCEDURE WavelengthToRGB(CONST
Wavelength:  Nanometers;<br>
           <span
></span
>           <span
></span>    VAR R,G,B:  BYTE);<br>
  CONST<br>
    Gamma       
=   0.80;<br>
    IntensityMax = 255;<br>
  VAR<br>
    Blue   :  DOUBLE;<br>
    factor :  DOUBLE;<br>
    Green  :  DOUBLE;<br>
    Red    :  DOUBLE;<br>
  FUNCTION Adjust(CONST Color, Factor:  DOUBLE): 
INTEGER;<br>
  BEGIN<br>
    IF   Color = 0.0<br>
    THEN RESULT := 0     // Don't
want 0^x = 1 for x <> 0<br>
    ELSE RESULT := ROUND(IntensityMax * Power(Color *
Factor, Gamma))<br>
  END {Adjust};<br>
BEGIN<br>
  CASE TRUNC(Wavelength) OF<br>
    380..439:<br>
      BEGIN<br>
        Red   :=
-(Wavelength - 440) / (440 - 380);<br>
        Green := 0.0;<br>
        Blue  := 1.0<br>
      END;<br>
    440..489:<br>
      BEGIN<br>
        Red   := 0.0;<br>
        Green := (Wavelength - 440)
/ (490 - 440);<br>
        Blue  := 1.0<br>
      END;<br>
    490..509:<br>
      BEGIN<br>
        Red   := 0.0;<br>
        Green := 1.0;<br>
        Blue  := -(Wavelength
- 510) / (510 - 490)<br>
      END;<br>
    510..579:<br>
      BEGIN<br>
        Red   :=
(Wavelength - 510) / (580 - 510);<br>
        Green := 1.0;<br>
        Blue  := 0.0<br>
      END;<br>
    580..644:<br>
      BEGIN<br>
        Red   := 1.0;<br>
        Green := -(Wavelength -
645) / (645 - 580);<br>
        Blue  := 0.0<br>
      END;<br>
    645..780:<br>
      BEGIN<br>
        Red   := 1.0;<br>
        Green := 0.0;<br>
        Blue  := 0.0<br>
      END;<br>
    ELSE<br>
      Red   := 0.0;<br>
      Green := 0.0;<br>
      Blue  := 0.0<br>
  END;<br>
  // Let the intensity fall off near the vision limits<br>
  CASE TRUNC(Wavelength) OF<br>
    380..419:  factor := 0.3 + 0.7*(Wavelength -
380) / (420 - 380);<br>
    420..700:  factor := 1.0;<br>
    701..780:  factor := 0.3 + 0.7*(780 -
Wavelength) / (780 - 700)<br>
    ELSE       factor :=
0.0<br>
  END;<br>
<br>
  R := Adjust(Red,   Factor);<br>
  G := Adjust(Green, Factor);<br>
  B := Adjust(Blue,  Factor)<br>
END
{WavelengthToRGB};        <span
></span
>           <span
></span
>            <br
>
</font></div>
</body>
</html>