Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Convert color from hsl to hex after applied expression and then return the value to the source text

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

    Posted by Michał Jawiński on April 19, 2019 at 8:18 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?

    Michał Jawiński replied 7 years, 4 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    April 19, 2019 at 8:35 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

  • Michał Jawiński

    April 19, 2019 at 9:20 pm

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

  • Dan Ebberts

    April 19, 2019 at 9:27 pm

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

    r+g+b

    Dan

  • Michał Jawiński

    April 19, 2019 at 9:34 pm

    Hmmm actually It’s not, sorry.

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

  • Michał Jawiński

    April 19, 2019 at 9:37 pm

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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy