RGB triplet for color names
Wilhelm Sanke
sanke at hrz.uni-kassel.de
Sat Mar 15 15:11:01 EST 2003
On Sat, 15 Mar 2003 Jim Hurley <jhurley at infostations.com> wrote:
> Does anyone know how to get the RGB color triplet for a given color name?
>
> For example the Color Names window shows ForestGreen to be 34,139,34
>
> How would I get those numbers programmatically, that is without going
> through the Color Names window?
>
> That is
>
> Put theRGB("ForestGreen") into theForestGreenTriplet
>
> Or whatever.
>
> Much appreciated,
>
> Jim
>
Hallo Jim,
You have first to set the backcolor of a - preferably hidden - control
to the colorname and then retrieve the RGB value by means of the
backpixel property. There was a short discussion on this list about such
questions at the beginning of last December.
One possibility: Write a "ColorToRGB" handler and create a field
"hiddenfield"
"on colorToRGB which
set the backcolor of fld "hiddenfield" to which
get the effective backPixel of fld "hiddenfield"
set the backPixel of field "Hiddenfield" to it
put the backcolor of fld "Hiddenfield" into anyColorVar
end colorToRGB"
then use this handler anywhere in your scripts
on mouseup
ColorToRGB cyan # or whatever colorname you want to convert
put anyColorVar" # or do whatever you like with anyColorVar
end mouseup
If you use both handler in a single script put "local anyColorVar" at
the top of the script. If you put the "colorToRGB" handler elsewhere,
maybe into the card script, you have of course to declare global
variables (Excuse me if I am being redundant here).
Regards,
Wilhelm Sanke
More information about the use-livecode
mailing list