ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Randomly turn on and leave on multiple shape layers using opacity

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kenny Ringgold
Randomly turn on and leave on multiple shape layers using opacity
on Apr 28, 2020 at 2:07:08 am

I've got a comp with a bunch of shape layers, and I want them to turn on randomly by going from 0 to 100 opacity and then once on, stay on. The top shape layer fill is keyframed to accomplish this, and I tried to have the subsequent (lower layers) turn on randomly using an offset expression (connected to a slider to control the amount). This has gotten me part of the way there, I just can't figure out how to randomize the offset and keep the layer on once it's on....

offset = thiscomp.layer("ADJUSTMENTS").effect("Opacity Offset")("Slider")
thisComp.layer(index-1).content("Fill 1").opacity.valueAtTime(time - offset)



I also tried this:

r=random(100)
if (r<=99) {0} else {100}

Which turns layers on randomly but again I can't keep them on and I also can't control the offset.

Can anyone educate me on where I'm going wrong?
Thanks in advance for any help.

Kenny


Return to posts index

Dan Ebberts
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 28, 2020 at 6:43:23 am

Try this for each shape's opacity transform:

maxDelay = 5; // turn all shapes on within 5 seconds
seedRandom(index,true);
myDelay = random(maxDelay);
time - inPoint < myDelay ? 0 : 100


Dan



Return to posts index

Kenny Ringgold
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 28, 2020 at 12:21:22 pm

Thanks Dan,
I actually used this and then added some code I located in one of your earlier posts that allowed me to set the duration of the fade and the offset using sliders in a Null adjustment layer. Thanks for both instances of help!
Kenny


Return to posts index


Kenny Ringgold
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 29, 2020 at 12:21:30 am

One more quick inquiry if I may, Dan...
What would be the easiest way to control length of time from the composition starts till the layers start randomly turning on?

Kenny


Return to posts index

Dan Ebberts
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 29, 2020 at 12:26:14 am

You could add a minDelay variable, like this:

minDelay = 3; // shapes wait at least 3 seconds to turn on
maxDelay = 5; // all shapes turn on within 5 seconds
seedRandom(index,true);
myDelay = random(minDelay,maxDelay);
time - inPoint < myDelay ? 0 : 100

then adjust the first two lines to suit.


Dan



Return to posts index

Kenny Ringgold
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 29, 2020 at 2:37:56 am

Thanks Dan!


Return to posts index


Andrei Popa
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 28, 2020 at 6:54:59 am

Add a slider to your first layer. This will save the times in which the layers appear. Add the following expression. You can modify at which key to start by changing the parameter in the key(2) : sTime = thisLayer.opacity.key(2).time;. numLayers is the number of child layers you have(exclude your main). maxDur is the maximum duration of the delay in seconds.


function getRandomTimes(sTime, numLayers, maxDur){
var crtTime = sTime;
var values = [sTime];
for(var i=1; i <=numLayers;i++){
seedRandom(1,true);
crtTime+=random(maxDur);
values.push(crtTime);
}
return values;
}

sTime = thisLayer.opacity.key(2).time;
numLayers = 7;
maxDur = 1;
var times = getRandomTimes(sTime, numLayers, maxDur);
val = 0;
i=0;
while (time>=times[i]){
val=i+1;
i++;
}
val


Then, to the following layers add this to opacity. firstLayerIndex is the index of your main layer in the current composition.

firstLayerIndex = 2;
index-firstLayerIndex <= thisComp.layer("Shape Layer 1").effect("Slider Control")("Slider") ? 100 : 0;


Andrei
My Envato portfolio.


Return to posts index

Andrei Popa
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 28, 2020 at 6:56:31 am

Didn't see Dan answered.
His solution makes them appear in random order. Mine keeps the order of the layers.

Andrei
My Envato portfolio.


Return to posts index

Kenny Ringgold
Re: Randomly turn on and leave on multiple shape layers using opacity
on Apr 28, 2020 at 12:24:23 pm

Andrei,
Thanks for your response...your expression doesn't do exactly what I needed, but it is a big help with generating random numbers for other related things I'm working on as well. I'm grateful for the knowledge!
Kenny


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]