How do I find the rgb values for colors defined by their name: e.g. blue, green, yellow etc.

Jan Schenkel janschenkel at yahoo.com
Tue Dec 10 16:09:33 EST 2013


Hi Richard et al,

There's an even faster method, based on the fact that the graphic effects always convert colour names to rob triplets.
See: <http://quality.runrev.com/show_bug.cgi?id=10253>

Here's a script to compare the average speed of the colorOverlay["color"] method versus the effective backPixel method:
##
on mouseUp
   local tColorName, tColorRGB1, tColorRGB2, tStart, tTime1, tTime2
   repeat for each line tColorName in the colorNames
      put the milliseconds into tStart
      set the colorOverlay["color"] of the templateGraphic to tColorName
      put the colorOverlay["color"] of the templateGraphic into tColorRGB1
      put the milliseconds - tStart & comma after tTime1
      put the milliseconds into tStart
      set the backgroundColor of the templateGraphic to tColorName
      set the backgroundPixel of the templateGraphic to the effective backgroundPixel of the templateGraphic
      put the backgroundColor of the templateGraphic into tColorRGB2
      put the milliseconds - tStart & comma after tTime2
   end repeat
   delete char -1 of tTime1
   delete char -1 of tTime2
   --
   answer "colorOverlay[color]" && average(tTime1) & return & \
         "backgroundPixel" && average(tTime2)
end mouseUp
##

On my machine, the output was
colorOverlay[color] 0.001812
backgroundPixel 0.005435

Incidentally, this is the method I will include in the next revision of Quartam Color Library.
That is a free/open source library, available under the commercial-friendly LGPL license.
See: <http://www.quartam.com>

Cheers,

Jan Schenkel.

=====
Quartam Reports & PDF Library for LiveCode
www.quartam.com

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

--------------------------------------------
On Mon, 12/9/13, Richard Gaskin <ambassador at fourthworld.com> wrote:

 Subject: Re: How do I find the rgb values for colors defined by their name: e.g. blue, green, yellow etc.
 To: use-livecode at lists.runrev.com
 Date: Monday, December 9, 2013, 5:21 PM
 
 Peter Haworth wrote:
 
 > Hi Jim,
 > Sent this earlier but it didn't make it for some
 reason.  This is a
 > function that some kind person on the list gave me a
 while back:
 >
 > *function* RGBFromColorName theColor
 > *   if* theColor is not a color *then*
 *return* "Error: not a color"
 >
 >    *create* invisible button
 >
 >    *if* the result is not empty *then*
 *return* "Error"
 >
 >    *set* the backgroundColor of last button
 to theColor
 >
 >    *set* the backgroundPixel of last button
 to the backgroundPixel of last
 > button
 >
 >    *get* the backgroundColor of last button
 >
 >    *delete* last button
 >
 >    *return* it
 >
 >    *end* RGBFromColorName
 
 For greater robustness and a modest performance boost you
 could use the 
 templateButton rather than creating a new physical button.
 
 --
   Richard Gaskin
   Fourth World
   LiveCode training and consulting: http://www.fourthworld.com
   Webzine for LiveCode developers: http://www.LiveCodeJournal.com
   Follow me on Twitter:  http://twitter.com/FourthWorldSys
 
 _______________________________________________
 use-livecode mailing list
 use-livecode at lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage
 your subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 




More information about the Use-livecode mailing list