Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.6K Views
|
22 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to extract values from a Color Setter?

Posted 3 years ago

i have a simple Color Setter :

{ColorSetter[Dynamic[y]], Dynamic[y]}

How do I get the vales of the selected color into a variable? As an example, I would like to acces the Hue from "HSB"

The following srcipts don't work :

ee ={ColorSetter[Dynamic[y]], Dynamic[y]}
ee = Setting[{ColorSetter[Dynamic[y]], Dynamic[y]}]
ee = Setting[Hue[{ColorSetter[Dynamic[y]], Dynamic[y]}]]

In the examples of WL doc. I often miss, how can I put it, "the other way to use something". Too many examples that show the same 'angle'. I also searched on the internet, but I got the same things as in the WL doc.

POSTED BY: B. Cornas
22 Replies
Posted 3 years ago

Thanks again, Eric, for your excellent explanations. Some things I got, others are still a bit mysterious for me, as I do not seem to get them working, like the labels. But I will get it eventually.

Lab is another ColorSpace, that is fortunaltely supported by WL. It is a very usefull ColorSpace which I use a lot in working on my photo's and images. It seperates the luminosity (the L channel) from the color, which are in the a (Magenta versus Green) and the b channel (Yellow versus Blue). This is usefull in many ways and Lab is the ColorSpace to get your colors popping and right. Another advantage is, that Lab is constructed to work in the way we humans see. It also tries to be 'linear' in the steps. Channel L goes from 0-100 and the two color channels a & b go from -100 to 100. Any 'color' with zero in both the color channels is so a neutral. Measuring in Lab values makes it easy to detect color casts where they should not be.

Your help was very kind and most usefull. I have put on my heavy duty shoes, as it seems that the road is still quite long :-)

best, Beat

POSTED BY: B. Cornas
Posted 3 years ago

Lists : isn't that what is meant with "Listable"

Yes, exactly. I thought I'd explain it in plain terms rather than force you down another learning trail about attributes.

So this is what overloading means - restricting the input variable to a certain type (Hue).

Overloading basically means having multiple "functions" with the same name. In Java you can overload if your input lists differ in their types. Some languages don't allow overloading at all. In Mathematica, you can overload with pattern matching.

I am probably still thinking Old School [regarding using the color square as input]

Yeah, don't get me wrong. I don't know that I would actually ever do that for real. I was just taking the opportunity to make a point about about representations.

RGB, HSB and Lab triplets above each color. But I suppose I would have to get the numbers the same way as I did in my primitive try, and convert to the different colorSpaces.

Not at all. This bit here,

Flatten[{hue = ColorConvert[rgb, "HSB"], HueSplit[HueComplement[hue], spread]}]

evaluates to a List of Hues. You can apply ToString to them to see them as Hue[0.5, 0.5, 0.5] (or whatever). Before you do the ColorConvert, you'll have RGBColors, and you can apply ToString to those to see RGBColor[0., 0., 0.] (or whatever). I don't know what Lab is, so you might have to come up with your own display representation for that. Or, if you really do want them as just triplets (list of three elements), then do the List@@ thing.

I tried with a different start color for the ColorSetter (not Black), but nothing seemed to work

In the Manipulate, you can change the bit that specifies the controller for rgb to look like this: {{rgb, RGBColor[0.5, 0.22, 0.5]}, ColorSetter}

I am so much used to 'stay' in the numbers and variables, until all the calculations are done and only then do the 'Translation' to the graphics on screen

Right. I pretty much agree with you. That's kind of what I'm trying to explain when I go on about representations. But I think we've reached the limits of being able to communicate this idea within this context, so I won't belabor the point anymore.

POSTED BY: Eric Rimbey
Posted 3 years ago

Eric, you've put quite some work into helping me :-)

The HueComplement function I get. I had something similar, but less general. Lists : isn't that what is meant with "Listable"? Some functions have that attribute, some not.

HueSplit[.99, .07] the Mod nicely wraps the spread around if necessary. Get it.

So this is what overloading means - restricting the input variable to a certain type (Hue).

Eric wrote : Test (Notice how this time I copied the little color square from above directly into this input expression. Mathematica is fine with that.):

I kew this, but it feels very alien to me. I can see that it sometimes might come in handy, but up till now, the opposite has been true for me. But then again, I am probably still thinking Old School :-)

I worked through your excellent example and of course it works, with a much nicer Frame as well :-)

I will need some more time to go nitty gritty on your code and dive again into the docs (Thread and MapAt). Your solution is very elegant.

I noticed that the Dynamic version and the Manipulate version (in one Nb) interfere with each other. probably because of the same Dynamic variable(s).

There is a thing though that I struggle with : I am so much used to 'stay' in the numbers and variables, until all the calculations are done and only then do the 'Translation' to the graphics on screen. F.i. in this case, I would like to add the RGB, HSB and Lab triplets above each color. But I suppose I would have to get the numbers the same way as I did in my primitive try, and convert to the different colorSpaces.

So, I'll get back to you after having studied some more. Thanks

PS. I tried with a different start color for the ColorSetter (not Black), but nothing seemed to work. I guess the wrong syntax, although I tried quite a few.

POSTED BY: B. Cornas
Posted 3 years ago

Thanks Rohit, this works and let's me save the values in a seperate variable.

I would never have come up with this solution of putting parentesis. Something like this, is hard to search in the docs. The only way, I would imagine, to get to a solution is to know and understand the bigger processes behind the scenes, like what exactly is happening when //FullForm is used. Unfortunately, these deeper, but somehow very elementary things are not often mentioned in the docs or for that matter in books. I have read maybe 2500 pages of WL instruction books, but still do not have a clear idea or concept of WL. I fiddle and search until something as by magic starts working. Sometimes just putting a curly bracket in another place does the job, but I feel I still have no clue.

Fortunately there is the forum, populated with very kind and helpful people. Great :-)

POSTED BY: B. Cornas
Posted 3 years ago

Here's a deeper dive...

POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: B. Cornas
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

The problem is here

orgColorRGB = x // FullForm

In general, form wrappers are not computable expressions, they should be used for display purposes only. Change to

(orgColorRGB = x) // FullForm

Then this will work

colorResult1 = Graphics[{orgColorRGB, Rectangle[]}]
POSTED BY: Rohit Namjoshi
Posted 3 years ago
POSTED BY: B. Cornas

Hi Cornas,

You can simply attach a notebook to your comment using the button "Add a file to this post" at the bottom of the editor

enter image description here

POSTED BY: Ahmed Elbanna
Posted 3 years ago

I seem to have troubles to attach the NoteBook as a seperate file, instead of it being inserted into the post. I managed once, and now I think I do the same, but get different results.

How should I do it correctly?

POSTED BY: B. Cornas
Posted 3 years ago

Thanks Eric, your guidance is really helpful. It’s very much appreciated.

I understand what you are explaining to me. I will look into Apply later, but that seems interesting.

Your code :

Dynamic[{x, FullForm[x], ColorConvert[x, "HSB"], 
  FullForm[ColorConvert[x, "HSB"]], List @@ ColorConvert[x, "HSB"], 
  ColorConvert[x, "HSB"][[1]]}]

Works well and I understand all of it. So basically, I have now what I want to start with : The selected color in RGB numbers , as well as in HSB numbers.

Also the List thing works and is understandable.

From here I can continue.

I managed to make use of Apply, I think an important function. I used it to get the HSB values, which I transformed, again into a ‘color’ format.

hueComp1 stands for a complementary color

colComp1 = Apply[Hue, {hueComp1, orgColorHSBsat, orgColrHSBbrit}]

To show the colors in the form of rectangles I have the following code - with a question :-)

I don’t understand that not one of the first two lines does work, but only the third way : RGBColor[x] I have already : orgColorRGB = x // FullForm So why is it not working as orgColorRGB has the same values as x?

THIS DOES NOT WORK

colorResult1 = Graphics[{RGBColor[orgColorRGB], Rectangle[]}] ;       (*  The ORIGINAL COLOR  *)
colorResult1 = Graphics[{orgColorRGB, Rectangle[]}] ;       (*  The ORIGINAL COLOR  *)

BUT THIS DOES WORK

colorResult1 = Graphics[{RGBColor[x], Rectangle[]}] ;     (*  The ORIGINAL COLOR  *)

I attach the Nb I am working on for reference. The purpose of it is to select a color, and make two complementary colors, with an adjustable speed from the exact complementary color. I plan to use this to create nice 3 color palettes for my design work.

Thanks again Eric, really helpful.

Best, Beat

Attachments:
POSTED BY: B. Cornas
Posted 3 years ago
POSTED BY: B. Cornas
Posted 3 years ago

Apologies, I forgot to mention...

(* THIS DOES NOT WORK *) h=v[[1]]//InputForm

You had assigned the value to v1, not v. So, v1[[1]] will give you the first part of the expression.

POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

I get it so far. I would never have come up with //FullForm. This WL really does things different from what I am used to. very surprising.

Now the next step, which I thought I would be able to manage, but I don't :-(

If I select a color, take the //InputForm and convert to HSB I get e.g. the following :

Hue[0.14196606106828644, 0.6012019781875348, 0.9318074311436637]

As this is not a List, I do not know how to extract the parameters separately into the variables 'h', 's' and 'b'. See my clumsy attempts in the attached Nb :-)

POSTED BY: B. Cornas
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: B. Cornas
Posted 3 years ago

Eric, I tried, but I get the same result as before, being a little square in the selected color. If a do :
ColorSetter[Dynamic[x]] x I do not get any numbers, I get the colored square.

I need the values of the color, in RGB, Lab and HSB, so for e.g. for Red , something like :

{1,0,0} for RGB {0.7,50,50} for Lab {0,0.6,0.8} for HSB

From there on, I can extract the 'Hue' or any other parameter for the selected color.

PS. There are two more answeres in the list. One by Rohit Namjoshi and another by you. They both seem empty to me. Is that correct? I still do not feel very comfortable with how to interact with the Wolfram Forum. Sometimes strange things are manifesting :-)

POSTED BY: B. Cornas
Posted 3 years ago

Maybe a little more flavor would help. The documentation used the expression

{ColorSetter[Dynamic[x]], Dynamic[x]}

to demonstrate how you can dynamically update a variable with a ColorSetter. That expression isn't itself the "color setter". You could just as easily use an expression like this:

NonsenseHead[Dynamic[x], ColorSetter[Dynamic[y]], Dynamic[y], 
 ColorSetter[Dynamic[x]]]

If you evaluate that and play with the output, you can see that one ColorSetter is linked to one dynamic variable and the other to the other.

POSTED BY: Eric Rimbey
Posted 3 years ago

The symbol y has the selected color.

{ColorSetter[Dynamic[y]], Dynamic[y]}

Pick a color, then

y // InputForm
(* RGBColor[0.13130388342107271, 0.9996948195620661, 0.023590447852292667] *)

ColorConvert[y, "HSB"] // InputForm
(* Hue[0.3149416123434789, 0.9764023506067313, 0.9996948195620661] *)
POSTED BY: Rohit Namjoshi
Posted 3 years ago

If you execute this:

ColorSetter[Dynamic[x]]

then the value of x will be the color displayed by the ColorSetter. If you click on the ColorSetter and change the color it displays, then x will contain the value of the new color. In other words, the answer to your question, "How do I get the vales of the selected color into a variable?" is that you already have the value in a variable--it's the variable wrapped in Dynamic and passed to the ColorSetter.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard