2 Replies Latest reply on Sep 22, 2015 9:06 AM by Rick Gerard

    Increment a Variable over time


      I have following problem: I am trying to tweak the speed of a Math.sin function. Therefore I need a variable that incerements over time with a combination of a keyframed speed variable.

      Sounds complicated, I know.

      Let's say I am using the global time variable and convert it with the timeToFrames() function I get an integer value for each frame.

      myTime = timeToFrames(time); 

      This leads me to a value of 1 for Frame 1, a value of 2 for Frame 2, and so on. But what if I want to manipulate the increment. For example:

      //speed (gets tweened from a certain value range,for example: 10 - 1) s = (some connected slider here) myTime += s; 

      If I have a speed of 10 at Frame 1 I would get a value of 11. If I have a speed of 8 at Frame 2, I would expect a value of 11 + 2 + 8 = 21.

      What I get is only 2 + 8;

      So I need to store the value at every frame. Is this possible?

      Please help.

        • 1. Re: Increment a Variable over time
          Rick Gerard Adobe Community Professional & MVP

          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:

          Screen Shot 2015-09-22 at 7.55.29 AM.png

          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  ,rstx-y));

          moveOut = Math.min(linear(time,outPoint - outTime,outPoint - thisComp.frameDuration,rsty ,epy));

          [moveIn, moveOut]

          • 2. Re: Increment a Variable over time
            Rick Gerard Adobe Community Professional & MVP

            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;