Convert frequency to RGB

Jim Hurley jhurley at infostations.com
Sun Aug 10 11:10:00 EDT 2003


I am trying to create the effect of gradually running through all 
colors of the visible spectrum. Unfortunately there is very little 
correlation between frequency (or wavelength) and the RGB numbers 
used to represent color on the screen. I know that algorithms exist 
but I have had no  experience with this.

I have  come up  with a real cludge (below). It is not smooth.

Anyone out there had any experience with this sort of thing? (I don't 
mean the handler itself. That can be streamlined. I mean the basic 
algorithm. Something that moves more smoothly through the 
electromagnetic spectrum.)

on mouseUP
   put 255 into r
   put 0 into g
   put 0 into b

   put 1 into dr
   put 1 into dg
   put 1 into db

   put 5 into theWait

   --red to yellow (255,0,0)to (255,255,0)
   repeat 255
     set the backgroundcolor of graphic 1 to  r,g,b
     add dg to g
     wait theWait millisec
   end repeat

   -- yellow to green (255,255,0) to (0,255,0)
   repeat 255
     set the backgroundColor of graphic 1 to r,g,b
     subtract dr from r
     wait theWait millisec
   end repeat

   --green to blue (0,255,0) to (0,0,255)
   repeat 255
     set the backgroundColor of graphic 1 to r,g,b
     subtract dg from g
     add db to b
     wait theWait millisec
   end repeat

   --blue to violet (0,0,255) to (127,0,127)
   repeat 127
     set the backgroundColor of graphic 1 to r,g,b
     add dr to r
     subtract db from b
     wait theWait millisec
   end repeat
end mouseUP

Jim



More information about the use-livecode mailing list