My 5 Favorite Expressions

Posted on: October 20, 2009
20 comments so far (is that a lot?)

I realize that expressions can be daunting, and some would rather copy and past useful code rather than learn the language. That’s cool with me. Therefore, I’d like to share with you my 5 favorite expressions. These are expressions I use in just about every project, and I consider them to be incredible workflow enhancements.

Download them as FFX presets for AE CS3 here.

Are you looking to learn more about After Effects Expressions? Check out my complete training series on the topic in the graymachine store.

1. Intertial Bounce

Essentially, Inertial Bounce creates a bouncing motion of any parameter from one keyframe to the next, based on its velocity. Being that true “velocity” includes the vector (or traveling direction in 3D space), the bounce happens in whatever direction the object is traveling. This also accounts for scalar or array values, so you’ll find that this expression works just as well on 2D rotation as it does on 3D position. It’s very cool!

This expression is a bit of a community effort. The seeds were certainly planted by the great Dan Ebberts, and then a modified version was posted on mograph.net. Although I’ve made a slight modification to it to make it a little more user friendly, it’s nothing that I will lay claim to as my own code. Nonetheless, it’s a great helper and I use it all the time.

Modify “amp” for the amplitude or how much bounce is present. The variable “freq” is the frequency, or how frequently the bounce occurs. The “decay” is like a friction or mass setting, a higher value means a shorter decay over time.

amp = .1;
freq = 2.0;
decay = 2.0;
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time){
n--;
}}
if (n == 0){ t = 0;
}else{
t = time - key(n).time;
}
if (n > 0){
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{value}

2. Autofade

This is nothing brilliant, but it is something I wrote and use all the time. You’ll also find something similar in the After Effects preset “Behaviors” called Fade In + Out, which uses the Solid Composite effect and a custom interface. But, I like a simpler version that I use on Opacity.

This is a slightly enhanced version that I’d revamped since I posted it in the “Auto Slideshow” presets and added the option to use markers. If there are no markers, the transition variable is used (where is says “transition=20″, this is in frames.) If there are *2* markers, the first marker is used for end point of the fade in, and the second marker is used to define the start of the fade out.

//Autofade: Add to opacity
transition = 20;       // transition time in frames
if (marker.numKeys<2){
tSecs = transition / ( 1 / thisComp.frameDuration); // convert to seconds
linear(time, inPoint, inPoint + tSecs, 0, 100) - linear(time, outPoint - tSecs, outPoint, 0, 100)
}else{
linear(time, inPoint, marker.key(1).time, 0, 100) - linear(time, marker.key(2).time, outPoint, 0, 100)
}

3. Snap Zoom In/Out

This is a cool expression to use on text. It creates a “snap” zoom on the in and out of the layer by modifying scale.

//Snap zoom in and out: apply to scale
snapScale = 300; //percent of scale to zoom

trans = 4; //  transition time in frames
trans = trans * thisComp.frameDuration;
inTrans  = easeOut(time, inPoint, inPoint + trans, [snapScale,snapScale], [0,0]);
outTrans = easeIn(time, outPoint, outPoint - trans, [0,0], [snapScale, snapScale]);
value+ inTrans + outTrans

If you prefer to use Z space position instead of scale, try this one:

zoom = 5000; //distance to zoom
trans = 4; //  transition time in frames
trans = trans * thisComp.frameDuration;

inTrans  = easeIn(time, inPoint, inPoint + trans, [0,0,zoom], [0,0,0]);
outTrans = easeOut(time, outPoint, outPoint - trans*2, [0,0,0], [0,0,zoom]);
value+ inTrans - outTrans

4. Y Axis Jitter

This is from Lesson 5 of my expressions series. This creates a random jittery motion in the Y axis. You can modify probability to make or less jitter, and the pos variable to define how large the jitter is.

// Y Axis Jitter
probability = 8 ;  //higher is less likely
pos = 50;
val  = random(-probability-2, 1);
m = clamp(val, 0, 1);
y = wiggle(10, pos*m)-position;
value + [0, y[1]]

5 . toComp

This one you’ll have to watch a short tutorial for here, and you can read a lot more about it at motionscript.com. The idea is that you can apply the equivalent 3D location to any 2D location. This might not sound exciting. But, think of all the 2D parameters out there, like lens flare location, Shine source, beams, etc. It is probably my most commonly used expression.

But, the basic idea is this:

layer = thisComp.layer("Null 1")
layer.toComp([0,0,0])

Note: I intentionally left off the semicolon, as you techinically don’t need it in this case. Therefore, all you need to do is pickwhip your layer where the “layer =” variable is.

20 Responses to “My 5 Favorite Expressions”

  1. Tweets that mention graymachine » Blog Archive » My 5 Favorite Expressions -- Topsy.com Says:

    [...] This post was mentioned on Twitter by Harry Frank, di1ca_design. di1ca_design said: RT @graymachine: New post: My 5 Favorite Expressions, includes download link for CS3 presets. http://bit.ly/1htw1V [...]

  2. John Dickinson Says:

    Thanks Harry, these are very handy.

  3. Steve Kirby Says:

    Thanks Harry, these are worth remembering.

    Here’s some animation preset’s I made for inertial bounce (Beaver’s version of it):
    http://www.stevekirby.co.uk/files/InertialBouncePresets.zip

    There’s more information about them on the mograph post:
    http://mograph.net/board/index.php?showtopic=13954&st=40

  4. Harry’s Top Five Expressions | Motionworks Says:

    [...] Harry Frank recommends these 5  Adobe After Effects expressions, then you know you need [...]

  5. Colin Says:

    cool list!

    I always stress ten cool basic things – I’m shocked how often advanced artists don’t use just a simple expression to help them do stuff.

    1. Map to Time
    2. Mute keyframes
    3. Use Expression effects (sliders, knobs, etc)
    4. Do Basic Math
    5. Interpolate values using linear
    6. Layer Space transformations
    7. Wiggle
    8. using index to get unique ids
    9. using strings in the text source
    10. sin waves

    c

  6. uberVU - social comments Says:

    Social comments and analytics for this post…

    This post was mentioned on Twitter by hashaftereffect: EXPRESSIONS| My 5 Favorite Expressions, includes download link for #AfterEffects CS3 presets. http://bit.ly/1htw1V via @graymachine…

  7. Benjamin Eshagpoor Says:

    Thanks, man! I use the toComp expression in almost every project as well. Looking forward to looking at the others!

  8. monike Says:

    thanks a lot for this useful collection.

  9. John Says:

    Thanks Harry this is a great resource – been using expressions for a while, learning bits here and there. The autofade one will save me hours!

  10. admin Says:

    Hey steve. Thanks, I forgot to put that link to the original mograph post. I had asked Alan (Beaver) if he wanted credit for that expression, and he said “No way”. So, but it’s still good to reference the original. That’s the place I always used to go to grab that expression, and I finally got around to making a preset for it. It just always bugged me that the variables were in the middle of the expression.

  11. Johnny Says:

    I will explore this expression and see what they do. I’m not really familiar with them or how they work.
    But will try them. THANKS!

  12. tendest Says:

    Thanks ,dude

  13. Suztv Says:

    You forgot one of the most basic and probably the most useful of all expressions:

    loopOut(“Cycle”,0)

    This lets you loop out keyframes on your timeline – extremely useful for long animations or comps or when you need an action to continue throughout the piece. I love using it with particles, pre-existing footage that is time-remapped, position, opacity… You name it. You can change the expression from endless to looping however many times by changing the “0″ to whatever number of times you need the item to loop. It sure beats copying and pasting keys!

  14. admin Says:

    Thanks Suztv. Coincidentally, I am using this one a lot on the current project I am working on. It is definitely useful, and definitely would be in my next top 5.

  15. Klas Says:

    Thanks!!
    I´m one of those guys that can´t get my head around expressions :)
    I use wiggle and random a lot but that´s about it.
    Any suggestions on how to understand the language of expressions?

    //Klas

  16. admin Says:

    Check out :

    http://www.graymachine.com/2009/04/after-effects-expressions/

    You can watch Lesson 1 for free!

  17. 40 great AE tutorials | Detroit Digital Media Says:

    [...] Visit Tutorial [...]

  18. Jan Says:

    very handy Harry :-) thank you!!!

  19. 5 favorite expressions for After Effects, courtesy of graymachine | LXB | LESTERBANKS Says:

    [...] lists his 5 favorite expressions for After Effects, including Intertial Bounce, Autofade, Snap Zoom In/Out, Y Axis Jitter, and toComp. You can [...]

  20. geoff brown Says:

    thanks very much.
    i especially appreciate the toComp script. very useful and fresh to me. BTW gorgeous site, cool clean and crisp.

Leave a Reply

Bad Behavior has blocked 393 access attempts in the last 7 days.