ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Peak value calculation

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Vince Babbra
Peak value calculation
on Jan 25, 2018 at 6:16:02 pm

Simplifying my last post...

Let's say I have a 2 second composition with a layer that has bunch of keyframes on a property, say it's y position.

I can use the below expression to return me the highest value of all the keyframes in the layer:

How can I adapt it so that it returns the highest value of the keyframes in that layer... but only up till that point in time?

thx

a = thisComp.layer("Layer1").transform.yPosition;
max = 0;
for(i = 1;i&lt;=a.numKeys;i++){
max = Math.max(max, a.key(i).value);
}
max


Return to posts index

Andrei Popa
Re: Peak value calculation
on Jan 25, 2018 at 10:15:22 pm

This should work.
a =thisComp.layer("Shape Layer 1").transform.yPosition
max = 0;
for(i = 1;i<=a.numKeys;i++){
if (a.key(i).time <= time) max = Math.max(max, a.key(i).value);
}
max


Andrei
My Envato portfolio.


Return to posts index

Dan Ebberts
Re: Peak value calculation
on Jan 25, 2018 at 10:20:26 pm

I'd try it this way:


a = thisComp.layer("Layer1").transform.yPosition;
max = a.value;
for (i = 1; i <= a.numKeys; i++){
if (time < a.key(i).time) break;
max = Math.max(max,a.key(i).value);
}
max



Dan



Return to posts index


Vince Babbra
Re: Peak value calculation
on Jan 25, 2018 at 10:33:57 pm

This works perfect guys... thank you so much... One final question, if I wanted the inverse, I wanted it to output the MINIMUM value instead, what would I need to change!?

Thx so much!


Return to posts index

Andrei Popa
Re: Peak value calculation
on Jan 25, 2018 at 10:44:20 pm

You should use Math.min instead of Math.max

Andrei
My Envato portfolio.


Return to posts index

Vince Babbra
Re: Peak value calculation
on Jan 25, 2018 at 10:48:19 pm

Hmm, using Math.min instead of Math.max does not work? It just returns a single value...


Return to posts index


Andrei Popa
Re: Peak value calculation
on Jan 25, 2018 at 11:24:44 pm

Maybe the first value is tha absolute minimum... I have just tried it and it work on my side.

Andrei
My Envato portfolio.


Return to posts index

Vince Babbra
Re: Peak value calculation
on Jan 25, 2018 at 11:45:23 pm

This is very strange. Please see here, what am I doing wrong?

https://www.dropbox.com/s/xcso312gkk2i6o0/Math%20Min%20Problem.mp4?dl=0

Thanks in advance!


Return to posts index

Andrei Popa
Re: Peak value calculation
on Jan 26, 2018 at 8:32:56 am

You will have to excuse my delay, i had to go to sleep and just got to the office right now. I have tested it with Dan's expression and worked. The difference is that in my expression, i initiate the min with 0, which stays the minimum for all the duration. That is why it didn't work. The big difference between Dan's expression and mine is that his shows the value as it changes, while mine just snaps when getting to the keyframe. I recommend you try both. So for mine to work just change min initialization and use Math.mina =thisComp.layer("Shape Layer 1").transform.opacity
max = a.key(1).value;
for(i = 1;i<=a.numKeys;i++){
if (a.key(i).time <= time) max = Math.max(max, a.key(i).value);
}
max


Andrei
My Envato portfolio.


Return to posts index


Vince Babbra
Re: Peak value calculation
on Jan 26, 2018 at 2:19:58 pm

This works! Thanks so much to both of you. Incredible!


Return to posts index

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