Jump to content

AE Expressions: a Basic Count-Down and Hold

  • Please log in to reply
No replies to this topic

#1 Guest_graymachine_*

  • Guests

Posted 21 June 2006 - 07:47 PM

This came from a question on another forum. How to have a type layer count from 100 to 0.

Here's the expression:

t = (1 / thisComp.frameDuration) * time ;
count = 100 - t ;

if (count < 0){





If we add this to the "source type" of a layer, this will do a simple countdown from 100 down to 0 for each frame that passes. How? Let's look!


This is equal to the time it takes for one frame to elapse in seconds.


is the current time in seconds. Therefore,

t = (1 / thisComp.frameDuration) * time ;

declares 't' to be equal to the current time in frames, regardless of fps.

Then we say

count = 100 - t ;

So, instead of going 0 - 100, now we have a value going from 100 to 0. There's probably a mathematical term for doing this flip-around, but I don't know what it is.

Now, thinking ahead, if we were making a countdown to zero, we want our countdown to stop at zero. So, we need to do a simple test:

if (count < 0){

If 'count' is less than zero, then pass the value of 0. Therefore we will never see a negative number.


If it is not less than zero.. then do this:


We are handing this value to be our source text. First, let's just say we had "count" here. Our source text would display a 100 - 0 countdown occasionally including a non-integer number like 4.9999999. Why? Because NTSC sucks. Our math is dealing with this multiple of 29.97 which yields some crazy numbers occasionally. If you are using PAL, then you might not even need this. BUT, we should always make our code bullet-proof.

So, instead we need to round our number to the integer closest to and not greater than 'count'. Hence, Math.floor(count).

Make sense?


Edited by graymachine, 21 June 2006 - 07:55 PM.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users