Create a Countdown Timer with Expressions | After Effects CC Tutorial

Countdown Timer with Expressions After Effects CC Tutorial

CREATE A FEW SIMPLE COUNTDOWN TIMERS IN AFTER EFFECTS EASILY! | Learn to write the expressions that you need to build a very simple or very complex timer in After Effects.

In this After Effects tutorial, we’ll dive into using a single text field and create a couple of VERY simple timers to kick things off and then we’ll write a bit more complex code to create a much more realistic and functional countdown timer that you have complete control over. You can choose the duration of the countdown and simply set it and forget it! Build the code once and have a countdown menu that you can use for any project anywhere.

Tags: after effects, after effects tutorial, after effect CC, after effects tutorials, after effects timer, after effect countdown timer, after effects expressions, how to, how to expressions, after effects timer expressions, after effects countdown code, after effects countdown tutorial, after effects countdown clock, after effects countdown timer tutorial, after effects timer countdown, after effects timer tutorial, after effects timer expression, tutvid, nathaniel dodson, AE

Tutorial Recording Notes:

Disclaimer: these are the actual notes I used to record this video and are written in a language you may or may not understand. Hopefully, you find them useful or cool.

Finished Code:

rateOfSpeed=1;
clockStartTime = thisComp.layer(“slider”).effect(“Slider Control”)(“Slider”)*60;

clockTimeNumber = Math.floor(clockStartTime – rateOfSpeed*time);

function addZero(n) {
if (n<10) return “0” + n else return n;
}

minutes = Math.floor(clockTimeNumber/60);
seconds = clockTimeNumber%60;

if (clockStartTime > 0 && time < clockStartTime) {
addZero(minutes) + “:” + addZero(seconds);
} else {“00:00”}

1. Basic counting upward timer:

  1. Add text layer w/ any text in it (Font:Rail, Ultra Light, 350px, #00CFFF)
  2. Align to the center of the comp
  3. Find Source Text and Alt + Click to open for expression editing
  4. Type in “Math.floor(time);”
  5. Explain what this does

2. Basic counting down timer:

  1. Change expression to:
  2. “Math.floor(60 – time);”
  3. Explain what is happening
  4. Show the problem if we go past 60 seconds

3. Advanced countdown timer:

  1. Clear out the expressions we just made. The goal is going to be to create a timer that the user can input a number to and have it count down from that.
  2. Create a new null object and drag a slider onto it.
  3. Now we’ll first set a rate of speed for our timer. In this case we want it to drop 1 second at a time.
  4. Enter “rateOfSpeed=1;”
  5. Then create the starting time that will be controlled by the slider.
  6. Enter “clockStartTime=PICK WHIP TO THE SLIDER”
  7. Now the number displayed will be equal to whatever we input to the slider.
  8. Next let’s get After Effects to spit the continuously changing countdown number back at us. Here’s how we do that:
  9. Enter “clockTimeNumber = rateOfSpeed*time;”
  10. This returns a crazy string of numbers. Let’s simplify:
  11. Change “clockTimeNumber = Math.floor(rateOfSpeed*time);”
  12. Number looks better. Show how the rateOfSpeed can speed up the number output.
  13. We now need to link this to the slider number that is taken in by the clockStartingTime var
  14. Change “clockTimeNumber = Math.floor(clockStartTime – rateOfSpeed*time);”
  15. This essentially multiplies our rateOfSpeed variable of 1 by the time (frame number at which the playhead is) and then subtracts that by the clockStartTime variable.
  16. If our slider is set to 5, we will see a timer that starts at 5 and each second subtracts 1 from it. This is okay, but after 5 seconds we hit negative numbers and we still don’t have much control here.
  17. If I want a five minute timer I need 300 seconds (60*5=300) so let’s set our slider to 300 and check out the timer now.
  18. But making other people have to go all this seconds math isn’t good, so let’s make this easier. We can add “*60” to the end of the var that targets the number coming out of the slider.
  19. This multiplies that number by 60. This is bad for 300, but if we want a 5 minute timer, simply change the slider to 5 and you get five minutes.
  20. Now we need to transform the formatting of the timer. We need minutes and seconds.
  21. Enter “clockTimeNumber/60” and explain what this is and show what’s happening (including all the crazy decimals)
  22. Next, let’s create a var to hold the number for our minutes Enter: “minutes = Math.floor(clockTimeNumber/60);”
  23. Explain what I just did.
  24. Create another var on the line beneath that for the seconds Enter: “seconds = clockTimeNumber%60”
  25. Enter “minutes + “:” + seconds;”
  26. This will fill out type field with this text that the expressions are outputting
  27. Break this down and show what the divide by 60 does to minutes and what the modulus (%) does for our number as well.
  28. Let’s add some zeroes to our formatting to fix this strange looking thing that’s going on.
  29. We need to create a function to fix our little issue
  30. Enter “function addZero(n) {
    1. if (n<10) return “0” + n else return n;
  31. }” and explain what’s going on here.
  32. Replace “minutes + “:” + seconds;” with “addZero(minutes) + “:” + addZero(seconds);”
  33. Now we have to limit the slider to prevent the problem that arises when somebody tries to set a negative number.
  34. Create the ‘if’ statement “if (clockStartTime > 0) { }
  35. Paste the “addZero(minutes) + “:” + addZero(seconds);” within the ‘if’ statement.
  36. Explain what’s happening and run a quick test.
  37. Add “else {}”
  38. Fill “”00:00″” into that else statement and explain what I did placing that string of text.
  39. Test the slider by pushing it to -100.
  40. Nice!
  41. Now drag the playhead all the way until the end and see the negative numbers.
  42. Fix this by adding a logical operator to the ‘if’ statement alongside the “clockStartTime > 0” by adding “&&” (and) into those parentheses and make sure it looks like this:
  43. if (clockStartTime > 0 && time < clockStartTime) { }
  44. Explain what’s happening here.

Leave a Reply

Your email address will not be published.