Activity › Forums › Adobe After Effects Expressions › Peak value calculation
-
Peak value calculation
Posted by Vince Babbra on January 25, 2018 at 6:16 pmSimplifying 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<=a.numKeys;i++){
max = Math.max(max, a.key(i).value);
}
maxVince Babbra replied 8 years, 7 months ago 3 Members · 9 Replies -
9 Replies
-
Andrei Popa
January 25, 2018 at 10:15 pmThis 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);
}
maxAndrei
My Envato portfolio. -
Dan Ebberts
January 25, 2018 at 10:20 pmI’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
-
Vince Babbra
January 25, 2018 at 10:33 pmThis 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!
-
Andrei Popa
January 25, 2018 at 10:44 pm -
Vince Babbra
January 25, 2018 at 10:48 pmHmm, using Math.min instead of Math.max does not work? It just returns a single value…
-
Andrei Popa
January 25, 2018 at 11:24 pmMaybe the first value is tha absolute minimum… I have just tried it and it work on my side.
Andrei
My Envato portfolio. -
Vince Babbra
January 25, 2018 at 11:45 pmThis 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!
-
Andrei Popa
January 26, 2018 at 8:32 amYou 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.min
a =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);
}
maxAndrei
My Envato portfolio.
Reply to this Discussion! Login or Sign Up