CREATE THIS PROGRESS BAR THAT FILLS ACROSS YOUR FRAME WITH EXPRESSIONS IN AFTER EFFECTS! | In this After Effects tutorial we’ll learn to use expressions and math to build a scaling graphic that builds across a timeframe that you want.
In this After Effects tutorial, we will create a simple graphic and then write out a bunch of expression code to convert a single graphic into a loading bar that will scale across the width of the composition. In this tutorial you will learn about outputting numbers, doing math with expressions, how to figure out how to transform raw numbers into a constantly changing number that will control the horizontal scaling of our loading/progress bar. Hope you enjoy the video!
Tags: after effects tutorial, after effects tutorials, after effects CC, after effects expression, after effects expressions tutorial, after effects tutorial motion graphics, after effects tutorial edit, after effects animation, after effects progress bar, after effects help, how to, tutvid, motion graphics, 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:
/*Change the timeOfProgress var to change the duration of the loader */
/*Number is equalled to the number of seconds i.e. 30=30seconds*/
timeOfProgress = 30;
chunks = 100/timeOfProgress;
if (time < timeOfProgress) { [chunks*time, 100]; } else [100, 100];
- Create a new composition. 30fps, 50000 into duration for five minutes, 2560×1440 size
- Use the rectangle tool and draw a rectangle any size onto the stage
- Add a fill of any color and get rid of the stroke
- Open the Rectangle in the layers area and open the Rectangle Path within that.
- Unlink the size W&H and set the width to 2560 and the height to 50
- Go back to the Shape Layer and hit the letter “S” while in the layers panel to bring up scaling options and unlink the W&V here
- Down scale the width and see how the shape scales to the middle. Not good.
- Grab the Pan Behind (Anchor Point) Tool and drag the anchor point roughly over to the left-side of the composition
- Zoom way in on the left side of the rectangle and place the anchor point exactly on the left edge of the rectangle (THIS IS IMPORTANT!)
- Now it’s time to make this progress bar come to life!
- Let’s get some numbers first and look at how this will work.
- Add text to the stage with the Type tool and set it to any font you like and any size that works for you. This is just to display numbers.
- Open the Type layer and open the text arrow and then Alt/Opt click the stop watch for the Source Text
- In the expressions area add “time” and click away and now show what happens here
- Now to round the number down, add the Math.floor(time); and show what happens now
- Now we’ll create a not-so-simple piece of math that will take the width of the composition and divide it by the number seconds we want the bar to take to get across the composition.
- I want the progress bar to be full when my playhead hits 30 seconds.
- Clear out the code we’ve written and move down to the Shape layer and hit “S” to bring up the scale options and Alt/Opt + click the stop watch to open the expressions and add:
- timeOfProgress = 30;
- Explain this.
- Add: chunks = 100/timeOfProgress;
- This will divide our target of a 100% scale by whatever the number of seconds we want our progress bar to take to get across the screen
- So here, 100/30=3.33333333 and 3.33333333*30=100
- So if our line moves 3.333333 pixels per frame, by the time it does that 30 times, we have a 100% wide bar
- Next we’ll add a line of code that multiplies the frame number by that 3.33333 number. Add:
- [(chunks*time), 100];
- Explain the array for use here for Scale. Explain he chunks var x time once more.
- Drag the playhead beyond the 30 frame mark and see how the progress bar keeps going. We need to stop this. Let’s write an if/else statement to do the job. Add:
- if (time < timeOfProgress) {
- [(chunks*time), 100];
- } else [100,100];
- Explain what’s going on here and why we write what we’ve written
- Now, add a simple note in the code to tell people to change this var number to the number of seconds they’d like the progress bar to run.
- Of course, we could also link this var to a slider so people could even more easily change the input number, but we’d also have to write another if/else statement to limit what numbers the slider can send to the var, but that’s a little beyond where I want to go in this video.
Leave a Reply