Skip to content

Instantly share code, notes, and snippets.

@animoplex
Created April 28, 2019 04:18
Show Gist options
  • Save animoplex/9cc2a3a0dd5da79b47fdfbd785c72cea to your computer and use it in GitHub Desktop.
Save animoplex/9cc2a3a0dd5da79b47fdfbd785c72cea to your computer and use it in GitHub Desktop.
Play / Pause Realtime Countdown - After Effects Expression by Animoplex
// Play / Pause Realtime Countdown - Created by Animoplex: www.animoplex.com
// Counts down a clock in realtime with the ability to play and pause the countdown with a checkbox
// NOTE: Expression will gradually slow down over duration of comp due to the while loop mechanic
src = effect("Checkbox Control")("Checkbox"); // play/pause control
dur = thisComp.frameDuration; // length of 1 frame
count = 300; // 5 minutes in seconds
t = 0;
function addZero(n) { // adds a zero to the end of numbers 0-9
if (n < 10) {
return "0" + n;
} else {
return n;
}
}
while (t < time) {
count -= src.valueAtTime(t) * dur; // adds value of all previous frames
t += dur;
}
sec = count % 60; // seconds
min = count / 60; // minutes
addZero(Math.floor(min)) + ":" + addZero(Math.floor(sec)) // creates display output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment