Equivalence of Color names to RGB

Richard Gaskin ambassador at fourthworld.com
Sat Jul 3 23:42:43 EDT 2004


Alejandro Tejada wrote:
> Hi developers,
> 
> I've almost finished a handler to export
> vector graphics from RR/MC to Adobe Ilustrator
> version 7 file format, but i need a table
> of equivalences between rgb and the color names,
> for example: AliceBlue = 239,247,255.
> 
> How could i convert the color names to their
> equivalent rgb triplet?

I don't know a way to do it programmatically (would be nice -- anyone 
know?), but you could write a lookup function if you're willing to 
include a list of the colorname/values somewhere.

You can create the list of values by making button with this script:

on mouseUp
   repeat for each line tColor in colorNames()
     set the backColor of me to tColor
     wait 2 with messages -- let OS X catch up with redraw
     put tColor &comma& the mouseColor &cr after tNuList
   end repeat
   delete last char of tNuList
   put tNuList into fld "ColorNamesLookup"
end mouseUp

Of course you'll need to leave the mouse over the button while it runs, 
but it doesn't take long and you'll only need to run it once.

Once you have your "ColorNamesLookup" field populated, your lookup 
function could be something like this:


function ColorName2RGB pColorName
   put fld "ColorNamesLookup" into tList
   get lineoffset(cr&pColorName&comma,cr&tList)
   if it = 0 then return empty
   else return item 2 to 4 of line it of tList
end ColorName2RGB

-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com


More information about the use-livecode mailing list