Activity › Forums › Adobe After Effects Expressions › Random Shuffle Layer Opacity
-
Random Shuffle Layer Opacity
Posted by Max Jackson on August 10, 2010 at 6:00 amHi CC,
I’m trying to randomly shuffle the opacity of 4 layers as the timeline plays. That is to say on is 100% while the rest are 0% so it looks like the timeline is shuffling through the layers.
I’m used to Flash and even though ActionScript is ECMA, the interface structure is waaay different in After Effects. There’s not an “actions” layer. So I was wondering what an ideal way to attach values to objects in this set-up would be if writing such a script.
Thanks for any feedback.
Max Jackson replied 15 years, 9 months ago 2 Members · 4 Replies -
4 Replies
-
Dan Ebberts
August 10, 2010 at 3:12 pmWith After Effects, the issue is that an expression can’t directly control anything except the property to which it is applied. One thing you can do though is apply a slider control to one of the layers (let’s say the first one) and apply an expression to that which “publishes” the index of the layer that should currently be visible. The espression might look like this:
holdTime = .5;
n = 4;
segment = Math.floor(time/holdTime);
seedRandom(segment,true);
Math.floor(random(n)) + 1;This provides a random number from 1 to 4 that gets recalculated every half second. It gets more complicated if you need to make sure the same number doesn’t repeat twice in a row or if you want the hold times to vary.
Then you would apply an expression like this to each layer’s opacity property:
idx = thisComp.layer(1).effect(“Slider Control”)(“Slider”);
if (idx == index) 100 else 0Dan
-
Max Jackson
August 11, 2010 at 3:48 amI think I might be getting ahead of myself. I think the real issue I have is migrating from object-oriented programming.
Coding aside, is there a good philosophy to use when approaching expressions? I feel like I’m using a remote to a TV that’s not plugged in. I don’t really get the structure.
Sorry if this sounds really dense. For this what should I do overall? Based on what I’m allowed, what would be my plan of action? I get lost in the slider “publishing” things. I understand that the slider is a means to supply an access-to range of values, but so I’m giving my layer the ability to alpha by dragging a slider…Got that. Then creating a boolean-like condition to control the layer it’s coded in.
In terms of layer structure I’m lost though. Sorry if that’s vague. I just see myself putting code and sliders in each layer and since I can’t attach code to an object I don’t know how to wire it up?
What am I missing? Should I designate one layer to be like some parent master layer of some kind?
-
Dan Ebberts
August 11, 2010 at 6:12 amThere are really a couple of things going on here. One is that any property that you want to control with an expression has to actually have its own expression. So you’ve got four layers, each with an opacity property you want to control — that’s four expressions right there. The good news is that in this case they can all be identical expressions.
The other thing is that you want (I think) to coordinate the randomness of the opacity expressions such that only one layer is visible at a time. That requires special handling because the random number generator would generate a different sequence in each opacity expression, so you need (in this special case) to have only one expression generating random numbers. That’s where the slider comes in. The slider is just a place to house the expression that will determine which layer should currently be visible. Each opacity expression references the output of the slider expression to determine if the opacity of that layer should be on or off.
So, to sum it up, you need five expressions. You have actually bitten off a bigger chunk than usual for your first expression.
Dan
-
Max Jackson
August 12, 2010 at 4:07 amOkay, I think I’m starting to get the picture better now.
I have to think of layers as being much more independent. Each layer must have code inside it to control it directly. I can’t cross-assign information, so in all, get used to redundancy.
I think also overall I’ve bitten off more than I can chew. I tried writing out my thoughts like I would in Actionscript in an AE environment and the smoke detector went off.
I’m guessing a good starting place would be to do some exercises using the slider with multiple layers and time.
Thanks for the assistance and direction Dan, it’s appreciated.
Reply to this Discussion! Login or Sign Up