I’m not sure what you’re after exactly, but this example would drive the Trim Paths End value from 100 to 0 as the seconds count down. Probably some form of this would do what you want:
t = thisComp.layer(“time”).text.sourceText.value;
sec = parseInt(t.split(” “)[3],10);
linear(sec,0,60,0,100)
You certainly could modify the expression to find the extents in the vertical directions as well, but this technique is so inefficient that I’m having trouble imagining why anyone would want to do that now that sourceRectAtTime() is available. The expression is slow because it starts at the left edge of the comp and samples a one-pixel-wide by comp-height rectangle at every pixel location from left to right until it finds one with non-zero alpha. Then it does the same thing starting from the right edge, moving left. That eats up a lot of horsepower. sourceRectAtTime() is so much better.
freq = 0.5;
decay = 1;
val = value
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 1){
w = freq*Math.PI*2;
for (i = 2; i <= n; i++){
t = time - key(i).time;
if (t > 10/decay) continue;
amp = velocityAtTime(key(i).time - .001);
val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}
}
val
freq = 0.5;
decay = 1;
val = value
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 1){
amp = velocityAtTime(key(n).time - .001);
w = freq*Math.PI*2;
for (i = 2; i <= n; i++){
t = Math.min(time - key(i).time,10/decay);
amp = velocityAtTime(key(i).time - .001);
val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}
}
val
The trick is that your code has to count how many events have occurred prior to the current time. If you’re monitoring a value, you can use the brute-force technique described here: