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
Wed Dec 11 04:56:53 EST 2013


Hi all,

I just came to the conclusion that my comparison method was incorrect, as everything was running so quickly that the milliseconds was too coarse-grained. So I made a new stack with one graphic and one button with script:

##
constant kTestReruns = 10

on mouseUp
   -- 1. test with visible graphic control
   local tTest1Time1, tTest1Time2
   show graphic 1
   TestWithGraphicControl kTestReruns, tTest1Time1, tTest1Time2
   -- 2. test with visible graphic control and locked screen
   local tTest2Time1, tTest2Time2
   lock screen
   TestWithGraphicControl kTestReruns, tTest2Time1, tTest2Time2
   unlock screen
   -- 3. test with invisible graphic control
   local tTest3Time1, tTest3Time2
   hide graphic 1
   TestWithGraphicControl kTestReruns, tTest3Time1, tTest3Time2
   -- 4. test with templateGraphic
   local tTest4Time1, tTest4Time2
   TestWithTemplateGraphic kTestReruns, tTest4Time1, tTest4Time2
   --
   put "Test" & tab & "overlayColor" & tab & "backgroundPixel" & return & \
         "Visible" & tab & tTest1Time1 & tab & tTest1Time2 & return & \
         "Vis+Lock" & tab & tTest2Time1 & tab & tTest2Time2 & return & \
         "Invisible" & tab & tTest3Time1 & tab & tTest3Time2 & return & \
         "Template" & tab & tTest4Time1 & tab & tTest4Time2 & return
   answer "Done"
end mouseUp

command TestWithGraphicControl pTestReruns, @rTime1, @rTime2
   local tStart, tColorName, tColorRGB
   -- using colorOverlay
   put the milliseconds into tStart
   repeat pTestReruns times
      repeat for each line tColorName in the colorNames
         set the colorOverlay["color"] of graphic 1 to tColorName
         put the colorOverlay["color"] of graphic 1 into tColorRGB
      end repeat
   end repeat
   put the milliseconds - tStart into rTime1
   -- using backgroundPixel
   put the milliseconds into tStart
   repeat pTestReruns times
      repeat for each line tColorName in the colorNames
         set the backgroundColor of graphic 1 to tColorName
         set the backgroundPixel of graphic 1 to the effective backgroundPixel of graphic 1
         put the backgroundColor of graphic 1 into tColorRGB
      end repeat
   end repeat
   put the milliseconds - tStart into rTime2
end TestWithGraphicControl

command TestWithTemplateGraphic pTestReruns, @rTime1, @rTime2
   local tStart, tColorName, tColorRGB
   reset the templateGraphic
   -- using colorOverlay
   put the milliseconds into tStart
   repeat pTestReruns times
      repeat for each line tColorName in the colorNames
         set the colorOverlay["color"] of the templateGraphic to tColorName
         put the colorOverlay["color"] of the templateGraphic into tColorRGB
      end repeat
   end repeat
   put the milliseconds - tStart into rTime1
   -- using backgroundPixel
   put the milliseconds into tStart
   repeat pTestReruns times
      repeat for each line tColorName in the colorNames
         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 tColorRGB
      end repeat
   end repeat
   put the milliseconds - tStart into rTime2
   reset the templateGraphic
end TestWithTemplateGraphic

##

Here's the output on the machine I'm currently working on:
##
Test	overlayColor	backgroundPixel
Visible	4659	9616
Vis+Lock	24	36
Invisible	17	21
Template	14	17
##

Admittedly a small sample, but I'd say:
- using a visible graphic control without locking the screen is the worst approach
- using colorOverlay["color"] is faster than using backgroundPixel
- using templateGraphic is faster than using a real graphic control (visible or not)

HTH,

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)





More information about the use-livecode mailing list