Welcome! My name is Alan Shisko, and I'm a freelance motion graphics artist working out of Toronto, Canada. I've been very lucky in my career to have had many inspiring teachers, and decided to start this blog to give back to the community that has enriched me both technically and aesthetically. Perhaps my words and images will inspire you to do the same! If you wish, take a minute to view my demo reel at Shisko.com, or view a comprehensive gallery of my past work Here.


Monday, January 08, 2007

My Favourite Expressions



IMPORTANT: READ THIS FIRST!
Blogger doesn't seem to allow for really long, uninterrupted lines of text (ie. long expressions), so you'll find that the code below is 'cut off'. When copying the code, make sure you begin the selection at the start of the expression (first line) and drag to select everything to the end of the last line: all will then be copied. What I'm saying is, don't copy single lines: you might miss something!

Expressions are a powerful but rarely used toolset that can drastically simplify animating in After Effects. Based upon the Javascript programming language, I suspect that 'artists' tend to shy away from anything resembling the BASIC that many of us were forced to learn way back in the dark high school days of DOS, but I think you'll find it's worth it to dig a bit deeper and figure out the rudiments of expressions.

I, personally, feel that I have a moderate understanding of expressions. I use the 'pickwhip' a lot in After Effects to link parameters for layers together (general rule of thumb: if you ever copy and paste keyframes, use expressions instead) and can whip something up from scratch if need be. That said, I can't claim intellectual ownership of the two expressions that I use the most, because the math was a tad bit beyond me. Read on, however, to see how you can use these expressions in a real-world project.

The first expression we're going to look at allows you to make an After Effects layer in a 3d composition 'one-sided'. The idea is this: if you have a layer facing the camera, you'll see it. But once the camera moves 'behind' the layer, instead of seeing the same layer but backwards, it'll disappear. This one was written by Michael Natkin of Adobe and is applied to the 'opacity' parameter of a 3d-enabled layer layer in a composition with a camera...

a = toWorldVec([0,0,1]);
b = thisComp.activeCamera.position - toWorld(anchorPoint);
c = dot(a,b)/length(b);
if (c > 0) 0 else value

Orbit the camera around the layer and you'll see it appear and disappear.

The second expression is a 'bouncy' effect that is applied to the scale parameter of any layer (doesn't have to be 3d), and was created by everyone's favourite polymath and all-round helpful guy, Dan Ebberts. You can modify the final size, duration and 'stickiness' of the bounce by altering the variables in the expression, and the only caveat to this one is that you can't tell it when to start: it always begins at 0:00, so some pre-composing might be necessary to use it in your composition.

(NOTE: see tip at top of post regarding copying/pasting this expression)

final_scale=100;
bounce_duration=3; //lower number is longer
bounce_speed=10; //lower number is slower
x=final_scale*(1-Math.exp(-bounce_duration*time)*Math.cos(bounce_speed*time));
[x,x]

So, there's some neat-o math for you, but how might it be used in a real-world production environment? I had a recent project that called for a 'light, hip, kinetic' look, and I ended up using both of these expressions a great deal to both lend visual appeal to the piece and to drastically simplify the project design and workflow. Take a look at the finished animation here, and then to get a visual overview of both the expressions and how they were used in the project, take a look at this video tutorial overview.

UPDATE: Regarding the necessity to pre-compose the 'bouncy' expression, Kasper sent me this note:

Hey there...
i was just watching your tutorial with the "bouncy" expression and one of the guys here at work did a little addon to the expression so that your layer don't have to be at 0:00:00 so no more pre-composing. here is the expression:

(NOTE: see tip at top of post regarding copying/pasting this expression)

final_scale=100;
bounce_duration=3; //lower number is longer
bounce_speed=10; //lower number is slower
x=final_scale*(1-Math.exp(-bounce_duration*(time-inPoint))*Math.cos(bounce_speed*(time-inPoint)));

[x,x]

Hope that it is useful (ed. note: sure is!)

UPDATE #2: Kasper is one clever fellow... read on and see how he and his colleagues have taken away the need to set the final scale in the expression...

So we updated the "bouncy" expression again. It was becoming a problem that you couldn't keyframe the scale of the layer because "final scale" was set in the expression. So you always had to use a null to keyframe the scale if you wanted to do some more scaling to the layer. But my buddy here at work updated the expression so that the scale is no longer defined within the expression. You now just set the scale as always within the "transform" properties. So that way you can now keyframe the scale.

(ed. note: it might not be apparent that this actually works. If you're at the start of the layer with the expression applied, the scale parameter will say "0". If you click and drag on the scale number, you can change the scale but when you release the mouse button it reverts to "0" again. No fear: it'll scale to the size you indicated when you actually run the expression.)

Here is the updated expression:

(NOTE: see tip at top of post regarding copying/pasting this expression)

bounce_duration=3; //lower number is longer
bounce_speed=10; //lower number is slower
x=value[0]*(1-Math.exp(-bounce_duration*(time-inPoint))*Math.cos(bounce_speed*(time-inPoint)));
[x,x]

8 comments:

John Dickinson said...

Hey Alan,
Nicely done. I'm going to post a link to this on Motionworks if that's cool.

JD

tom said...

Just wanted to thank you for another insightful and inspiring tutorial.

Jonathan Hart said...

Thank you for your wonderful posts. You are an inspiration to an aspiring mographer like myself... more more more!

Simka said...

Nice work,great tutorial but I have a problem with expression
final_scale=100;
bounce_duration=3; //lower number is longer
bounce_speed=10; //lower number is slower
x=final_scale*(1-Math.exp(-bounce_duration*time)*Math.cos(bounce_speed*time));
[x,x]
After Effects report error.To be honest I'm kind of scare to use expression but I want to learn.Can you help me out with this one?Please!

Alan Shisko said...

Simka,

It works great here... are you sure that you applied it to the 'scale' attribute? Here's the easy way to do it:
-copy and paste the expression.
-Select the layer that you want to 'bounce' in your timeline.
-Hit the "s" key... this opens up the 'scale' parameter.
-If you're on a PC, hold down the 'alt' key and hit the little stopwatch icon beside the word 'scale'... this applies a 'neutral' expression to 'scale'. If you're on a mac, I believe you hold down 'option' (beside the apple key) and hit the stopwatch.
-Select the text in the the resulting little expression text editor and 'paste' the expression.
-Should work!

Alan Shisko said...

Whoops: mistake in the above note: line 1 should be just 'copy the expression', not 'copy and paste...'

Jonas Hummelstrand said...

Hi Alan,

Thanks for sharing your favorites!

index.php said...

My fave expression would have to be wiggle. It adds Wiggly Wiggly fun to anything it touches.