Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Triggering random expression with another layer’s property

  • Triggering random expression with another layer’s property

    Posted by Ben Robinson on January 30, 2017 at 9:37 pm

    I posted a few days ago looking for a way to loop an opacity fade up / stay on / fade down, with fade / stay on times linked to sliders. I actually managed to make that one work myself, starting with another expression from, of all things, a built in preset. What I ended up with was this:

    ctrl = comp("MAIN COMP").layer("TIMING CONTROLS");
    fadeTime = framesToTime(ctrl.effect("Fade In/Out Time (Frames)")("Slider"));
    onTime = framesToTime(ctrl.effect("On Time (Frames)")("Slider"));
    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

    It works just as I want it to. What I also need to do though–and I replied to my own post in the hopes of finding an answer, but might have overcomplicated things–is trigger two other “events” based on the opacity working on the above expression. I want freeze frames of a precomp to change to another random frame every time the opacity hits zero, so that when it fades back up it will show a different frame. Similarly, I’d like a colour control adjustment layer within the pre comp to cycle randomly though a set of six RGB values, so that each subsequent freeze frame is a different, random colour. I’ve come very close to making it all work, but just can’t quite see my way through it.

    Ben Robinson replied 9 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 30, 2017 at 10:10 pm

    I think the key is that opacity hits zero at the end of each fadeTime. So for random stuff to change at that time, you need to do something like:

    n = Math.floor(time/fadeDur);
    seedRandom(n,true);
    // do random stuff

    for sequencing, it would be like this:

    seqLen = 6;
    n = Math.floor(time/fadeDur)%seqLen;
    // use n as the sequence index

    Dan

  • Ben Robinson

    January 30, 2017 at 11:07 pm

    Thanks Dan. That works perfectly. So, it turns out, did another method I’d already arrived at–possibly even from one of your own, after much reading / experimenting…

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

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

    Even though it wasn’t directly linked to the opacity it was linked to the same duration-setting sliders. For some reason, though, it wasn’t working for a couple of days. Not sure if I’d mistyped / mis-linked something or what–but the opacity and frame change just didn’t marry up. I like your method with the direct link to the opacity though. Seems like it will give more consistency.

    Thanks

    Ben

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