No items found.

Tutorial: Tapering A Stroke with Expressions in After Effects Part 1

Jake Bartlett

We all know After Effects is PACKED with features, but sometimes After Effects just doesn’t have the feature we want built into the program; for example the ability to taper a stroke with ease and control. Well, After Effects still has us covered in that department, it just takes a little more know-how to do it.We just need to roll up our sleeves and get our hands dirty with some fancy expressions.

Expressions can seem a tiny bit overwhelming at first, but once you learn how they work you can do some really amazing stuff. In this lesson our resident Expressions Wizard, Jake Bartlett, will take you through the first part of how he built this powerful tapered stroke rig. It’s a lot to digest if you’re new to expressions, but Jake will guide you through and break down everything into easy to handle nuggets of knowledge.

In this lesson Jake will be using a really great tool for writing expressions in After Effects called Expressionist. Go ahead and grab that here if you're ready to really dive deep into the world of code.



Tutorial Full Transcript Below 👇:

Music (00:01):

[intro music]

Jake Bartlett (00:23):

Hey, this is Jake Bartlett for school of motion. And I am going to be teaching you how to make a tapered stroke rig in after effects using expressions. Now, expressions are a very intimidating topic. Let's face it. Code is just not a language that most motion designers speak, but if you can understand some very basic principles of how to use expressions as a problem-solving tool, the possibilities that they open up are pretty incredible. You can create entire setups inside of after effects that allow you to do things that natively after effects can't even do. They're an extremely powerful tool to have in your toolbox. And hopefully after this lesson, you will have a very good grasp on how to use them to your advantage. So let me start with my big fat disclaimer up front. We are going to be writing a lot of code in this lesson, and it's going to get pretty geeky, but it's not going to get too complex.

Jake Bartlett (01:16):

Really. We're going to be more clever with our expressions, so you should have no problem following along. I'll go step-by-step. And at the end, we'll have a tapered stroke rig that you can reuse over and over in any project. All right, let's get straight to it. I'm going to make a new composition and frame rate. Doesn't really matter. Resolution I'll do 1920 by 10 80, and I'll set the background color to white, just so it's easy to see, and I'm going to start by drawing a line. Now, natively shape layers. Do not allow you to taper a stroke in after effects. It's a single width all the way along your line. There's no control for that. The only real solution that I know of that exists is trap codes, 3d stroke. And the reason I don't really want to use that is because one it's not free.

Jake Bartlett (02:00):

And two, it works with mask paths. So I don't have all of the controls and special operators that shape layers allow me to have. So when I approached this problem, originally, my goal was to have a line behave exactly the same way that I'm used to on a shape layer that I could control with trim pads and use all kinds of operators on exactly the way that I was used to with the additional control of being able to control the width of the line from one end to the other. So let me show you what my original concept for that. Even being a possibility was I will go into my contents and add a trim paths on the shape group. I don't need that fill and I'll make my stroke round caps and round joins. Then I'll take my trim paths and set the end value to 10.

Jake Bartlett (02:48):

And I'm going to make a bunch of duplicates of this group. So let's say 10, and then I will bring up all of the start and end values. And I want to offset each one of these by 10%. So they have 10 different segments. So I'm just going to do that really quick, not a very fun process to have to do this. All right, there we go. So we've got 10 segments all offset, um, by 10% on the trim paths, then I will open up the stroke width and offset each one of these by 10 pixels. So 100 than 90, all the way down the line.

Jake Bartlett (03:29):

All right, there we go. So if you take a look at this line, it's totally crude, but you can kind of see the concept of working. Basically if you segment this line and offset the trim pass of each one of them, as well as the stroke with you kind of get a taper. Now, obviously you would need a lot more segments to make this not noticeable and doing it by hand is pretty much out of the question that takes way too much time. And I have all these duplicate groups that each have a copy of the same path. So if I were to go in and try and modify this path, that's only controlling this segment. Then I've got another path, another path, really, I would want one path to control all of the segments. So I wanted to figure out a way to get expressions, to do all this complicated work for me.

Jake Bartlett (04:17):

So I didn't even have to think about it and I'd be left with a tapered stroke. So now I'm going to walk you through how I used expressions to solve that problem. I'll start by deleting all of the duplicate groups and I will rename this master group. Then I'll duplicate that group and rename it taper oh one, and I'll regroup that group and name it, duplicate groups. Now setting up this structure is pretty important because we're going to be referencing a lot of different properties in groups within this layer structure. So naming is super important. So let's continue to structure and rename the contents of the master group, master path, master trim paths and master stroke. All right, in the duplicate groups, I will go into the taper oh one, and that is all just find the way it is. So I want these expressions to be based off of the master group.

Jake Bartlett (05:15):

I want all the duplicates to be following the master group. And then the expressions that we use will automatically divide this line up into segments and offset the stroke incrementally. So the first thing I want to do is link the duplicate path to the master path. So this is what we're going to use our first expression for if you've never used expressions before you just go to any property that has a stopwatch for the key frames and hold down option or alternate PC and click on that stopwatch that will open up the expression dialog box and give us a few extra controls. And it automatically fills in the code that references the, the property that you were putting that expression on. Now, I don't need this line of code. I actually need the code that references the master path, but I don't actually have to know how to type that out or what the code to reference that is.

Jake Bartlett (06:04):

There's this little expression pick whip that behaves just like the parenting pick Quip. I can click and drag it and then come down to the master path and let go. And then after effects will automatically fill in that code for me. So I don't have to do any coding. It's as simple as that, I just click off to apply it. And now that duplicate bath follows the master path. And if I offset the trim paths for this group, just so we can see the two different groups grabbing this path and moving it around, you see that it looks like there's only one copy of that path because this path will always follow it. Now that we have that expression so awesome. We're already using expressions to make stuff work. Let's keep going next. I want to add some expression controls. So I'm going to come up until effect and go to expression controls.

Jake Bartlett (06:52):

And you'll see this whole list of controls that we can add now on their own expression controls do absolutely nothing. They're basically there just to give you values that you can use to control expressions. So the first one we'll start with is slider control. So go to expression controls, slider control. And by default, a slider, if I total this open has a range of zero to 100, you can grab this number and go past that range in either direction. And you can also right click on the slider and say, edit value to adjust that range. We're not going to need to do that, but just so you're aware if you ever need to have a different range of numbers, zero to 100 is going to work just fine for what we're using it for though. So I'm going to rename this slider stroke width, and then I want to link the master stroke width to that slider to do that.

Jake Bartlett (07:43):

I'll just hit option and click on that stopwatch to add the expression, grab this expression, pick whip, and I can actually come up to the effects controls panel and let go. And there we go. The after, uh, after effects fills in that line of code for me, I click off of it. And that number turns red. Now that means that there's an expression driving this value. I can click and drag in this number and you see it's changing. But as soon as I let go, it switches back to zero. The reason why it's zero is because our stroke width slider is set to zero. If I adjust this, you see that now the stroke width of my master path is being controlled by that. And just like I said before, I can increase that to a higher number if I need to, but I seriously doubt I'll ever need a stroke with higher than 100.

Jake Bartlett (08:29):

So I'm going to leave the range right where it is next. I'm going to duplicate this slider and I'll rename it. And, and I want to tie the master trim paths, end value to that slider. So I will add an expression again and pick whip that slider and click off. Now, if I move this slider around, it controls the end value. And because the end value as a percentage of zero to 100, the range of zero 100 is perfect for that value. So no need to change that next. We need to add another type of expression control. I'll come down to angle control, and this is going to be a value measured in degrees. So the offset control is measured in degrees as well. So that's the type of controller I want to use to drive that property. So I will add my expression, grab the pick whip, select the angle control and click off. Now that angle is controlling the offset of the trim paths.

Jake Bartlett (09:27):

Now, if you take a look at the way that after effects wrote this expression, it's referencing the effect angle control and the value of angle. But the Morton part that I want to point out is that the name of this effect is angle control, which you can see up here. If I change the name of this angle to offset the expression, just updated based on what I named it. So after, after effects is pretty intelligent in that sense, which is a really nice feature. All right? So we've already got three controls driving a rig, but there's a lot more you can do with expressions than just linking properties to expression controllers or to other properties. You can have complex equations. You can base stuff on time, offset, key frames, there's all kinds of possibilities. Again, we're not going to get too complex, but we are going to start writing some code of our own.

Jake Bartlett (10:16):

So this is where I want to introduce an extension for after effects called expressionists. So I'm going to switch over to my expressionist layout and make this window bigger over here. Now, expressionists is an expression editor that is much easier to work with. Then the expression editor built in to after effects. As you can see down here, I'm confined to this window. I can't change the size of the font and it can get pretty complex. If you have a lot of lines of code with not a lot of room to work with expressionists behaves a lot more like an actual coding program inside of after effects. And it has a ton of great features. If you're serious about learning, how to write expressions and making your own things with expressions, I highly recommend that you purchase expressionists. It is totally worth the money and we have a link for it on this page.

Jake Bartlett (11:09):

So you can go check it out. If you think you're going to get it, I would even recommend that you pause the video, go buy it, install it, and then come back. So you can follow along with me inside of expressionists. It's fine. If you don't use expressionists. Everything I do in here is completely doable inside of after effects. Expression is just makes it a lot more easy to look at. Alright. So the first thing I want to do is work on the start value of the master trim paths. So I'm just going to clean up my layer a little bit, so I can just focus on what's important. I want the start value to be based on the end value and the total number of groups in my layer. So the number of duplicates that we have in this group here right now, there are two groups total, the master group and taper oh one.

Jake Bartlett (11:53):

So I want the start value to be the end value divided by the number of groups, which is two. So it should be 50. So what does the expression look like? That would get that to happen? Well, let's write that code. I'll come over to expressionist and I will select the end value. And down here, I have this pick whip. I will click it once. And expressionist fills in the code exactly the same way as if I was writing the expression down here and using the expression pick whip. Now, the syntax that expressionist uses is slightly different than the syntax after effects, eases, and syntax is just the structure and the naming conventions that coding languages use. So things like putting names in quotes and putting groups in parentheses, the thing is after effects and natively uses one naming convention for its syntax and expressionists just uses another one.

Jake Bartlett (12:44):

That's a little bit more consistent expressions are based on the JavaScript language. And it's pretty flexible in the way that you can write things. If you look down here after effects, puts content, master group dot content, master trim paths, and expressionists uses parentheses and double quotes for each one of those groups instead. So you see contents instead of being separated by periods is just in the exact same format. As the other groups. The end result is exactly the same. It's just a little bit different way of writing the code. So if you're not using expressionists, just know that anytime I click on the pick whip, my code's probably going to look different than yours, but the end result is going to be exactly the same. So don't worry about it. All right. So that code references, the end value. And then again, there are two total groups, the master group and the taper, oh one.

Jake Bartlett (13:32):

So I want to take this end value and divide it by two. Then I'll apply that to the start value by having my start value selected. And then inside of expressionists, pressing command enter that applies the expression. And look at that. Our start value is now 50% because it is 100, the end value divided by two. So that's great. If I go into my effects control and I adjust the slider, you see that the start value of the master group is moving in proportion to the end value. So if this was set to 50, then the start value is 25% because it has half of the end value. Great. The problem is that hard-coded number is not going to update with the number of groups. So if I were to duplicate this groups, this value doesn't change at all. So instead of using a two, we need to tell after effects how to count the number of groups and automatically fill that in instead of a hard coded number.

Jake Bartlett (14:35):

So I'll delete these duplicate groups, and now I'm going to show you really quickly how to get a groups index. So I'm just going to make a new composition really quick for a demo. You don't have to follow along with this. Uh, I'm going to make a new solid, and you probably already know that this number over in this column is the index value of the layer. That's what aftereffects calls it's number. It's an index value. What you might not know is that inside any layer, every group, every effect, and every property has an index value. There's just no number next to it. So inside of this layer is a transform group right now. That's an index value of one. If I add, say a fast and blur to that layer, now there's an effects group. So in this hierarchy, the index value of effects is one in transform is two. If I open up the effects and I duplicate this fast blur five times now there's a hierarchy inside of the effects group. Fassler 1, 2, 3, 4, 5. So I'll open up the fifth fast blur and I'll add an expression on the Blair value. And I'm just going to type in a simple expression, this property. So the property I'm writing the expression on.property group parentheses one close parentheses.property index.

Jake Bartlett (16:03):

I'll apply that. And now we have a value of five. So this expression is saying this property, the blurriness property group one, which means the property group one level higher than this property. Give me the property index for that value. So one level higher is fast blur five from the value that I'm writing the expression on. If I change the order of this fast blur to the third position, that value updates to three. And if I copy this expression to all of the fast blurs, and double-tap the E to bring up all the expressions, you see that the index value is reflected in the fast blurs blurriness, and it updates based on the order of the effects. So that's how we can find the property index of any value. So I'll go back to this main comp and things get a little bit more tricky when it comes to shape layers to show you what I mean, I'm just going to go into the stroke of this, taper a one, and I'll add an expression under the stroke width.

Jake Bartlett (17:08):

So if I type that same expression, this property.property group, one.property index, and I capitalize this property that is not the proper syntax, so that would have broken the expression. So that is something that is very important to take note of. It's very common for commands and expressions to start with lowercase, but then the second word of the command to be uppercase in every word after that uppercase as well. And if you don't follow that syntax, the expression will break. So anyway, we've got this property property group, one property index. So the index of stroke one, so it says, it's got a value of three. If I move it up, it goes to two. So we know it's working. Here's where it gets interesting. The next level up is taper. Oh one. So you would think if I change this to group two, we should get the index value of taper a one, but this returning a value of two, and there's only one group inside of duplicate groups. If I duplicate this taper, the value doesn't change, I can do it as many times as I want. It's always going to be two. So the reason this is happening is because there's actually an invisible layer of the hierarchy that we're not seeing to show you what I mean, I will grab the stroke width and let's get rid of this. I'll clear it out. And I'm going to pick whip that stroke width.

Jake Bartlett (18:34):

So let's look at this layer structure that it, that it gave us starting at this layer contents, duplicate groups, contents, which we don't see taper, or one contents again, then stroke one, then stroke width. So the reason this is happening is because there is an invisible layer of contents inside every shape group. It's a unique thing to shape layers, but it's very important to be aware of because when we're using this property group command, we need to account for those levels of the hierarchy, even though we can't see them. All right, so let's get rid of that expression and we can actually start doing some coding. So let's go back to the start value. I will load that back in, and I'm going to get rid of this divided by two. Now, obviously this line of code is not that easy to look at. It's pretty long, and it would take you a little bit to figure out what exactly it's saying.

Jake Bartlett (19:34):

It's not very clear, but expressions allow you to create what are called variables in a variable is basically a way for you to create your own shorthand so that your code is easier to look at. So I'm actually going to clear out this entire line of code, and I'm going to start over by writing a new variable. So to write a variable, you start by typing VAR for variable, and then you need to give it a name. So I'm going to name this end and then an equal sign, and then the line of code that you want and to contain. So I want to go to the effects and to the end, slider and expression is can't pick whip anything from the effects control. So that's why I went down to the effect. But then with that selected, I will click on the pick whip and end that variable with a semi-colon.

Jake Bartlett (20:21):

It's very important that you end it with a semi-colon or else after effects will not know when that variable is supposed to end, but there you go. Now I can use, and in anywhere in my expression after that line, and it will automatically interpret it as this line of code. Cool. So the next variable that I need is the total groups. So I'll make another variable and name it, total groups, and then I need to write the expression that will give me the total groups. So I'm going to pick any property within this taper. Oh one. So we'll just say the opacity pick rabbit, and then I can get rid of everything on this line of code that I don't need. And remember, I want to count the number of groups within duplicate groups. So I need to go to this layer contents, duplicate group contents that invests that invisible layer of contents, and I can get rid of everything else. Then I'll type in a new expression. It's very simple dot numb properties. And what that saying is take the number of properties that are within the contents of that group.

Jake Bartlett (21:33):

So now I can write my equation. So drop down two lines and I'll say end divided by total groups. And I'll end that with a semi-colon now after effects is pretty forgiving and we'll generally still carry out a command, even if you don't end the line with a semi-colon, but it's just a good practice to get into, to make sure that there are no mistakes in your code and no errors pop up. So just get into the habit of ending every line with a semi-colon. All right, now that I've got that written, I will apply it to the start value. And the value goes to 90.7, which is exactly the end value. So let me just make this 100% to make it more clear. Why is the end value 100 divided by the total groups? Also 100, there are two different groups, so it should be 50, right?

Jake Bartlett (22:24):

Well, the problem is we defined total groups to be the number of properties within duplicate groups. And the master group is not contained within that. So the expression is actually working exactly the way it's supposed to. It's just not what we want. So we need to account for this master group within our variable for the total groups. And it's very simple to do that. All I have to do is add a plus one after numb properties, and that will automatically increase the number of properties by one, anytime it references it. So let me reapply that to the start. And there we go, we're back to 50%. And now if I duplicate this group, you see that the end value updates as well. Now it's not updating the way that I need it to, but it is being based on that total number of groups, which is progress.

Jake Bartlett (23:14):

So we're doing great. Let's delete those duplicate groups. And then we need to add another factor into this, which is the segment link. So I actually need to duplicate my end slider and I'll rename it segment length, and I need to define a variable for that slider. So I will drop down here and type in VAR, SEG length just for short, and then open up the segment, pick whip it and finish off that variable. Now I want to update my equation to be end minus the segment length divided by the total of groups. And if you remember back to your algebra days, the order of operations applies here. And by that, I just mean multiplication and division is going to happen before addition and subtraction. So this equation is going to play out like this. It's going to take the segment length 100 divided by the total groups too.

Jake Bartlett (24:20):

So that becomes 50. Then it's going to take the end value, which is 100 and subtract 50 from it. And it'll do it in that order. So let's apply that to our start value. And now when I duplicate this group, you see this number is getting bigger, closer to 100, making the segment link smaller with every duplicate that's working exactly the way it needs to. And that's actually all we have to do for the start value. Now we can move on to the duplicate groups. All right, hopefully you're following along with no problems. I know this is a lot to take in, but hang in there. We're making really great progress. Let's get into the trim paths of the taper, a one and start with the end value. Now really I want the end value of the first duplicate to be in the exact same place as the start value of the master trim paths. Or another way to think about it is I want the end value to be the same as the master end minus one segment length. Now that might sound a little bit confusing. So instead of talking about it, I'm just going to show you let's write the expression for the unvalued. I'll load that up into expressionists, by shift, clicking into the editor, and let's define some variables, so VAR and equals, and we'll again, we'll grab that end slider.

Jake Bartlett (25:45):

Then we'll add a variable for the group index and I'll write the same expression we used before this property.property group three.property index. And the reason I chose three is because one level up is the trim pads. Two levels up is that invisible layer of contents. And the three levels up is taper a one, which is the index value that I need. So this property, property group three property index, then I'm going to define one more variable and I'll put this on the second line. It will name this master start, and this is going to be the master trim paths start value.

Jake Bartlett (26:33):

And then one last variable for the segment length. Now this segment length is going to be different than the actual master pants segment length. I don't want it to be based exactly on slider instead. I want it to be based on the trimmed portion of the master path. So whatever the length that segment is to find that all I have to do is subtract the start value of the master path from the end value, which is the same as the end value of the slider, which is why I pick whipped the end slider instead of the master end. So for the segment length, very simply, I just want to write end minus master start. So within this variable, I'm already referencing variables that I defined up here. That's an extremely powerful feature of variables. As long as the variable was defined before this line, I can already use it.

Jake Bartlett (27:26):

All right. So now that all my variables are defined, I'll actually write the equation. I want this end value to be the end value minus the segment length times the group index. So let me walk you through this. The end value master end set here, minus the segment length times the group index, and again, order of operations, it's going to do that multiplication before this subtraction, the segment length is this segment, the master paths segment length times the group index in this case, it's one. So end minus one segment length. Let's apply that to the end value.

Jake Bartlett (28:08):

And it's set to 50, which is exactly the same as the start value of the master trim paths. I'll set this taper a one to multiply. Just you can see this is perfectly overlapping. So there's no gap between the two lines. And if I adjust the segment length, you see that, that updates with it and the end value also controls that. So what happens if I duplicate this group? Well, it offsets, and this is segmented evenly. I can duplicate this a bunch and you see that all of these end values are spread out evenly and the segment length, proportionately spaces, everything out. So I hope you're getting excited. This is actually working. Let's delete the tapered groups and now we need to do the same thing for the start value and the variables can actually stay the same. So I'm just going to reuse this instance of expressionists.

Jake Bartlett (28:57):

The equation just needs to change slightly instead of the start value being based on the end value of the master trim paths, it needs to be based on the start value. So instead of end, I'm going to type in a master start and I'll apply that to the start value. Everything else is the same. Now, when I adjust the segment length, look at that the end value of the duplicate and the start value of the master stays at directly in the center there, and everything else gets spaced out proportionately. I can duplicate this a whole bunch and just like that, everything is perfectly spaced out and I'm able to adjust the length of that line and animate it exactly the way that you would expect a shape layer to behave. If I move the offset angle, now there's something I forgot to do. I did not set up the offset of any of the duplicates to be based on that, but that is an easy fix.

Jake Bartlett (29:52):

I'll just delete all my duplicates option, click on that offset expression, pick with the offset value. Now that's all linked up. I'll reduplicate this a bunch of times, and now I can use that offset control exactly as you would expect it to be used. So that's really awesome. We've already solved the first part of the problem, which was automatically dividing up that segment based on the number of groups. Now, obviously if I take off this multiply, this line looks exactly the same as it did when we started. So we need to solve the other half of the problem now, which is offsetting the stroke width. So take a deep breath and let's keep going. I'm going to delete all these duplicates again, I'll set this back to multiply just so we can see where the two lines are segmented and I'll collapse the trim paths for both groups. And I will open up the stroke one. This is where we're going to be working. And before I forget, I'm actually going to link some of these properties up. I want the color of all the duplicates to be driven by the color of the master stroke. So I will directly link that.

Jake Bartlett (31:04):

I don't think I'll need to mess with the opacity. So I'm going to leave that the way it is, but let's start writing the stroke with expressions. So I will select that and then shipped click into expressionists to load that property up. And we'll start by defining more variables. So let's start with the stroke width and pick whip, the stroke width slider. Then we're going to need to know the group index, which we can actually pull from the trim paths. That variable is going to be exactly the same. Let me find that group index copy and paste that in. And we're also going to need to know the total groups. So I'll define that variable, total groups equals, and I'll just pick whip the stroke width, and again, delete everything I don't need. So I need to know the duplicate groups, contents, the number of properties in there. So delete everything after that and type dot numb properties. And there's my total groups. So let's write the equation.

Jake Bartlett (32:12):

I want the stroke with, to be based on the slider's stroke with. So I'll type in stroke, width divided by the total groups, times the group index. So let's apply that expression to the stroke with, and it stays at 100. Now, again, that is because we did not account for the master group in our total groups. So I need to come back up to that variable, add plus one at the end, then update that expression. And now it has half the width let's duplicate this group a bunch of times, and it seems to be working kind of, it's not doing exactly what I expected. Um, this taper is going in reverse and the master group is on the wrong end. So the reason why this is happening is because even though this counts taper, oh one all the way up to taper 10, the index of structure starts at the top and goes down.

Jake Bartlett (33:11):

So every new duplicate is actually the index value of one. So taper 10 is now one nine is two all the way down the line taper one, which is here at the end, has the group index of 10. So what I need after effects to do is reverse that index order. And it's actually pretty simple. All I have to do is type in total groups minus the group index. And I need this to be calculated before it's multiplied by the rest of the equation. So to make that happen, I just have to put this within parentheses.

Jake Bartlett (33:47):

So what's happening here is going to take the total number of groups. So right now there are 10, actually 11 because of the extra and then subtract the group index from it. So if taper, oh one, it has an index value of 10. I'm going to take the total number of groups 11 and subtract 10 from it. And it's going to become group one and say, group seven, we'll take the total groups again, 11 minus seven is four. So that's essentially reversing my index order. So the lead, all these duplicates go to my stroke width and then reapply this expression. Now, if it makes them duplicates, look at that our stroke is tapering in the correct order. And if I have enough of these, I'll turn off the multiply that segmentation gets less and less noticeable. Now this is great, except that I have no way to control how thick or thin this taper is.

Jake Bartlett (34:49):

So we need to add one more piece of the equation into our expression. And I'll start by adding a new slider. I'll just duplicate the end and rename this taper out. Then I'll delete all these duplicate groups. And this last part of the equation is a function with an expressions called linear interpolation. And that sounds complicated, but once you understand it, it is an incredibly powerful tool. So again, I'm going to jump into a new composition. You don't have to follow along with this. It's just for a demo, but feel free. If you want to, I'm going to make a square again, and I'm going to add a slider control to it.

Jake Bartlett (35:30):

And this slider by default goes from zero to 100. Now let's say I wanted to change the rotation of this layer. So I'll bring that up. And rotation is measured in a value of degrees while the slider control is just a hard number. If I wanted this slider to control the rotation of this square, where zero was zero degrees, but 100 was one entire rotation that wouldn't work. If I directly linked them together. And I'll show you if I just link this to the slider, the slider set to 100, the re the angle of the rotation goes to 100. It doesn't go to one revolution because one revolution is actually a value of 360 degrees. Now, linear interpolation allows me to remap any range of values to another range of values. And I'll show you what I mean by that. Let's load this expression up and I'll define this as a variable. So VAR slider equals and then this code for the expression and it with a semi-colon and I'll come down and say linear parentheses. And then I need to tell the linear expression what values to look at. So I'm going to type slider.

Jake Bartlett (36:58):

So I target the slider control, and then I need four numbers. So I'm just going to put a comma zero comma zero comes zero comma zero. So we have four numbers. Uh, this is completely arbitrary right now, but I'll tell you what these mean. The first number is the input minimum value. And the second number is the input maximum value. So the range of numbers of that slider that we want to pay attention to. So I want the range to go from zero to 100. So zero is fine. And the second number will be 100.

Jake Bartlett (37:32):

The second set of numbers is the output range. So the minimum output and the maximum output. So when the slider is set to zero, which is the input, I want to interpret that number as this number, the output. So zero is actually fine when the slider is at zero, it should be at zero degrees. But when the output slider is at 100, I want the rotation to be 360 degrees. So I'll type 360 degrees there. And then I'll finish this off with the semi-colon. And just one more time, I'm going to run through this again, just so it's crystal clear, we're targeting the slider values and taking the range of zero to 100 and remapping that range from zero to 360. Let's apply that expression to the rotation. And now this is set to 100 and you see that we have a one full revolution.

Jake Bartlett (38:34):

And if I adjust slider, you see that it makes an entire rotation from zero to 100. So that's an example of what linear interpolation can do. Now, you can do a lot more than hard-coded numbers in the linear interpolation. You can use a variables, you can do equations, and you don't even have to use a full range of numbers. I could have said from a minimum input of 25 to say 75. And then if I reapply that to the rotation now, until this value reaches 25, nothing happens, but you see that as soon as it hits 25, it starts rotating. And then once it gets to 75 is when that rotation finishes its entire revolution. And then from 75 to a hundred, nothing happens. So it's an extremely powerful function. And it's a key factor in getting our tapers stroke to work the way that we want it to. So let's go back out to our tapered stroke and you can jump back into following along.

Jake Bartlett (39:39):

I'll load up the stroke with again, and now that we have this taper out slider, let's put that into our variable list. So VA VAR and we'll call it taper out, equals pick up the taper out semi-colon and then I'm actually going to take this equation and make it a variable. So I'm going to type VAR and name this stroke taper equals, and then this equation. So now anytime I type out stroke taper, it's just going to interpret that as this entire equation. Now our new equation is going to be a linear expression. So we start by typing. Oops, I had my layer selected. Let's get back to the stroke width.

Jake Bartlett (40:33):

All right, there we go. So linear parentheses, and I want to look at the taper out slider. So taper out comma zero to 100 comma stroke, width, comma, stroke, taper, and then end it with a semi-colon. Now, what does this expression say? It's saying take the range of zero to 100. And in this case I'm treating this kind of like a percentage. When the taper out is set to 0%, I want no taper. And when it's at 100%, I want the maximum taper. So the range of zero to 100% is remapped to the stroke width, which makes sense, because when this, when there's no taper, the duplicate groups should match the stroke with, at the master. And when it's at 100%, I want it to be the stroke taper, which is our equation that makes the taper work. Anything in between is automatically interpolated between those two values.

Jake Bartlett (41:43):

So this is making the expression extremely flexible, allowing us to control things with variables instead of fixed hard-coded numbers, let's apply this to the stroke width and duplicate the group of bunch. So now we have 10 total groups and now watch what happens when I adjust this taper outsider. I hope I just blew your mind because that is a working tapered stroke with full control of the taper. And if I duplicate this group a whole bunch and maybe lower the stroke wits to say 50, it starting to become really difficult to see that there are any segments in there. And I can go ahead and modify this path to say, be a curve like this, and then maybe change the segment link. So it doesn't take up the entire line. And this is a completely working tapered stroke. If I set some key frames, let's zoom in here, um, you know, just something really simple. We'll go from zero to 100 on the end value.

Jake Bartlett (42:50):

And then I will just easy ease these key frames really quickly. And let's Ram preview this layer animates exactly the same way that a single path would on a shape layer, but we have these added controls of being able to taper the stroke control, the segment length and the stroke width, all right here with lots of calculations taking place behind the scenes so that we don't even have to think about it. All we're left with are the animation controls that we're already used to using. And if I closed this path and maybe made this like a figure eight, then instead of animating the end value, I could animate the offset, you know, just put it at one.

Jake Bartlett (43:47):

And then I will Ram preview that. And we now have a looping tapered stroke going around this figure eight. So it's time to place your head between your knees. Take some deep breaths. We just built a freaking tapered stroke rig inside of after effects on a single shape layer using expressions. That is pretty incredible. Now, the way that I like to animate with this is usually with a low number of groups, usually around 10, and then once I'm ready to render, I'll really crank up the duplicates. Now, if I go ahead and do that, say there's 40 groups, you might notice that after effects is starting to slow down a little bit, uh, as I'm working with this. And it's just because with every group duplicate after effects have to recalculate all of these expressions that we wrote for every frame. So typically, like I said, I'll work with say 10 groups and that's generally quick enough.

Jake Bartlett (44:44):

And then once I'm ready to render, I'll just increase the duplicate count until that taper is no longer noticeable. And then you're ready to roll. Holy crap. That was a lot to take in. We just covered linking properties directly with expressions, defining variables, writing equations, determining index values of groups and counting the number of groups within a group and the linear interpolation. I know that that was a lot to take in. And if you're anything like me, you're probably pretty overwhelmed right now. But if you were able to follow along and you can grasp all the concepts that I covered, you are well onto your way to harnessing the power of expressions, to allow you to build things, to make animation the priority and make really complex intricate processes happen in the background. So you don't have to think about it. Now we can actually build a lot more functionality into this rig, but we're going to save that for the next lesson for now, give yourself a hand, pat yourself on the back.

Jake Bartlett (45:41):

That was an incredible amount of coding, especially if you're new to expressions. Now, if you got lost at any point and you really don't feel like going back and figuring out what went wrong, you can always sign up to be a VIP member of school of motion and download my project file for free. Then you can just use my project and take that tapered stroke rig that I just built and reuse it in any of your own projects. And again, I can't say enough good things about expressionists. We didn't even cover all of the amazing features that it allows, but I'm sure you noticed that seeing this color-coded syntax makes looking at these expressions much easier than working in these tiny little boxes with no highlighting at all. It'd be much more difficult to catch mistakes inside of this box. So again, check out the link to expressionists on this page, if you're serious about getting into writing your own expressions. All right. That's enough. Thank you so much for sticking with me through that very long process. Now get out there and start making some tapered stroke animations and post your work online. Let us know what you make with this rig. Thanks again, and stay tuned for the next lesson where we're going to add more features to this rig using some more types of expression controllers.

Success! Check your email (including spam folder) for your download link. If you haven't yet confirmed your email with us, you'll need to do that one time.
Oops! Something went wrong while submitting the form.
No items found.
No items found.