RGB triplet for color names

Jeanne A. E. DeVoto jeanne at runrev.com
Sat Mar 15 14:56:03 EST 2003


At 8:25 AM -0800 3/15/03, Jim Hurley wrote:
>Does anyone know how to get the RGB color triplet for a given color name?

Here's a way that relies on a trick discovered by (if I remember correctly)
Ken Ray:

function RGBFromColorName theColor
  if theColor is not a color then return "Error: not a color"
  -- create a temporary object for the color transformation:
  create invisible button
  if the result is not empty then return "Error"
  set the backgroundColor of last button to theColor
  -- transform the color using the backgroundPixel trick:
  set the backgroundPixel of last button to \
      the backgroundPixel of last button
  -- the button's backgroundColor is now RGB:
  get the backgroundColor of last button
  delete last button -- don't need the temp object any more
  -- the create command automatically chose the pointer
  -- tool, so change it back:
  send "choose browse tool" to me in 10 milliseconds
  return it
end RGBFromColorName

--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
Runtime Revolution Limited - Software at the Speed of Thought
http://www.runrev.com/





More information about the use-livecode mailing list