ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Hex Code from text?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Street
Hex Code from text?
on Sep 18, 2017 at 10:34:43 am

Hi, I have a query.

I have a text layer which contains a hex value. I also have a Colour Control effect applied to a Null object.

I would like to set the colour of the Colour Control to the value which the text layer contains, using an expression

So, for example, if the value "ff0000" was written inside the text layer, the Colour Control effect would use that value and create a red colour.

Is there a way this can be achieved?

Many thanks!


Return to posts index

Scott McGee
Re: Hex Code from text?
on Sep 18, 2017 at 11:38:14 am

Dan Ebberts posted this a while back for someone else

hexColor = 0xfbd142;
r = (hexColor >> 16)/255;
g = ((hexColor & 0x00ff00) >> 8)/255;
b = (hexColor & 0xff)/255;
hsl = rgbToHsl([r,g,b,1]);

You could set up your "Text" layer (source text) add this to the expression

"0x" + text.sourceText;

Then when you copy and paste the hex code it will automatically add the 0x at front.

Then the above expression change to this.

hexColor = thisComp.layer("Text").text.sourceText;
r = (hexColor >> 16)/255;
g = ((hexColor & 0x00ff00) >> 8)/255;
b = (hexColor & 0xff)/255;
hsl = rgbToHsl([r,g,b,1]);


That should work for you.


Return to posts index

Chris Street
Re: Hex Code from text?
on Sep 18, 2017 at 12:51:40 pm

Hi, thanks for your help but I'm not sure if I've done this correctly.

The initial hex colour in the text layer is "ff0000" (red) but after implementing the code as below, the resultant colour ends up being a hex value of #2C3C7A (a luminous green).

Have I done anything wrong here?

Thanks for the assistance!

hex_edited is the text layer (initally written as ff0000):

"0x" + thisComp.layer("hex_edited").text.sourceText;


Colour Control Expression:

hexColor = thisComp.layer("hex_edited").text.sourceText;
r = (hexColor >> 16)/255;
g = ((hexColor & 0x00ff00) >> 8)/255;
b = (hexColor & 0xff)/255;
hsl = rgbToHsl([r,g,b,1]);


Return to posts index


Dan Ebberts
Re: Hex Code from text?
on Sep 18, 2017 at 12:59:49 pm

Try this:

txt = thisComp.layer("Text").text.sourceText;
c = parseInt(txt,16);
r = c >> 16;
g = (c & 0x00ff00) >> 8;
b = c & 0xff;
[r,g,b,255]/255


Dan



Return to posts index

Chris Street
Re: Hex Code from text?
on Sep 18, 2017 at 1:03:53 pm

That's absolutely fantastic, works perfectly! Thank you so much :D


Return to posts index

Scott McGee
Re: Hex Code from text?
on Sep 26, 2017 at 10:25:53 am

Bizzarely, as I didn't test it and now need to use this...I got a luminous green as well, but with Dan's new expression I got pink.

txt = 0x0000ff;
r = txt >> 16;
g = (txt & 0x00ff00) >> 8;
b = txt & 0xff;
[r,g,b,255]/255

This strangely works for me.

Dan if you have a minute, is there a reason why the three expressions (Similar) although people have responded that they work, it reacts differently for others...I am scratching my head here.

I only took a stab in the dark by removing the c and just replacing it all with txt and it worked first time.

Bizarre.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]