Extract color code

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9867
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Extract color code

Post by FourthWorld » Thu Feb 17, 2022 7:00 pm

IIRC someone here or on the mailing list posted a CMYK conversion function within the last few years.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7266
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Extract color code

Post by jacque » Thu Feb 17, 2022 7:27 pm

I've noticed that if I set the color from the hex pane of the color picker then that's what I get back when querying for the color. Not sure if that's useful in this case.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Extract color code

Post by dunbarx » Thu Feb 17, 2022 7:28 pm

This shows at least one simple and direct conversion:
https://www.rapidtables.com/convert/col ... o-rgb.html
Though I have read that because the two worlds these protocols live in, print, which has four elements (CYMK) and is subtractive, and screen, which has three elements (RGB) and is additive, the conversion is not so simple.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4036
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Extract color code

Post by bn » Thu Feb 17, 2022 8:58 pm

Here is a stack that has color type conversions from Monte Goulding. I made small corrections to it and post it here.
I talked about this stack with Monte way back on a conference in Edinburgh and he was fine with the corrections to the library and did not mind it being in the public domain. It would be nice to give him credit when using it in your project.

Kind regards
Bernd
Attachments
libColor_Monte_BN.livecode.zip
(19.19 KiB) Downloaded 76 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9476
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Extract color code

Post by richmond62 » Sat Feb 19, 2022 7:02 pm

Here's a fairly goofy question:

What does max mean in this context?

K = 1-max(R', G', B')

"Its the short form of representing, a function that returns maximum among a set of given numbers."

https://math.stackexchange.com/question ... s-max-mean
-
SShot 2022-02-19 at 20.04.26.png
SShot 2022-02-19 at 20.04.26.png (5.23 KiB) Viewed 2750 times
-
Ah: nothing quite like the "soggy toast" feeling of answering one's own questions. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9476
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Extract color code

Post by richmond62 » Sat Feb 19, 2022 7:40 pm

SShot 2022-02-19 at 20.37.34.png
-
Convert RGB 'guff' into CMYK 'guff'.

15 minutes on 2 very strong Gin-and-Tonics proving that the Maths on this page is
OFF by a factor of 100:

https://www.rapidtables.com/convert/col ... -cmyk.html

Stack removed as improved version posted in next post.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9476
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Extract color code

Post by richmond62 » Sat Feb 19, 2022 8:34 pm

SShot 2022-02-19 at 21.31.05.png
-
As I have never had to do this in the last 20-odd years what on earth prompted me
to look up round in the Dictionary . . .
Attachments
CoMe-YucK.livecode.zip
(1.11 KiB) Downloaded 85 times

PaulDaMacMan
Posts: 637
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Extract color code

Post by PaulDaMacMan » Wed May 22, 2024 3:27 am

A couple years late to this thread, but I just wanted to add (re-CMYK) that as mentioned they're two different color worlds, additive color vs. subtractive color, so there's no perfectly correct conversion to be had.

Usually there's some adjustment made in the process of converting to CMYK from RGB, that is there's usually a color curve applied that's (probably not) calibrated to a printing device. This is referred to as GCR (gray component replacement) or UCR (under color removal).

So there's my $0.02
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

stam
Posts: 2776
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Extract color code

Post by stam » Wed May 22, 2024 10:11 am

Also late to this, but just to add that the FerrusLogic team have previously ported the javascript framework TinyColor to liveCode and made it available as opensource on GitHub under the extremely permissive MIT licence (you just need to include the licence info and use in any commercial/non-commercial way you see fit): https://github.com/Ferruslogic/TinyColor

This does a ton of colour conversions and has around 70 functions. A valuable library and contribution

While it is always fun to learn by doing, to be productive using libraries like this are a must... just posting for awareness.

Stam

PaulDaMacMan
Posts: 637
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Extract color code

Post by PaulDaMacMan » Wed May 22, 2024 8:26 pm

stam wrote:
Wed May 22, 2024 10:11 am
While it is always fun to learn by doing, to be productive using libraries like this are a must... just posting for awareness.

Stam
Right, I knew that but your posting that link (thanks) had me looking at it again and just notice there's a nice function in there:
getSystemAppearance() to check if operating system is in dark or light mode that works on Mac,iOS, Android, and Windows.

The only problem is it doesn't do Linuxes, I'm looking into doing something like that (there's a lot of variations in Linux world to consider).

There's also none for running in a browser (Emscripten / HTML5), that's easy enough to get from web API.
As seen here, fourth button from top right side: http://openxtalk.org//WebStacks/HC3PlusPlus.html
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”