Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Looping opacity with set fade up/down and “stay on” durations

  • Looping opacity with set fade up/down and “stay on” durations

    Posted by Ben Robinson on January 26, 2017 at 11:18 pm

    I’ve been scouring this site (and others) for over an hour now trying to find a way to fade a layer up over a set time, stay on for a set time, then fade down over the same fade up time, then loop. I can get the fade up, stay on, fade down bit–but falling down at adding the loop. I’ve found several examples that are close–but I can’t decipher the code sufficiently to apply it to my needs; and the more I stare at the expression field in AE the less capable I’m becoming…

    Any help much appreciated.

    fadeTime = effect("Fade In/Out")("Slider")/25;
    onTime = effect("On Time")("Slider")/25;
    fadeDur = fadeTime*2+onTime;
    fadeInOpacity = linear(time, inPoint, inPoint+fadeTime, 0, 100);
    fadeOutOpacity = linear(time, fadeTime+onTime, fadeDur, 100, 0);
    (fadeInOpacity * fadeOutOpacity) / 100

    Actually worked this out before my post even went live. Added a modulus to the above code to get

    fadeTime = effect(“Fade In/Out”)(“Slider”)/25;
    onTime = effect(“On Time”)(“Slider”)/25;
    fadeDur = fadeTime*2+onTime;
    t = time%fadeDur;
    fadeInOpacity = linear(t, inPoint, inPoint+fadeTime, 0, 100);
    fadeOutOpacity = linear(t, fadeTime+onTime, fadeDur, 100, 0);
    (fadeInOpacity * fadeOutOpacity) / 100

    I guess searching / staring at all the different examples somehow got something though…

    Ben Robinson replied 9 years, 3 months ago 1 Member · 1 Reply
  • 1 Reply
  • Ben Robinson

    January 27, 2017 at 12:48 pm

    Ok, so it turns out I hadn’t solved my own problem after all–mainly because it’s not just the opacity expression I need; I also need to time remap a random freeze frame and a random colour change (from a set palette) at the same time as the fade up / fade down–basically a new frame / colour every time opacity reaches zero. On top of that, a second layer also needs to randomly change colour over the same period as fade up / fade down.

    I’ve confused myself with all of that–and it’s my project! Maybe an actual description will help…

    I have a set of icons (currently 38, but could increase), all 1 frame in length, in a 38 frame precomp. Around that precomp is a border. I want to randomly select a frame from the icon precomp and hold on it for a set amount of time (ideally set by a slider in a master comp) and have it fade out over a set time (again on a slider) then change frame and colour (via a Tint / Fill effect) then fade up again (same as fade out time). Meanwhile the border will, as the icon fades out / in, change from one random colour to another (without fading in / out).

    I have some of this working–but can’t get the timing of each change to coincide, even though the timings are all supposedly linked to the same master sliders…

    Current fade in/out code (this seems to work as I want it to):

    fadeTime = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("Fade In/Out Time (Frames)")("Slider"));
    seedRandom(comp("MAIN COMP").layer("TIMING CONTROLS").effect("Random Seed")("Slider"), true);
    onTime = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("On Time (Frames)")("Slider"))*random(1,2);
    fadeDur = fadeTime*2+onTime;
    t = time%fadeDur;
    fadeInOpacity = linear(t, inPoint, inPoint+fadeTime, 0, 100);
    fadeOutOpacity = linear(t, fadeTime+onTime, fadeDur, 100, 0);
    (fadeInOpacity * fadeOutOpacity) / 100

    Time remap code (works, but timing is off with above opacity change):

    segDur = comp("MAIN COMP").layer("TIMING CONTROLS").effect("On Time (Frames)")("Slider")/25+comp("MAIN COMP").layer("TIMING CONTROLS").effect("Fade In/Out Time (Frames)")("Slider")/25;
    minVal = inPoint;
    maxVal = framesToTime(37);

    seed = Math.floor(time/segDur);
    seedRandom(seed,true);
    random(minVal,maxVal);

    Colour change (this, again, works, but timing doesn't match--works well as transition for border, but not for icon colour change):

    colors = [[49,32,28,255]/255,
    [0,175,170,255]/255,
    [221,0,49,255]/255,
    [172,0,51,255]/255,
    [255,108,27,255]/255,
    [220,143,27,255]/255];
    easeTime = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("Fade In/Out Time (Frames)")("Slider"));
    segDur = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("On Time (Frames)")("Slider"))*2;

    curSeg = Math.floor(time/segDur);
    t = time%segDur;
    seedRandom(curSeg,true);
    idx1 = Math.floor(random(colors.length));
    seedRandom(curSeg-1,true);
    idx0 = Math.floor(random(colors.length));
    ease(t,0,easeTime,colors[idx0],colors[idx1])

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