Does hexadecimal color codes in block editor not work?

I would like to use hexadecimal color codes in block editor. Since it is available in designer I thought I just copy the code from it. Well, turned out I was wrong. What the heck. I want to select elements by comparing hexadecimal color codes, but seems what available in the designer is kind of just a hint. I was naive again. I am too tired to figure out myself, but is it possible to convert that hex code in the designer to a one that usable in block editor? I mean I can make a hex to decimal converter, but I think that is not enough because there is a hex to base10 block in the editor but I could not make it work. I do not know how opacity integrated in the math.

1 Like

Ok, so far I understand it and mostly figured out myself the RGB to hex conversion.
The problem is I want to copare with a color that the app gives back. For example textcolor or backgroundcolor of an element.And the conversion does not seems to work for that. I try tom ake a test app fast.

OK. It is working. I just tried to use the hex as the AI2 use in block, put the alfa to the begining of the hex that is why it did not work first time. Thank you.

OK. One more question. How do you compare the RGBA code of the elements. I tried it with the make color block, but does not work.
Like this:


I tried without the color making blocks on the left side of compare still did not work.
Color blocks is a mess.

You could break down the two colors into R1,G1,B1 and R2,G2,B2 then compute the 3 dimensional distance between the two colors in RGB space:
ABS(R1-R2) + ABS(G1-G2) + ABS(B1-B2)

Colors are just 32 bit integers where the alpha channel is the highest order 8 bits, followed by red, green, and blue, respectively. You don't need to split them to compare them for equality. Also, each channel is 0-255, so the color you are expressing in those blocks is just a mostly transparent near-black. I don't know if that is intentional or not.

Color distance metrics are useful for cases where your colors are close but not exact, like from spots in an image.

Having a metric lets you find the closest matching color from a list of named colors.

That's what I thought too. Thank you. The main problem is the relationship between the designer and the block programming interface.
Like the example I showed to @TIMAI2.
If I set the color in blocks then works OK.
Like he showed it to me.


BUT
If I set it in designer:

Then it does not work.
And I even tried to put the alfa before the RGB numbers in the block section (1,1,0,0) but it did not work either.

So I guess there is some kind of rounding in the math between the designer and the block interface or something else.

Experimenting a little I found out 2 things.
1- I can not match an RGBA code getting from an item`s properties set in the designer with one I make in blocks.

So, the conclusion is, if I want to make use of the colors was set in the designer I have to use the color to hex conversion that @TIMAI2 provided. That works hundred percent.

The simple RED set in designer gives back the color number of -65536. While if I set it in blocks it is a much bigger number and positive, so the math does not match.

Edit: Hm. If I pull the RED from the color palette then it is OK, but if I make it from RGB colors then it is not. So the "make color" block is not compatible with the palette.

Yep, depending on where you look, you either get the Decimal 64 bit colour number or the Decimal 32 (24) bit colour number

:upside_down_face:

1 Like

Yes, you are right. Brilliant.

Well, there is a future update plan for the team. :smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.