Convert frequency to RGB

Jim Hurley jhurley at infostations.com
Mon Aug 11 19:41:01 EDT 2003


>
>Message: 10
>Date: Mon, 11 Aug 2003 17:20:41 -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 Monday, August 11, 2003, at 04:43 PM, Jim Hurley wrote:
>
>>  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.
>>
>That should translate OK.  As with yours, it changes only red, green or
>blue at a time, and thus will vary in intensity in ways not intended. 
>The blue-purple looks like it goes too purple to me.  The function does
>attempt to put an envelope over the whole thing that is probably
>related to sun intensity and eye response.
>
>See how it looks.
>
>Dar Scott
>

Dar,

Not very well. Still a bit jerky--in the literal sense. I may have to 
work on this for a while. I've seen some very nice graphics, I think 
it was in a web page construction application which had a 
rainbow-line as a demarker between sections.

I wonder if an image like this could be imported into RR and 
deciphered  the RGB values from the image by running the wand (from 
the 1.1.1 color palette) over it and somehow extract this data.

I think I got the Pascal program translated correctly. It looks like this:

on mouseUP
   repeat with wavelength = 779 down to 381
     set the backgroundcolor of grc 1 to convertWavelength(wavelength)
     wait 1 tick
   end repeat
end mouseUP


function convertWavelength w

   switch
   
   case w>380 and w <= 419
     put .3 + .7*(w-380)/(420-380) into tFactor
     put -tFactor*(w-440)/(440-380),0,tFactor into results
     break
   
   CASE  w >419 and w <=440
     put -(w-440)/(440-380),0,1 into results
     break
   
   case w > 440 and w <=490
     put 0,(w-440)/(490-440),1 into results
     break
   
   case w>  490 and w <=510
     put 0,1,-(w-510)/(510-490)into results
     break
   
   case w>  510 and w<=580
     put (w-510)/(580-510),1,0 into results
     break

   case w>580 and w<= 645
     put 1,-(w-645)/(645-580),0 into results
     break

   case w >645 and w<=701
     put 1,0,0 into results
     break
   
   case w>701 and w< 780
     put 0.3 + 0.7*(780 - w)/(780 - 700) into tFactor
     put tFactor,0,0 into results
     break
   end switch

   repeat with i = 1 to 3
     put round(255*(item i of results)) into item i of tResults
   end repeat

   return tResults

end convertWavelength



More information about the use-livecode mailing list