Search

After Effects Expressions Simplified

by Andrew Kramer
Creative COW Magazine : Business Secrets & Success Issue
After Effects Tutorial from The Creative COW Magazine


Creative COW Magazine presents After Effects Expressions Simplified



Andrew KramerAndrew Kramer
Murrieta California, USA

©2007 Andrew Kramer and CreativeCOW.net. All rights reserved.

Article Focus:

In this After Effects tutorial from The Creative COW Magazine, see through the confusion of After Effects Expressions with just a few simple steps.


Using expressions, anyone can link filters and transformations, as well as many other parameters, to drive powerful new effects and streamline job processes. The operative word here is `anyone' - and in this case, I do mean just about anyone. Don't let the idea of expressions scare you.

Admittedly, After Effects expressions can be complicated but for the everyday After Effects user, powerful expressions are well within reach and they are easier than you might think. A simple example of using expressions lays in the pickwhip function.

The pick-whip allows users to easily create expressions that can accomplish techniques which would take a lot more work using After Effects' other methods.

Suppose I'm doing some motion graphics and I want 20 pictures to all be tinted a certain color. Easy enough, I can tint one and then copy and paste the effect to each of the 19 other photos. But if you're like me, you are constantly making changes and don't want to keep copy and pasting all of these changes so that your images look consistent. To solve this problem, we're going to use expressions to link parameters together without any actual scripting, just by using the pickwhip.


A SIMPLE EXPRESSION:

Here's how to control the tint color for multiple layers at once:

1. Add the tint effect to your first layer or your `control' layer.

2. Change the `Map Black To' (see Figure 1 below) color to Red.

3. Then on your second layer, add another tint effect.

4. Now Alt-Click (CMD-Click on Mac) on the Stopwatch of the `Map Black To' color and the timeline window will expand.

5. A text box will appear and while everything is still selected, mouse over to the left where you see the expression functions.

6. The one that looks like a swirl is called the Pick Whip. Click and drag it to `Map Black To' color parameter on the control layer and let go. You may have to expand the control layer properties.

7. Now copy the 2nd layers tint effect and paste it to any additional layers that need to be linked. The code is essentially hard coded so you do not need to repeat the steps.

8. Then change the control layers tint color and watch as all the pictures change to the same color.


Expressions Example
Figure 1

Expressions like this are great for keeping everything in sync and making multiple changes at once. Using the pick whip is a great way to link similar effects. But what about linking different effects together?

Let's study the original example, linking the blur amount to the opacity to create a smooth fade-in or out; essentially we want to change the opacity of a layer and drive the blur amount at the same time.

1. Add the fast blur effect to your layer

2. Alt-click the stopwatch for "blurriness"

3. Type: linear(transform.opacity,0,100,50,0)


Now a month ago if I had seen this expression I would have thrown my hands up and just made extra keyframes. But let me explain the last line in a way that has helped me to understand expressions.

linear(transform.opacity,0,100,50,0)


Inside the parenthesis are five values separated by commas. The first is the specific property; After Effects has to know what is to be considered - in this case, the transform.opacity. Remember you can pick-whip any parameter to automatically type a parameter's property name.

The next two values indicate the parameter range to be considered, in this case the opacity amount from 0-100.

The last two are what values are to be executed - or in this case the blur amount. In other words the opacity of 0-100 generates the values for the blur of 50-0. Why 50-0 and not 0-50?

When the opacity is at 100 percent, we want the blurriness to be 0 and when the layer is completely transparent we want it to be blurred by 50. So if I wanted more blur I might use this expression...

linear(transform.opacity,0,100,200,0)


...increasing the max blur to 200 or dropping it to as little as 20.

linear(transform.opacity,0,100,20,0)


`Linear' is a common method in which to remap these values across time so that the change is gradual but direct. Using this method you are able to link non-uniform values like the opacity with a layer's rotation, where rotation values span from 0-360 degrees compared to opacity which is 0-100.

If you were to use an expression on the rotation it might look something like this:

Linear(transform.opacity,0,100,0,360)


Using this expression, as the layer fades out, it will also rotate 360 degrees.


VARIABLES

I remember back in high school when I had to figure out what `y' equaled if y=x+4 and x=6. Well, for those of you that have been out of school for a while, y=10. If I remember correctly, they referred to these as "variables." One way to think of a variable is a value that is "to-be-determined." In other words, a variable is a dynamic value or number based on specified or notyet- specified values. Once all the non-specified values are determined, the variables value is generated and integrated into the expression or simply executed. I may not have paid much attention in math class but some of it has come back to me.

Using variables with expressions allows After Effect to create incredibly more effects.


AN EXAMPLE THAT MAKES USE OF VARIABLES

An example of using variables is found when creating a realistic camera shake. This effect, which we'll start and later modify with a variable, is best implemented through expressions. Possibly the most famous simple expression is:

wiggle(A,B)


When applied to the position of a layer, this expression will create random values - or in this case, random movement. In this example, wiggle is the function and A is the number of changes per second, with B representing the distance of change. wiggle(5,10) when applied to the position of layer would cause the position to change direction 5 times per second and move 10 pixels at a time.

The Wiggle function is a great way to add random movement to layers, creating more realistic animations - but what if I wanted to generate an earthquake that comes and goes gradually? Currently, this expression uses exact values that don't change but using a variable that is linked to a slider control we can keyframe this earthquake effect over time.

If you've tried to use an effect from the expression controls category, you may have noticed that nothing happens; you may have thought something was wrong and deleted it. In order to work properly, these expression controls must be linked to actual operators like position or opacity.

So let's get started, we want to create a camera shake on the position of a layer...

1. Alt-click on the stopwatch to set layers position

2. Type: wiggle(5,10)


Notice the layer shakes a bit. Let's continue:

3. Add the effect "Slider Control" from the expression control category in the effects list

4. Rename the effect in the effects control to "shakeAmount"

5. Return to the position expression and change the number 10 to shakeAmount


It should now read: wiggle(5, shakeAmount)

AE Expressions
Figure 2


ADDING THE VARIABLE

Now we need to define the variable so After Effects knows what is being referenced by the word "shakeAmount".

6. above the line with the wiggle script [or below] type: shakeAmount =

7. Then with the blinking type cursor positioned after the `=' drag the pickwhip to the shakeAmount slider in the effects controls. [or timeline]

8. The property info should print something like this:
shakeAmount = effect("shakeAmount")("Slider")

9. Then add a semicolon to the end to define it as a variable.
shakeAmount = effect("shakeAmount")("Slider");
wiggle(5, shakeAmount)


Now if you change the value in the effects control to 25, you'll see the clip shake and the position value should show up in red (instead of blue), indicating an expression is driving the value. So if you haven't guessed, the shakeAmount variable is getting the value from the shakeAmount slider - and the shakeAmount variable is defining the wiggle amount.

Now you can easily keyframe the amount of shake using the slider control. You may also change the number 5 to create rapid or smoother movement. But when you're tired of going back into the expression editor to make changes to the frequency you may want to set up another variable.

Follow the steps above with a new Slider control named `frequency' and add it to the current expression to create this:

shakeAmount = effect("shakeAmount")("Slider");
frequency = effect("frequency")("Slider");
wiggle(frequency, shakeAmount)


Now you can keyframe or adjust both expression sliders dynamically without editing code. But wait, there's more! You now have it shaking, but couldn't it also rotate?

Simply copy everything in the `position' expression and paste it into the rotation property - everything is already linked to the sliders, so we'll use the current variables to drive a rotation and the position.

Now you may notice that the rotation expression is creating relatively large values - turning a thing 15 or 20 degrees is jarring - but if you lower the shake amount to soften the rotation, the layer's position no longer shakes enough. If the shakeAmount slider is set to 20 we're probably getting rotation changes around 20 so we need to make this value lower but we don't want to make new sliders. Here is an easy solution; take the current expression and divide it by 10.

Copy expression from the position:

shakeAmount = effect("shakeAmount")("Slider");
frequency = effect("frequency")("Slider")
wiggle(frequency,shakeAmount)


Paste to rotation and simply divide by ten by adding this:

/10


shakeAmount = effect("shakeAmount")("Slider");
frequency = effect("frequency")("Slider")
wiggle(frequency,shakeAmount)/10


Now when a value of 20 is created by the wiggle expression it is then divided by 10 and now this new value is executed so instead of rotating 20 degrees it only rotates 2.

Imagine linking multiple layers to one control layer so that you could globally make adjustments to entire compositions with variables and various expression controllers. Once you get beyond the basic fundamental uses of expressions, start thinking about creative ways to drive unique effects with math equations and random movement.

I've created some expression based effects that help to simplify creating light sabers as well as generating three dimensional falloff and even an accurate frame rate converter for PAL to NTSC conversions as well as 29.97FPS to 24FPS or vise versa.

For me it was Dan Ebberts on the Creative Cow forums that opened my eyes. I've always been a visual person and was told that you're either a creative person or a technical person. With Dan's help the concept of expressions is no more complicated than the things I already do. And while I'll never be an expert code writer I have found creative ways to use expressions to streamline unique effects. I've also learned one more thing, writing code is creativity squared.

If you need help with expressions, check out the Creative COW's After Effects Expressions forum, dedicated to those wanting to dig deeper into the power of After Effects expressions.


Andrew KramerAndrew Kramer is a visual effects artist and filmmaker. He is one of the leaders you'll find in Creative COW's popular After Effects forum, as well as our Photoshop forum. As a Creative Cow contributing editor, his free tutorials have been downloaded hundreds of thousands of times and in them he has demonstrated popular effects like creating the Ipod Nano Light Streaks and Simulated 3D reflections in AE.

Andrew is also the creator of Serious Effects & Compositing, Creative Cow's best selling video training DVD for After Effects, one of the Creative Cow Master Series training DVDs available at: www.creativecowtraining.net



Find more great Creative COW Magazine articles by signing up for the complementary Creative COW Magazine.


More From Business Secrets & Success Issue:
Adobe Production Studio Comes to the MacWindows Hardware & Software
Adobe Production Studio Comes to the Mac
Feature
Big Changes for the COW in 2007COWmunications feedback
Big Changes for the COW in 2007
Editorial
Communicating Ideas That SellBusiness & Marketing
Communicating Ideas That Sell
Tutorial
Capturing Live Music for VideoEvent Videographers
Capturing Live Music for Video
Tutorial
Microsoft Expression Studio: Microsoft's Designs on DesignersWindows Hardware & Software
Microsoft Expression Studio: Microsoft's Designs on Designers
Review
Streamlining the Review and Approval Process with Adobe Premiere ProAdobe Premiere Pro
Streamlining the Review and Approval Process with Adobe Premiere Pro
Tutorial
How Can I Make Money In A Glutted Market?Business & Marketing
How Can I Make Money In A Glutted Market?
Business
Get What You Need While Shooting InterviewsMotion Graphics - How Do I?
Get What You Need While Shooting Interviews
Tutorial
P2 Tapeless Workflow Helps Rewrite HistoryPanasonic HVX - HPX (P2)
P2 Tapeless Workflow Helps Rewrite History
Review, Feature
Finding the Way to Real Money - Full TimeBusiness & Marketing
Finding the Way to Real Money - Full Time
People / Interview, Business
MORE




More From Adobe After Effects Expressions:
AE Quick Tips #4: Copy Expression OnlyAdobe After Effects Expressions
AE Quick Tips #4: Copy Expression Only
Tutorial, Video Tutorial
Animating Text Reflections with ExpressionsAdobe After Effects Expressions
Animating Text Reflections with Expressions
Tutorial
Swinging A Realistic ChainAdobe After Effects Expressions
Swinging A Realistic Chain
Tutorial
Building and Animating a CG SnakeAdobe After Effects Expressions
Building and Animating a CG Snake
Tutorial, Video Tutorial
Using Expressions to Create a Volume MeterAdobe After Effects Expressions
Using Expressions to Create a Volume Meter
Tutorial, Video Tutorial
A better Grid using expressionsAdobe After Effects Expressions
A better Grid using expressions
Tutorial
MORE


  Business Secrets & SuccessAdd Comment
Creative COW Magazine is copyright 2006 - 2009 by Creative COW®. All rights are reserved.
No reprint rights are granted except to educational institutions such as universities, colleges,
art academies and other training academies. All other rights are expressly reserved.
[Top]