Activity › Forums › Adobe After Effects Expressions › Hex Code from text?
-
Hex Code from text?
Posted by Chris Street on September 18, 2017 at 10:34 amHi, 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!
Gray Wilcox replied 5 years ago 4 Members · 7 Replies -
7 Replies
-
Scott Mcgee
September 18, 2017 at 11:38 amDan 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.
-
Chris Street
September 18, 2017 at 12:51 pmHi, 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]); -
Dan Ebberts
September 18, 2017 at 12:59 pmTry 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]/255Dan
-
Chris Street
September 18, 2017 at 1:03 pmThat’s absolutely fantastic, works perfectly! Thank you so much 😀
-
Scott Mcgee
September 26, 2017 at 10:25 amBizzarely, 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]/255This 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.
-
Gray Wilcox
May 1, 2021 at 1:53 amI’m using a .csv in my project (not in my actual comp) and i’m attempting to use Hex code from the .csv to drive my color control expression.
compName = thisComp.name;
hexColor = footage(“players_cards – one_team.csv”).dataValue([37,compName]);
r = (hexColor >> 16)/255;
g = ((hexColor & 0x00ff00) >> 8)/255;
b = (hexColor & 0xff)/255;
hsl = rgbToHsl([r,g,b,1]);the idea being the comp is labeled “0” and when i make duplicates, it will increment up and make new versions of the same player card, with new data from the .csv file.
-
Gray Wilcox
May 1, 2021 at 2:21 amso i fixed my issue:
my .csv had HEX values with a # in front. i removed the #’s leaving only the digits, and everything worked.
Reply to this Discussion! Login or Sign Up