-
Full-featured countdown timer
Creative cows has helped me a ton in the past, so I’m contributing my full-featured countdown expression.
Simply use it as the source text for a text layer. All you need to edit is in the first few lines.
//Full Function Countdown Script
//Written by Jason Vore – co*******@*****il.com//Attach as an expression for the source text for a Text Layer.
intMinutesToCountdown = 3; //How many minutes you want to be counted down.
intSecondsToCountdown = 0; //How many additional seconds you want to be counted down.offset = 0; //Number of seconds to hold the countdown timer at full before it starts counting down
boolIncludeMinutes = 1; //1 to include minutes, 0 to exclude
boolIncludeDecimalSeconds = 1; //1 to include decimal parts of seconds, 0 to exclue
intDecimalsToInclude = 2; //Number of decimal points to include
boolAllowNegativeTimes = 0; //1 to allow the countdown to run past 0, 0 to hold the timer at 0 seconds.
boolIncludeLeadingZeroes = 1; //1 to include leading zeroes in front of minutes to keep text in same location//DO NOT EDIT ANYTHING BELOW THIS LINE!
i = inPoint + offset; //the “time” to actually start the countdown
intSecondsToCountdown = intMinutesToCountdown * 60+ intSecondsToCountdown; //calculates total seconds in the countdown
fltSecondsRemaining = intSecondsToCountdown – time + i; //decimal of number of seconds remaining, uses i start the countdown at the inpoint of the clipif (fltSecondsRemaining > intSecondsToCountdown)
{
fltSecondsRemaining = intSecondsToCountdown; //If we haven’t gotten out of the offset period, reset the timer to full.
}if(!boolAllowNegativeTimes)
{
if(fltSecondsRemaining<0) fltSecondsRemaining = 0; //If we've passed zero seconds and user has chosen not to allow negative times, reset time to 0.
}intMinutesRemaining = Math.floor(fltSecondsRemaining/60); //Calculates number of minutes remaining
decSecondsRemaining = fltSecondsRemaining - 60 * intMinutesRemaining; //reduces seconds to less than 60
intDecimalMultiple = Math.pow(10,intDecimalsToInclude); //Multiplier for placing decimal place in the correct spot.
decSecondsRemaining = Math.floor(decSecondsRemaining * intDecimalMultiple); // moves decimal to the right and chops remainder
dspSecondsRemaining = decSecondsRemaining/intDecimalMultiple; //prepare the seconds for display - puts the decimal point back where it belongsif (!(decSecondsRemaining%intDecimalMultiple) && boolIncludeDecimalSeconds)
{
dspSecondsRemaining = dspSecondsRemaining + "."; //If we are at an even second and the user wants the decimal places displayed, tag the decimal point on to the string.
}if(boolIncludeDecimalSeconds)
{
for (a=1;a<=intDecimalsToInclude;a++) { if(!(decSecondsRemaining%Math.pow(10,a))) { dspSecondsRemaining = dspSecondsRemaining+"0"; //Add appropriate trailing zeroes if we are showing decimals. } } } if(decSecondsRemaining < 1000 && boolIncludeMinutes) { dspSecondsRemaining = '0' + dspSecondsRemaining; //if we are under 10 seconds and displaying minutes, and a leading 0 to the seconds } if(boolIncludeMinutes && intMinutesToCountdown >= 10 && intMinutesRemaining<10 && boolIncludeLeadingZeroes)
{
dspMinutesRemaining = '0' + intMinutesRemaining;
}
else
{
dspMinutesRemaining = intMinutesRemaining;
}dspMinutesRemaining + ':' + dspSecondsRemaining