ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Triggering random expression with another layer's property

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ben Robinson
Triggering random expression with another layer's property
on Jan 30, 2017 at 9:37:07 pm
Last Edited By Ben Robinson on Jan 30, 2017 at 9:49:50 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.

Return to posts index

Dan Ebberts
Re: Triggering random expression with another layer's property
on Jan 30, 2017 at 10:10:24 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);
// do random stuff

for sequencing, it would be like this:

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


Return to posts index

Ben Robinson
Re: Triggering random expression with another layer's property
on Jan 30, 2017 at 11:07:11 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);

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.



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved