Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions fade-in/out color based on input values

Tagged: 

  • fade-in/out color based on input values

    Posted by Marshall Eide on February 17, 2022 at 2:22 pm

    Hi there! I have two instances of a text layer’s Tint Effect being colored based on user-input values. So there’s ‘fade’ in/out of the color blue. Everything works except for the 2nd round of variables appended with a ‘2’

    var cti = timeToFrames();
    var tli = thisComp.layer("Controller").effect("TarLight 1 on")("Slider")
    var tlo = thisComp.layer("Controller").effect("TarLight 1 off")("Slider")
    var tli2 = thisComp.layer("Controller").effect("TarLight 2 on")("Slider")
    var tlo2 = thisComp.layer("Controller").effect("TarLight 2 off")("Slider")
    var frames = 1 / thisComp.frameDuration;
    var fadeTime = thisComp.layer(1).effect("Fade Time")("Slider") / frames;
    var st = tli / frames;
    var et = tlo / frames;
    var st2 = tli2 /frames;
    var et2 = tlo2 /frames;
    gray = [99, 102, 106, 255]/255
    blue = [3, 169, 244, 255]/255
    if ((cti >= tli && cti <= tlo) || (cti >= tli2 && cti <= tlo2))
    	{blue}
    	else if (cti < tli)
    	{
    	ease(time, st, st - fadeTime, gray, blue)
    		}
    	else if (cti > tlo)
    	{
    	ease(time, et, et + fadeTime, blue, gray)
    		}
    	else if (cti < tli2)
    	{
    	ease(time, st2, st2 - fadeTime, gray, blue)
    		}
    	else if (cti > tlo2)
    	{
    	ease(time, et2, et2 + fadeTime, blue, gray)
    		}
    else
    {gray}

    the 2nd round of ‘else if’s’ don’t do the fade and I’m wondering if there’s a better way to order this or if I’m out of luck.

    Marshall Eide replied 4 years, 2 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    February 17, 2022 at 6:45 pm

    You need to structure your if tests so that they’re in chronological order, otherwise, (in this case) you’ll never get past this one:

    else if (cti > tlo)

    I haven’t tested this, but you should be able to replace all your if/else stuff with something close to this:

    if (cti < tl0)

    ease(time, st, st - fadeTime, gray, blue)

    else if (cti < tlo + fadeTime)

    ease(time, et, et + fadeTime, blue, gray)

    else if (cti < tl02)

    ease(time, st2 - fadeTime, st2, gray, blue)

    else{

    ease(time, et2, et2 + fadeTime, blue, gray);

  • Marshall Eide

    February 18, 2022 at 1:17 am

    Hi Dan!
    Thanks for your help here and on the many posts you’ve answered! I’ve learned a lot from you already. However, this doesn’t seem to work either. I think I didn’t explain the end goal of the expression so well. The blue fade comes on, holds, and fades out, then based on another separate set of values comes on again, holds and fades out.

    I took your advice in putting things in chronological order and it’s helped me with other expressions, but this one I’m starting to think can’t work because the ‘cti’ (frame number) is being tested by four different variables. They both work when split apart. I was thinking if “st” (start time) and “et” (end time) variables could be switched in the

    ease(time, var, var +/- fadeTime, color, color)

    array it might reduce the if statements. I’m not that advanced yet, but I’m keen to learn.

  • Dan Ebberts

    February 18, 2022 at 3:33 am

    There were a few typos in there, but I think this does what you descibe:

    var cti = timeToFrames();

    var tli = thisComp.layer("Controller").effect("TarLight 1 on")("Slider")

    var tlo = thisComp.layer("Controller").effect("TarLight 1 off")("Slider")

    var tli2 = thisComp.layer("Controller").effect("TarLight 2 on")("Slider")

    var tlo2 = thisComp.layer("Controller").effect("TarLight 2 off")("Slider")

    var frames = 1 / thisComp.frameDuration;

    var fadeFrames = thisComp.layer(1).effect("Fade Time")("Slider");

    var fadeTime =fadeFrames / frames;

    var st = tli / frames;

    var et = tlo / frames;

    var st2 = tli2 /frames;

    var et2 = tlo2 /frames;

    gray = [99, 102, 106, 255]/255

    blue = [3, 169, 244, 255]/255

    if (cti < tlo)

    ease(time, st, st - fadeTime, gray, blue)

    else if (cti < tlo + fadeFrames)

    ease(time, et, et + fadeTime, blue, gray)

    else if (cti < tlo2)

    ease(time, st2 - fadeTime, st2, gray, blue)

    else

    ease(time, et2, et2 + fadeTime, blue, gray);

  • Marshall Eide

    February 20, 2022 at 11:48 pm

    Thank you Dan! This seems to work flawlessly. This makes everything so clear! I think my big mistake was relying on the if statements to determine the time things should turn on. When it’s already dictated in the ‘ease()’. All the ‘if’ needs to do is return a true statement chronologically.

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