
1. Re: Increment a Variable over time
Rick Gerard Sep 22, 2015 8:09 AM (in response to SlimMarten)Expressions cannot store a value for every frame but you can set up a relationship between values so that something like a value from 1 to 10 will give you a value say between 10 and 100. You do that with these functions:
Let's take linear(t, tmin, max, value1, value2)
If you set t = time and then write:
linear(t, 1, 10, 1, 100)
now at 1, you get 1, at 2 you get 12, at 3 you get 23 and so on until you reach 10 where you get 100.
If you were to write an expression that went back and counted each frame then added the values retrieved from each frame you would end up with recursive math and the expression would slow rendering down exponentially. These interpolation functions work much faster. You can tie them to markers or in and out points so that you can do things like fly a layer in and bounce it to a stop then drop the layer off the screen with an expression like this: (note: there are sliders and check boxes added to the layer to control the animation.
sif = effect("slideIn Frames")("Slider");
sof= effect("slideOut Frames")("Slider");
// find in and out point
inTime = sif * thisComp.frameDuration;
if (effect("Match SI SO")("Checkbox") == 0) {
outTime = sof * thisComp.frameDuration;
}
else if (effect("Match SI SO")("Checkbox") == 1) {
outTime = inTime;
}
// Fix layer size when scaled
sf = scale  [100, 100];
xSize = width + (width * sf[0]/100);
ySize = height + (height * sf[1]/100);
realSize = [xSize, ySize];
// Set Positions
spx = 0  realSize[0] + realSize[0]/2 ;
rstx = value [0];
rsty = value[1];
epy = thisComp.height + realSize[1]  realSize[1]/2;
// create movement
freq = effect("bounce Frequency")("Slider");
amplitude = effect("bounce Amplitude")("Slider");
decay = effect("bounce Decay")("Slider");
posCos = Math.abs(Math.cos(freq*time*2*Math.PI));
y = amplitude*posCos/Math.exp(decay*time);
moveIn = Math.min(linear(time,inPoint,inPoint + inTime,spx ,rstxy));
moveOut = Math.min(linear(time,outPoint  outTime,outPoint  thisComp.frameDuration,rsty ,epy));
[moveIn, moveOut]

2. Re: Increment a Variable over time
Rick Gerard Sep 22, 2015 9:06 AM (in response to Rick Gerard)I should mention a couple of other things to try. Instead of adding you could try a multiplier. This would accelerate your effect without running into the recursive problem.
The other thing to consider is that if you use timeToFrames(time) and use the frame numbers to control motion you will kill motion blur in CC 2014 or earlier. It just won't work. Instead will need to use
myTime = time/thisComp.frameDuration;