All Articles After Effects
After Effects: Expressions Basics
Richard Lainhart on Tue, February 14th 0 comments
While Expressions in Adobe After Effects can intimidate many a user, there's many reasons to embrace them fully and Richard Lainhart shows us how friendly they can be.

Expressions in After Effects are a powerful but rather scary feature that even many experienced AE artists shy away from, simply because expressions look like computer code. Well, they are computer code, of a sort - in fact, expressions are based on Javascript, much used in Web programming, and like all computer languages and scripts, expressions have a strict syntax. If you don't follow the syntax, the code won't execute, and many find that syntax obscure and unintuitive. 

However, After Effects has tools that help you create useful expressions without having to know the proper syntax or understand the underlying code. In this article, we'll take a brief look at Expressions and show you how to use a simple expression to create an automatic VU meter that appears to respond to an audio track.


Step 1 - What Are Expressions?

An expression in After Effects is a modifier applied to a specific animation property, like Rotation, to either link that property to the values in another property, even in another layer, or to automatically animate that property without using keyframes. 

For example, let's make a simple analog loudness meter in After Effects: create a new comp about 5 seconds long, and add a new long, narrow Solid to it, called Needle - I've made mine 20 pixels wide and 200 pixels high:

Needle


Double-click the solid to open it in its Layer window, grab the Pan Behind (Anchor Point) tool, and shift the anchor point for the Needle down to its bottom edge, so the Needle will rotate around its end instead of its middle.


Step 2 - The Wiggle Expression

Now at this point we could add some random Rotation keyframes so the needle rotates around, but a much faster and more flexible way to do that is to use a Wiggle expression, which will automatically rotate the needle randomly.

So, type R to solo the Rotation property for the Needle, then Option-click the Stopwatch for the Rotation property (Option-clicking the stopwatch will add a new expression). When you do, you'll see that the property values for Rotation turn red, meaning they're controlled by an expression, and you'll also see a line of highlighted text in the Timeline saying transform.rotation:

Rotate it


You'll also see some additional interface objects appear under the red property values. Now, that "transform.rotation" text is just a placeholder, reminding us that whatever expression we add will be applied to Rotation. Next, with that text still highlighted, click on the Expression Language Menu arrow that appeared below the red Rotation values when you added the expression and choose Property > wiggle(freq, amp, octaves = 1, amp_mult = .5, t = time). You'll then see that whole "wiggle" line replace the "transform.rotation" line.

setting the wiggle values


If you click away from that text, you'll get an unhelpful error message from After Effects, saying that the expression is disabled. Don't worry about that for the moment; here's what it means.

The words that you see in the parentheses after "wiggle" are the possible arguments, or modifiers, that the wiggle command can take. "Freq" (frequency) refers to the rate of the wiggle, "amp" (amplitude) to the amount of wiggle, and so on. 

For this wiggle expression to work, we have to replace those argument names with actual numbers - as it is, the arguments are just reminders of what can be modified.That's what the error is referring to - that the arguments have to be replaced with real values. In this case, we're going to remove the last three arguments and just modify the first two, which will give us a simple randomized animation.

So, put your cursor inside the parentheses and select and delete everything between them, so you just see this: wiggle().  Then type in 5, 20 inside the parentheses. What we've just done is replace the first two text argument's actual numbers - the position of the numbers, and the comma between them, tell wiggle that the first number is to be applied to freq  - that is, the rotation will wiggle randomly 5 times per second for the length of the comp. The second number 20 in the amp position means that the value of the Rotation will vary plus and minus 20 units (in the case of Rotation, plus and minus 20 degrees). 

Your expression should now look like this:

The expression


And your animation should look something like this:


The wiggle expression randomly rotates the Needle around in a way that simulates a VU meter responding to audio levels. To change this response, just change the two numbers inside the parentheses - a higher first (freq) number will make the needle jitter more rapidly; a higher second (amp) value will cause the needle to swing in a wider arc. 

As you can see, keyframing something like this would require many keyframes, and changing that keyframed motion after the fact would require a lot of tweaking. By using an expression instead, simply changing a couple of values will change the animation completely, and make it much easier to adjust the effect.

Well, that's a basic introduction to expressions. We're going to follow this up with another tutorial on linking this meter to the real amplitude values in an audio track, so stay tuned for that. In the meantime, as always, experiment and have fun!

Continue the joinery with After Effects Expressions in Part 2.

Comments (0)

You must be logged in to comment.

Feedback
Course Advisor
Don't Know Where To Start?
Ask A Course Advisor
Ask Us!
Copy the link below and paste it into an email, forum, or Facebook to share this with your friends.
Make money when you share our links
Become a macProVideo.com Affiliate!
The current affiliate rate is: 50%
Classes Start Next Week!
Live 8-week Online Certification Classes for: