ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Updating Expressions over time

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Laurie Gibbs
Updating Expressions over time
on Jan 17, 2020 at 11:16:16 pm

Hi,

Thanks in advance to anyone who takes the time to go down this rabbit hole, I would be really grateful to anyone who can help me get this working.

I've written an expression to calculate the average rate that layers switch on (become active):

//////time that each layer becomes active (in frames 50fps)

layer_01 = thisComp.layer("Layer 1").inPoint*50;
layer_02 = thisComp.layer("Layer 2").inPoint*50;
layer_03 = thisComp.layer("Layer 3").inPoint*50;
layer_04 = thisComp.layer("Layer 4").inPoint*50;

//////frame duration of gaps between layers

a = (layer_02 - layer_01);
b = (layer_03 - layer_02);
c = (layer_04 - layer_03);
d = (layer_05 - layer_04);

///////average duration of gaps between layers

(a+b+c+d)/4

This is working as I hoped.
Now, I would like to compare the frame duration of the gap most recent 2 layers with the overall average, like this:

((a+b+c+d)/4)/d

which is also working great and gives me 0.97 (which is a kind of phase relationship between the average gap and the most recent gap).

Now the bit where I'm having trouble is calculating this value over time. As the play head moves through the composition, I want to compare the most recent gap with the overall average.

I'd hoped I'd be able to do this with a couple of arrays and an 'active layer counter' like this:

avArray = [(a+b),(a+b+c),(a+b+c+d)];
gapArray = [a,b,c,d];
layerCount = thisComp.layer("Layer 01").active+thisComp.layer("Layer 02").active+thisComp.layer("Layer 03").active+thisComp.layer("Layer 04").active;

(avArray[layerCount]/layerCount)/gapArray[layerCount]

(I know the expression would have needed a little tweaking as the array's start from [0])

Unfortunately, I got this far only to realise that you don't seem to be able to plug variables in to select from an Array, so my layerCount value was useless.

If anyone has read this far and has some ideas on how to help, it would be hugely appreciated.

Many thanks,

Laurie


Return to posts index

Andrei Popa
Re: Updating Expressions over time
on Jan 18, 2020 at 12:02:37 pm

Im on the phone, so that may get some things wrong but here is the idea:

inPoints[1]=thisComp.layer("Layer 1").inPoint*50;
inPoints[2]=thisComp.layer("Layer 2").inPoint*50;
inPoints[3]=thisComp.layer("Layer 3").inPoint*50;
inPoints[4]=thisComp.layer("Layer 4").inPoint*50;
inPoints[5]=thisComp.layer("Layer 5").inPoint*50;
i=2;
lastGap=0;
sum=0;
while(inPoints[i]<time){
lastGap=inPoints[i]-inPoints[i-1];
sum+=lastGap;
}
(sum/(i-1))/lastGap;


Andrei
My Envato portfolio.


Return to posts index

Laurie Gibbs
Re: Updating Expressions over time
on Jan 18, 2020 at 3:05:12 pm

Hi Andrei,

Thanks for taking a look at this. I was hoping there would be a neater way of doing this that wouldn't require those array setups.

I've tried using the expression you have suggested but, I'm getting an error on line 1:

inPoints[1]=thisComp.layer("Layer 1").inPoint*50;
Error: inPoints is not defined

Please let me know if you can think of a fix for this.

Many thanks,

Laurie


Return to posts index


Andrei Popa
Re: Updating Expressions over time
on Jan 19, 2020 at 2:05:36 am

This would be the first expression fixed:

inPoints=[]
inPoints[1]=thisComp.layer("Layer 1").inPoint;
inPoints[2]=thisComp.layer("Layer 2").inPoint;
inPoints[3]=thisComp.layer("Layer 3").inPoint;
inPoints[4]=thisComp.layer("Layer 4").inPoint;
inPoints[5]=thisComp.layer("Layer 5").inPoint;
i=2;
lastGap=0;
sum=0;
while(inPoints[i]<time){
lastGap=inPoints[i]-inPoints[i-1];
sum+=lastGap;
}
((sum/(i-1))/lastGap)*50;


And this would be a neat way to do it.
Put all those sequenced layers one after another in the timeline.init must be the index of the first one, layersNumber must be the nuber of the layers. The commented part of row 12 is the average. If you need the average, just take that commented text and replace the one in front.

init=3;//first layer of the sequence
layersNumber = 5 ;//The number of layers for the sequence
i=init+1;
lastGap=1;
sum=0;
while(thisComp.layer(i).inPoint<time && ithisComp.layer(init+1).inPoint){
(sum/(i-init-1)) /lastGap; //(sum/(i-init-1))*50;
}else{
value
}


Andrei
My Envato portfolio.


Return to posts index

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