Countdown Timer with Expressions After Effects CC Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well hey everybody I'm Nathaniel Dodson from Sun vidcom welcome right into this Adobe After Effects tutorial where we're gonna create a super cool it's a pretty simple thing it's a countdown timer and I'm gonna show you three different ways to create countdown count up timers we're gonna use expressions in After Effects think you're gonna enjoy it and learn a thing or two while we're at it if you enjoy this video make sure you subscribe to my youtube channel and with that out of the way let's jump into After Effects and check this thing out alright well here we are in Adobe After Effects and let's just jump right into it the first thing I'm gonna do is grab my text tool and we're just gonna place some text and be kind of in the middle of the screen and we'll just type out the word timer you can really use any text you want because we're gonna be replacing this text with our outputted expression slash code generated text I am going to use the typeface let me do something a little simpler here maybe I'll go with rail and I'm going to choose let's go with the ultra light so maybe not thin we'll go ultra light just slightly bigger or thicker I should say and let's change the color to like a super light blue let's try like zero zero I'll be super blue see FFF something like that a nice C blue very very bright I'm gonna go to a line and just align this to the Centers of my composition kind of sort of something like that and we've got our text so here's how to create a basic counting up word seconds timer open up the timer text layer open up the text sub sub object I guess we could call it hold down alt or option and click on the little stopwatch for source text and we're simply going to type out time and we're gonna stop and you can see our text is now replaced with this zero now if I hit the spacebar to begin playing through this expression you can see we're getting what looks like some crazy math that's being done and that's because code is pretty precise computers in general fairly precise machines so we're getting the second at which the playhead is at that very moment which is three seconds and change and it's displaying us three point seven because by the time we get to 3:30 that's gonna really be four seconds so we're a little over two-thirds of the way there and sure enough seven is a little over two-thirds of the way to 10 when we're talking about decimal numbers right we all know that this doesn't do me much good though because when I have a timer on a video and it looks like this people are gonna be having epileptic seizures and all kinds of nasty stuff so I want to round my number down so here's how we're gonna do that we're gonna use a simple math operator here when you say math dot floor around the sucker down to the nearest number William what number well of course that's going to be times we're gonna place time within the open and close parentheses and now when we play through our video we get a nice clean one two three four or five six you know as the speed of our video plays through so this is really how to just create a very basic counting up word timer we could take this text we could align it to the center of our composition like so and we could just kind of let this thing go and it will count all the way up to 300 seconds which of course is equal to five minutes why because in my composition composition settings I have this sucker set to a duration of 5 minutes so it'll just count as long as your After Effects composition is in existence and minus 5 minutes let's go ahead and set a simple countdown timer a timer that's gonna count from 60 down to 1 over to 60 to 0 really so what we would do here is we would stick with math.floor but what we're gonna do is add to this we're gonna create we're gonna do a little bit of math number 1 let me just show you I'm gonna cut this just to show you how this math works so you could tell this text look a text be equal to 100 and boom it's equal to 100 we could also say look text be equal to 100 minus 32 and it's gonna be equal to 68 right we could we could say 100 maybe plus 32 in which case it'll be 132 what I'm trying to show you here is that we can perform math within our expressions I could use an Asterix instead and say 100 times 32 is can be 3,200 all right or you know of course divided by 32 as well and it's gonna be 3 point 1 2 5 3 and 1/8 so I did all of that to just say I can perform a little bit of math in here so I can say look math dot floor be equal to 60 minus whatever the time is so you can see what's gonna happen is it's gonna begin at 60 and when the playhead gets to 1 it's gonna subtract 1 which of course is 59 when the playhead gets to two it's gonna subtract 2 which is 58 57 and so on and so forth so now we have a timer that begins at 60 and counts down one second at a time and eventually it's going to hit zero now of course when it hits zero because we haven't put any limitations on it it's just gonna keep going into the negative numbers how to tackle that that's a whole different thing well we'll get to something similar to that in a little bit but you can see very quickly we've created a very basic counting up word timer and a very basic counting down word timer let's talk about the more advanced timer though this is where things get fun let's clear out this quick expression here the goal of our timer is going to be to create a timer that the user can input a number and have it count down from that number let's go ahead here and right click and choose new by the way notice has just refilled our text when we got rid of the expression stuff with our original text we're gonna go here right click new and choose new null object and I'm gonna double click on this I'm not gonna double click on it I'm used to working with Photoshop layers I'm gonna right click on it and she was renamed I still have not gotten used to that after all the time I've used After Effects I'm gonna I'm gonna name this timer duration or something like that because onto this null layer we're gonna come over here to our effects and presets panel I'm gonna search for the slider there it is slider control we're gonna drag and drop this here onto the null object layer and now we have this slider control so the idea is gonna be a user should be able to punch into the timer look I want my timer to start at 5 minutes and count down from there so they would just punch in the number 5 let it be and the timer would go to work starting at 5 and countdown so I'm just gonna leave the said zero we'll get back to the slider in just a moment so the first thing we'll do is we will set a rate of speed for our timer I'm gonna do the work again here inside the source text area of our timer text so alter option click on that and we've opened up our expressions our default text has gone away that's fine I'm gonna begin by creating a variable now when you're creating your own stuff and you're more advanced with expressions you can create super short variable names that you know what they mean but for the sake of tutorials I like to work with more literal longer variables so everybody kind of is on the same page so our first variable is gonna be called rate of speed and I'm camel coding here that's where the first letter is not capitalized and every letter thereafter is capitalized so we can say look rate of speed equals let's just go with 1 so this is the rate at which our timers gonna move just one at a time one unit whatever that means now we're going to create the starting time so I'm gonna hit enter/return we're going to place another variable and we're gonna call this clock start time again we're camel coding and we're gonna say this is equal to what's it equal to well I'm glad you asked let's toggle down our null object and within effects we have this slider control and within slider control we have this slider and it's outputting a number so what we want to do is come back over to here and place our cursor after the equals sign for start time and then use this little pink whip icon and say look it's gonna be equal to this number here this slider number there we go and an After Effects puts this long line of code in there that's perfect now I'm gonna hit the semicolon to just close off that line of code and be done with it now you can see of course our slider control is set to zero we have a zero out there we're not really outputting much of anything we're just building our variables right now so I'm not really concerned with anything but we aren't triggering any errors not yet at least what we next want to do is get After Effects to spit sort of a continuously changing countdown number back at us so we can use it and display it here in our text field so here's what we gonna do we're gonna create another variable so I'm gonna hit enter/return a few times here in fact I'm even gonna drag my expression window downward a little bit just to open up a little bit of space for us to use down here I'm gonna create another variable and I'm gonna call this clock time I'll call it clock time and number and I'll say look clock time number you're gonna be equal to my rate of speed so rate of speed that's that rate of speed variable really that's basically I'm typing the number one but you're gonna be the rate of speed multiplied by time so whatever the second is at which my playhead is that's what you're gonna be multiplying by so 1 times 1 is 1 1 times 2 is 2 1 times 3 is 3 and so on and so forth and this might seem a little redundant it is unless you want to change the rate of speed maybe you want your countdown timer to move at double speed then all you have to do is update rate of speed to 2 and all of a sudden you have a timer that's gonna move twice as fast so that's the reason I'm building it this way I'm gonna throw a semicolon onto the end of this and I'm gonna deselect you can see here if I drag the playhead that we're gonna get we do have a continuously changing number now but it's a little crazy right it's just kind of going wild there's all these decimals well how do we fix the decimal issue just like we did before with a simple math dot floor so let's change clock time number here we sell a clock time number you're definitely equal to this but before we get to that we're gonna say math dot floor and then here we're going to place this little this little mathematic problem within those parentheses and that's gonna kind of simplify things for us you can see now we're just spitting back nice clean beautiful numbers and if we play through it you can see it's just gonna advance one second at a time now like I said if we change rate of speed let's say we wanted to go five times faster change rate speed to five and watch how fast the numbers jump now you see that we're moving five times it's going up five numbers every second so that's where the little rate of speed thing can be nice if you want to have extra flexibility and control over your countdown clock and if you don't they just leave rate of speed at 1:00 and you got a perfect countdown clock by the second so now we need to link this here to whatever the slider number is that's taken in by our clock start time variable so here's what we gonna do we're gonna come in here we're gonna say yeah we're still gonna work with in math dot floor but what I'm gonna say is use my clock start time variable and subtract rate of speed times time so this could be something as easy as let's say clock start time is 60 so start my timer at 60 and then just subtract by one and then two and then three and then four and then five and as the playhead moves down obviously this number here rate or speed times time is going to get bigger and bigger and bigger and as that subtracted from clock start time well guess what our countdown clock is going to display a smaller and smaller and smaller number now the problem is our slider right now is at zero so I'll drag through this and you can see we're just getting this crazy negative number because it's starting with zero and just subtracting one two three four five six seven and so on and so forth so we're gonna change slider here we're gonna say well of course we want this to be five minutes so we'll set this to five but watch what happens it sets our timer for five but it's boom or we're right back down to zero because this is really just seconds if we want five minutes we have to start this at 300 because 300 divided by five is 60 or rather I should say five times sixty five minutes is five units of 60 seconds five times 60 equals 300 and our problem of course is going to be that this is no timer just a thing counting down from 300 to zero yeah sure over the course of five minutes look at that we're back down to zero but this is not a very effective or easy way to work so let's change a couple things here so number one we can use the slider and punch in a minute number that we want and also so our clock will display seconds and minutes instead of just this giant 300 number to make this easier for people who be coming in and using our slider let's change the way the clock start time takes the number from the slider so right now it's just literally taking the number off the slider but remember we can do math so why not just add a asterisks 60 to the end of this so we'll say look take the number there from the slider and just multiply 60 so so many types in five instead of being five seconds make it five times 60 which would be hey 300 seconds now right now the sliders at 300 so when I click away we're at 18,000 a little excessive I understand but now we can go to slider say look yeah I want five minutes and there we are 300 seconds we still aren't displaying minutes and seconds but we're gonna get to that so I don't know if you've noticed but whatever the last variable that we type is that is what our source text is respecting and displaying here in the text field so let's go ahead and choose something else to display like if I just type down here 1000 and I click away you can see that the text field is gonna display the number 1000 that doesn't do us any good though let's uh let's do something that's a moving dynamic number let's take our clock time number so we're gonna say clock time number where we're doing all this math math floor clock start time yadda yadda yadda and we know that right now if I well you know what if I well yeah here let's just let's display it if I display that and just leave it as it is it's gonna display 300 because five times 60 which is what this ends up being is 300 but it's only 300 when the the playhead is at the very beginning that doesn't do any good I need to start breaking this down by the minute so let's try dividing this by 60 and see what happens well hey there we go this is a good start we got five minutes and as we begin dragging the playhead we're getting these crazy decimals again but look look at what happens if I drag this out to the one minute mark we display a straight even four minutes so everything at 30 seconds it should be about four and a half either we go four point five that's four and a half so we're getting the correct information now it's a matter of using the code to format it so it looks and acts like a timer so let's uh I'm gonna wipe this out for a second we'll bring it back in a minute if we need I want to create a couple variables here because I want to hold the number for our minutes and that'll hold a number for our seconds so let's create a variable called minutes and we're going to say all right minutes you're gonna be equalled two math dot floor open and closed parenthesis and the minutes are going to be that clock time number simply divided by sixty right that gave us a nice even five and if we math dot floor it it's just gonna be five until it's four and then it's gonna be four until it's three and three until it's two and so on and so forth so that's good that's gonna give us a nice even minute and then seconds this one has to be a little bit more complex but it's still pretty easy to do here seconds equals that same clock time number we're not gonna divide it by 60 here instead we're gonna use what's called a modulus and that's gonna be the percentage symbol so shift 5 on my keyboard and here we're gonna say modulus this 60 now what exactly the modulus is doing it has to do with taking the remainder of a divided number and all kinds of complicated math stuff I'm not really good with math stuff here's what I know it does it basically is gonna say look take this clock time number which right now is 300 and force it to work within a loop that only goes up to 60 and then resets itself to zero and it'll do that as many times as it has numbers so how many units of 60 fit into 300 well of course we know that's five because we've just talked about ad nauseam at this point so this is going to give us a number that begins at 60 slides its way back down to zero and then resets to 60 just like a stopwatch or a countdown timer should add a little semicolon to the end of that line and now what do we want to display in our text field well we can simply type it out look I want to see the minutes right I want that to display in this text field whatever the number is so if I just leave minutes I'm gonna get my minutes that's not enough though I need seconds too so we're gonna say minutes plus seconds and watch what happens here here I can play through this and we're getting kind of a complicated looking I don't know what's going on here well here's what we need to do we need to actually place a specific string in here so we could say minutes plus and then open and close double quotes and we want to place some text in here so we're gonna display text and by placing double quotes it's gonna tell our expressions look actually type out the word or letter or symbol that we place in here so I'm gonna place a colon and then I'm gonna say plus seconds so we're saying look display minutes plus then display the semicolon plus then after the semicolon display the seconds and let's see what we've got hey hey look at this now as we scroll through we have something that resembles a timer and let's see if it works let's go up to the slider and set this to three minutes instead look at this we begin at 3 minutes and now we're going down to 2 and 1 and so on and so forth very very cool I'm gonna set it back to 5 here in a slider so we've got a five-minute timer and by the way if you want to see I could I could change this and I could say look and type out the word tut vid in between the letters and you can see the word Tut FID would type out that obviously make a lotta sense for our timer so we're gonna stick with the : here's where things get a little bit more complex as if this lot of code didn't look complex enough to you we need to create a function because obviously we're missing a zero and maybe we want a zero to be out here next to the 5 because what if we punch our timer up to 10 right it's gonna have extra numbers so maybe we always want there to be a zero next to the 5 and of course we need there to be a zero that shows up there so here's how we're gonna do this I'm gonna come up here and I'm gonna place a function I'll place a function right up here between there our top two variables and this next variable just just because it looks good here so I'm gonna talk about the word function just tell the expression zip we're gonna create a function and then I'm gonna give the function a name so I'm gonna give this function the name of add a zero again we're camel coding and in parentheses here I'm just gonna put the letter n this is just sort of a placeholder you're gonna see exactly how this works in a minute just type it out I'm not even gonna try to explain it because it's it's just basically a return to number but that I know understand that means nothing to you at this point in time let's create an open curly bracket and to return a couple times close curly bracket and hit the tab key to indent and in here I'm gonna place an if-else statement so I'm going to say look if that returned a number n whatever that is we don't even know what it is right now if that is less than 10 closed parenthesis we want you to return a zero and we want the zero to be a string so we put this within double quotes a string is just a piece of text it's not a data a number like this is a number it's not the same as typing number this is a number that the expressions in after-effects can do math with you can add numbers together you can't add like if I say 0 plus 25 that doesn't work it would just literally display 0 plus 25 in my text field so when you say look return the letter the letter 0 the numbers 0 plus whatever this end a number is what does this mean this seems complex hang with me here a second I'm going to show you and then the else part of the if statement here we're gonna say else simply return the N number and then a semicolon here at the end so what exactly does this function mean well basically what we're gonna be telling our expression here I'm gonna scroll down a little bit I'm gonna open up my expression panel a little bit more what we're gonna be telling our little expression here is when we use this function if the returned number which is gonna be any number it can be it's this variable it can it can change if it's less than ten returned a zero plus that number I know what you're thinking it still doesn't make a lot of sense well let me just let me just show you what we're doing here okay so we want our timer to have the minutes plus the : plus the seconds but instead of seconds we want this to be our function so I'm going to say look add zero and then in parentheses hey doesn't this look familiar if I get rid of n we got the same exact thing here but instead of typing n this is where n is going to be defined and n is going to be seconds so whatever number seconds are which right now it's zero that becomes n so what is the if statement saying the if statement saying look if n is less than ten return a zero plus whatever n is so what's going to happen when I commit this well the functions going to look and say wait is n is the seconds less than ten yes it is it's zero therefore it's going to place a zero on the left side of this currently existing zero but as soon as that n is greater than ten it's simply going to return of the seconds which can be 11 and 12 once we got it 11 and 12 we don't want an extra zero there because then it'll be zero 11 that doesn't look good so check this out we now have two zeros so let me just move through this there we go 459 you know what I should probably move up here so we can see it in action right you can see that look there we are at 10 and as soon as we get to soon as we get to O nine we've got oh nine oh eight oh seven oh six oh five and then as soon as it's greater than 10 again when it's equal to 59 well the zeros go away see it real quick let me show you if I just add zero to this to say look if n is less than 10 return 0 plus and else return just n which is just the the R all seconds if I do the same thing here and I say look return 0 plus and here as well you see we got the 0 next to 59 as well because despite the fact that our n the seconds is greater than 10 we're still telling it to return an extra 0 being attached to that seconds number we don't want that though obviously because we want it to look like a proper timer it's a little complicated I understand but as you kind of sit here and think about and conceptualize it it'll start to make sense especially if you build this along with me and oh by the way we can come over here and add the zero to the minutes as well sorry I keep rolling over my toolbar there I zero to the minutes as well which is going to go ahead and say zero three minutes and if I push my timer up to something like 10 minutes and I slide back to near the beginning there's no zero next to the 10 so you can you know you've got some personal preference here I think I kind of like the zero we'll probably just stick with it for the sake of sticking with it and learn to love it now another thing we want to do is just limit the slider to prevent the problem that would arise if somebody tries to set a negative number here so let's create another if statement here I'm gonna create this one down here at the bottom so I'm gonna say look if and then in parentheses o'clock start time remember that's going to be basically what the what the sliders equal to if o'clock start time is greater than zero I'm gonna add some spaces between the stuff if it's greater than 0 open curly braket and to return a couple times close curly bracket make my expression window a little bit larger even if it's if the o'clock start time is greater than 0 well we're gonna let you execute this double function here and display what we want you to display and we'll come down here outside of the curly bracket we'll say else if the o'clock start time is less than 0 open and close curly bracket there semicolon and within those curly brackets if we wanted to just display static text so open and close quotes we're going to say zero zero colon zero zero and then I will click away and we can play through this timer still works like normal but if I come up here to the slider and I try setting this to like negative five look at that it just displays zeros across the board and nothing's happening when I drag and move the playhead around because we just kind of locked it down because we don't deal with time in the negative space so now there's one more problem or issue that we need to tackle here and that is when we get all the way to the end we're gonna see some negative numbers now we're not seeing them here because of course we have a five-minute composition here and we have a five-minute timer but if I change let's try it ain't changing the time order like three minutes and you can see here yeah when we get out past three minutes we start getting these negative numbers that look pretty awful right how do we fix this well we need to add something to our if-else statement so we'll come back here to if and we're going to add a second parameter not only this o'clock start time have to be greater than zero before you execute my time function here or my a bit of math that's going to display that but I want it also to add something else needs to be going on here so I'm going to use a double ampersand that is the way you say an so not only clock start time needs to be greater than zero and also time make sure I put space there between the ampersand ampersand and time and the time needs to be less then whatever clock start time is so remember if clock start time is three minutes once the time gets passed three minutes well guess what it's gonna trigger the else statement which is just gonna set our countdown timer to zeros across the board let's see what happens here well here we are out past three minutes and sure enough we're down to zero so when we get to three minutes we hit zeros across the board and then it just stays zero all the way out so it's a bit of code I'm gonna include this here probably there's a comment or over on the blog so if you don't want to go through all of this shuckin and jivin to write this code and you just want to copy and paste it you'll of course be able to do that but I wanted to really take a nice deep dive and walk through how all this code works so you understand it when you are going ahead and trying to write and build your own expressions here in Adobe After Effects and yeah I guess that'll pretty much wrap this one up there you have a simple counting up time or a counting down timer and then the more advanced kind of better looking timer in Adobe After Effects if you enjoyed this tutorial again make sure you subscribe to my channel so you never miss any After Effects or video editing tutorials past the present or future if you're on discord check out our discord server it's a happen in place and we're growing super fast discord may slash Hut fit and if you do Instagram you can follow me over there at Tut fit as well where I try to do a live show just about every day and that's a whole bunch of fun as well guys for just a bunch of stuff about expressions I really can't put it any other way than that a bunch of stuff about expressions for all that and more that's it get got it good neva Dodson Tut vidcom I'll catch you in the next one and before you go make sure you subscribe to my channel for more great tutorials every day also by my course it helps us do what we do and this channel is supported by viewers just like you you can also just click the thumbnail and watch another video from this channel see you next time guys [Music]
Info
Channel: tutvid
Views: 365,739
Rating: undefined out of 5
Keywords: 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
Id: tzMbwnv79MA
Channel Id: undefined
Length: 24min 19sec (1459 seconds)
Published: Wed Feb 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.