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

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

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

jim hurley
The subject says it all.

Thanks.

Jim

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Peter Haworth
Here's 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

Pete
lcSQL Software <http://www.lcsql.com>


On Mon, Dec 9, 2013 at 3:30 PM, James Hurley <[hidden email]>wrote:

> The subject says it all.
>
> Thanks.
>
> Jim
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Peter Haworth
In reply to this post by jim hurley
I'll try that again with better formatting:

*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

Pete
lcSQL Software <http://www.lcsql.com>


On Mon, Dec 9, 2013 at 3:30 PM, James Hurley <[hidden email]>wrote:

> The subject says it all.
>
> Thanks.
>
> Jim
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Devin Asay
In reply to this post by jim hurley

On Dec 9, 2013, at 4:30 PM, James Hurley wrote:

> The subject says it all.

Jim,

I think the only option is to set one of the color properties of an object to a named color, then examine the value of that property.

set the backgroundColor of grc "foo" to aquamarine
put the backgroundColor of grc "foo"

Devin

Devin Asay
Learn to code with LiveCode University
http://university.livecode.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

jim hurley
But Keven ,

if the set is “blue”
then the Put is “blue”

How can for the Put into rgb?

Jim

n Dec 9, 2013, at 4:30 PM, James Hurley wrote:

> The subject says it all.

Jim,

I think the only option is to set one of the color properties of an object to a named color, then examine the value of that property.

set the backgroundColor of grc "foo" to aquamarine
put the backgroundColor of grc "foo"

Devin

Devin Asay
Learn to code with LiveCode University
http://university.livecode.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Peter Haworth
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

Pete
lcSQL Software <http://www.lcsql.com>


On Mon, Dec 9, 2013 at 4:43 PM, James Hurley <[hidden email]>wrote:

> But Keven ,
>
> if the set is “blue”
> then the Put is “blue”
>
> How can for the Put into rgb?
>
> Jim
>
> n Dec 9, 2013, at 4:30 PM, James Hurley wrote:
>
> > The subject says it all.
>
> Jim,
>
> I think the only option is to set one of the color properties of an object
> to a named color, then examine the value of that property.
>
> set the backgroundColor of grc "foo" to aquamarine
> put the backgroundColor of grc "foo"
>
> Devin
>
> Devin Asay
> Learn to code with LiveCode University
> http://university.livecode.com
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Walt Brown
In reply to this post by jim hurley
http://lessons.runrev.com/s/lessons/m/2592/l/125746-translating-a-color-name-to-an-rgb-numeric-triplet


On Mon, Dec 9, 2013 at 6:30 PM, James Hurley <[hidden email]>wrote:

> The subject says it all.
>
> Thanks.
>
> Jim
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Richard Gaskin
In reply to this post by Peter Haworth
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
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Jan Schenkel
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 <[hidden email]> wrote:

 Subject: Re: How do I find the rgb values for colors defined by their name: e.g. blue, green, yellow etc.
 To: [hidden email]
 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
 [hidden email]
 Please visit this url to subscribe, unsubscribe and manage
 your subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

J. Landman Gay
On 12/10/13 3:09 PM, Jan Schenkel wrote:

>
> 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
> ##

These are great scripts, they're going into my scrapbook.

The original question though was how to convert an RGB value to the
nearest colorname. I don't think you can.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Peter Haworth
In reply to this post by Jan Schenkel
Thanks Jan, I will convert to using that method.

Pete
lcSQL Software <http://www.lcsql.com>


On Tue, Dec 10, 2013 at 1:09 PM, Jan Schenkel <[hidden email]> wrote:

> 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 <[hidden email]> wrote:
>
>  Subject: Re: How do I find the rgb values for colors defined by their
> name: e.g. blue, green, yellow etc.
>  To: [hidden email]
>  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
>  [hidden email]
>  Please visit this url to subscribe, unsubscribe and manage
>  your subscription preferences:
>  http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Peter Haworth
In reply to this post by J. Landman Gay
Whoops, really?  I read it the other way round.  Which was it Jim?

Pete
lcSQL Software <http://www.lcsql.com>


On Tue, Dec 10, 2013 at 1:42 PM, J. Landman Gay <[hidden email]>wrote:

> On 12/10/13 3:09 PM, Jan Schenkel wrote:
>
>>
>> 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
>> ##
>>
>
> These are great scripts, they're going into my scrapbook.
>
> The original question though was how to convert an RGB value to the
> nearest colorname. I don't think you can.
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Alejandro Tejada
In reply to this post by jim hurley
Hi Jim,

Jim Hurley-2 wrote
The subject says it all.
Could you use a lookup list? :D
http://web.njit.edu/~kevin/rgb.txt.html

Al
Reply | Threaded
Open this post in threaded view
|

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

Peter Haworth
In reply to this post by J. Landman Gay
Whoops, really?  I read it the other way round.  Which was it Jim?

Pete
lcSQL Software <http://www.lcsql.com>


On Tue, Dec 10, 2013 at 1:42 PM, J. Landman Gay <[hidden email]>wrote:

> On 12/10/13 3:09 PM, Jan Schenkel wrote:
>
>>
>> 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
>> ##
>>
>
> These are great scripts, they're going into my scrapbook.
>
> The original question though was how to convert an RGB value to the
> nearest colorname. I don't think you can.
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Stephen Barncard-4
In reply to this post by J. Landman Gay
On Tue, Dec 10, 2013 at 1:42 PM, J. Landman Gay <[hidden email]>wrote:

> The original question though was how to convert an RGB value to the
> nearest colorname. I don't think you can.


​sure you can.  But a human needs to be involved in the substitution.
Create a list with all the standard color names converted to RGB values-
put the name, a comma and the triplet on each line.​

then do a search to find a matching triplet

if found, display the name. If not, present an answer color dialog showing
the un-named color, allowing the substitution of a near neighbor.



*--*
*Stephen Barncard - San Francisco Ca. USA - Deeds Not Words*
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

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

Alejandro Tejada
Stephen Barncard-4 wrote
​sure you can.  But a human needs to be involved in the substitution.
Create a list with all the standard color names converted to RGB values-
put the name, a comma and the triplet on each line.​

then do a search to find a matching triplet

if found, display the name. If not, present an answer color dialog showing
the un-named color, allowing the substitution of a near neighbor.
Actually, as RGB colors are just numbers, it should possible to
create a pattern matching function to look up for the
nearest color in the Named colors list... :)

If I do not have this headache, I will be testing this idea
just for fun... :o

Al
Reply | Threaded
Open this post in threaded view
|

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

Jan Schenkel
In reply to this post by Jan Schenkel
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)


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode