Activity › Forums › Adobe After Effects Expressions › 5 Minute Countdown
-
Dan Ebberts
May 25, 2012 at 1:08 amYou would need a more complex expression. Here’s one that uses a checkbox control on the text layer to drive the count down. The count only proceeds when the checkbox is in the “on” state.
p = effect("Checkbox Control")("Checkbox");
accum = 0;
ct = inPoint;
cv = p.valueAtTime(inPoint);
for (i = 1; i <= p.numKeys; i++){
kt = p.key(i).time;
if (kt <= inPoint) continue;
if (kt >= time) break;
accum += cv*(kt - ct);
cv = p.key(i).value;
ct = kt;
}
accum += cv*(time-ct);rate = -1;
clockStart = 1440;
function padZero(n){
return ((n < 10) ? "0" : "") + n;
}
clockTime = Math.max(clockStart + rate*accum,0);
t = Math.floor(clockTime);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60); min + ":" + padZero(sec) + ":" + Math.floor((clockTime%1)*10)
Dan
-
Chad Keddington
August 28, 2012 at 10:05 pmHi code works great but I am wondering if their is away to get rid of the leading number when they turn to zero.
Chad
-
Dan Ebberts
August 28, 2012 at 10:16 pmI’m not sure which version you’re talking about, but to eliminate leading zeros you would eliminate the call to padZero():
rate = -1;
clockStart = 7200;function padZero(n){
if (n < 10) return “0” + n else return “” + n
}clockTime = Math.max(clockStart + rate*(time – inPoint),0);
t = Math.ceil(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
“” + hr + “:” + min + “:” + padZero(sec)Dan
-
Chad Keddington
August 29, 2012 at 12:46 amHi Dan I am confused. Here is the code I am using. I want I five minute countdown. But when it gets down to just seconds I dont want the zeros to shows.
rate = -1;
clockStart = 300;function padZero(n){
if (n < 10) return “0” + n else return “” + n
}clockTime = Math.max(clockStart + rate*(time – inPoint),0);
t = Math.floor(clockTime);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
min + “:” + padZero(sec)Chad
-
Dan Ebberts
August 29, 2012 at 2:08 amI’m still not sure exactly what you’re after, but try changing the last line to this:
(min > 0 ? min : “”) + “:” + padZero(sec)
and if that’s not it, try this:
min > 0 ? min + “:” + padZero(sec) : sec
Dan
-
Chad Keddington
August 29, 2012 at 4:04 amThat a little closer. What I want it to do is somthing like this count down from 5:00, 5:59,5:58…..4:00…3:00…1:00, 59, 58 …10, 9, 8, 7 … 1, 0
Sorry for all the confusion
Chad -
Dan Ebberts
August 29, 2012 at 4:27 amNow I’m confused. Isn’t that what the second variation from my previous post does?
Dan
-
Chad Keddington
August 29, 2012 at 12:07 pmThe last post does do that except when it gets down to sec the semi colon is still showing. The previous one were I get ride of the call to padZero does count down in sec but does not show the minutes.
Thanks for all the help.
Chad -
Ruben Gomez
June 16, 2015 at 11:14 amHi Dan,
That script was very helpful…. Is there any way in the script that I can start the countdown after couple of seconds….
rate = -1;
clockStart = 300;function padZero(n){
if (n < 10) return "0" + n else return "" + n
}clockTime = Math.max(clockStart + rate*(time - inPoint),0);
t = Math.floor(clockTime);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
min + ":" + padZero(sec)
Reply to this Discussion! Login or Sign Up