ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Convert color from hsl to hex after applied expression and then return the value to the source text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Michał Jawiński
Convert color from hsl to hex after applied expression and then return the value to the source text
on Apr 19, 2019 at 8:18:49 pm

Hello, I'm not so proficient in programming expressions so I'm hoping that you guys could help me with upgrading some code that I found here. I have a shape with a fill. Inside this fill is an expression that brightens the color from another shape.

c = comp("Color Theming").layer("Secondary 2").content("Secondary").content("Fill 1").color

hsl = rgbToHsl(c);

factor = 1.3; // 30% brighten

newL = Math.min(hsl[2]*factor,1);

hslToRgb([hsl[0],hsl[1],newL,hsl[3]])


At the end of this expression I would like to convert hsl to hex and then pass that value to the source text that will be in Color Theming composition. I couldn't find that specific function that converts hsl to hex. I assume that adding that part of expression to the fill and then linking source text to that fill color will do the job. Am I correct?


Return to posts index

Dan Ebberts
Re: Convert color from hsl to hex after applied expression and then return the value to the source text
on Apr 19, 2019 at 8:35:33 pm

So you want the hex for the color that results from the expression, is that correct? If so, you wouldn't need to modify the fill expression, but you'd need to link to the resulting color with something like this in the source text of your text layer:


function pad(s){
return s.length < 2 ? "0"+s : s;
}
c = thisComp.layer("Test").effect("Fill")("Color");
r = pad((c[0]*255).toString(16));
g = pad((c[1]*255).toString(16));
b = pad((c[2]*255).toString(16));
r+b+g



Dan



Return to posts index

Michał Jawiński
Re: Convert color from hsl to hex after applied expression and then return the value to the source text
on Apr 19, 2019 at 9:20:10 pm

Yes ☺ Works like a charm! This is exactly what I was looking for. Thank you Sir!


Return to posts index


Dan Ebberts
Re: Convert color from hsl to hex after applied expression and then return the value to the source text
on Apr 19, 2019 at 9:27:57 pm

Ah, sorry, I did mess up the last line. It should be:

r+g+b


Dan



Return to posts index

Michał Jawiński
Re: Convert color from hsl to hex after applied expression and then return the value to the source text
on Apr 19, 2019 at 9:34:40 pm

Hmmm actually It's not, sorry.



Returned value seems not to be true. Below I'm attaching a screenshot of modified expression



Return to posts index

Michał Jawiński
Re: Convert color from hsl to hex after applied expression and then return the value to the source text
on Apr 19, 2019 at 9:37:02 pm

Ahhhh ok, I've missed that aswell. Now it works properly ☺ Thank you again


Return to posts index

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