- Online resources for expression examples
- Expression example: Make a layer revolve in a circle
- Expression example: Rotate the hands of a clock
- Expression example: Position one layer between two others
- Expression example: Create a trail of images
- Expression example: Create a bulge between two layers
- Expression example: Fade opacity of a 3D layer based on distance from camera
- Expression example: Make a 3D layer invisible if facing away from camera
- Expression example: Flip layer horizontally if facing away from camera
- Expression example: Animate scale at each layer marker
- Expression example: Start or stop wiggle at specific time
- Expression example: Match camera focal plane to another layer
Many of the examples in this section are based on expressions provided by Dan Ebberts.
Online resources for expression examples
Dan Ebberts provides example expressions and tutorials for learning how to work with expressions on his MotionScript website. For example, Dan provides an excellent page about collision detection.
Trish and Chris Meyer provide a series of articles about expressions on the ProVideo Coalition website. These articles contain many useful examples.
Colin Braley provides a tutorial and example project on his website that show how to use expressions to make one layer repel others in a natural-seeming manner.
The AE Enhancers forum provides many examples and much useful information about expressions, as well as scripts and animation presets. In this post on the AE Enhancers forum, Paul Tuersley provides a tutorial and example project that show how to use expressions to animate several layers in a swarm.
Rick Gerard provides an example on his website that demonstrates rolling a square object along a floor so that the sides stay in contact with the floor plane.
Carl Larsen provides a video tutorial on the Creative COW website that demonstrates how to use expressions and parenting to relate the rotation of a set of wheels to the horizontal movement of a vehicle.
Marcus Geduld provides some examples from his book, After Effects Expressions, on the Focal Press website. In the "String Manipulation" section, Marcus shows how to use basic JavaScript to manipulate the text in the Source Text property of a layer. He even shows how to use an array of strings so that a layer's Source Text property can be set to a specific word from a list. In the "Physical Simulations" section, Marcus shows how to use expressions for orbits, bounces, jiggles, and collision detection.
Chris Zwar provides an example project on his website for automatically arranging still images or videos into a grid (like a video wall). You can easily adjust position and spacing with sliders that are connected to a system of expressions. There are three compositions in the project—one for stills, one for videos, and one to create an auto-storyboard in which a video is sampled at user-defined intervals and aligned into a grid.
JJ Gifford’s website provides several example projects that demonstrate how to use expressions.
Rhys Enniks provides a video tutorial on his website in which he uses expressions and multiple text animators and range selectors to animate text as if it is being typed onto a computer screen.
Maltaannon (Jerzy Drozda, Jr.) provides a video tutorial on his website that shows how to use expressions to create a volume meter using the results of the Convert Audio To Keyframes command.
Harry Frank provides a tutorial on his graymachine website that shows how to use expressions to read data from an external text file.
Expression example: Make a layer revolve in a circle
You can create an expression without using properties from other layers. For example, you can make a layer revolve in a perfect circle.
Expression example: Rotate the hands of a clock
You can use the pick whip to link rotation values between layers to animate the hands on a clock—as the hour hand moves from hour to hour, the minute hand rotates the full circumference of the clock face. This type of animation would take a long time to create if you had to set each keyframe for both hand layers, but with the pick whip, you can do it in a matter of minutes.
Guy Chen provides a simple project on the After Effects Exchange on the Adobe website that takes this idea further, connecting the rotation of the minute hand and hour hand of a clock to the rotation of the second hand.
Harry Frank provides a clock project on his graymachine website, in which the movements of the hands are connected to an Expression Controls (Angle Control) effect on a null layer that controls the time. (See Expression Controls effects.)
Expression example: Position one layer between two others
This example expression positions and maintains one layer at a balanced distance between two other layers.
Expression example: Create a trail of images
This example expression instructs a layer to be at the same position as the next higher layer in the Timeline panel, but delayed by a specified amount of time (in this case, 0.5 seconds). You can set similar expressions for the other geometric properties.
All layers follow the same path, and each is delayed 0.5 seconds from the previous.
Dan Ebberts provides more examples and techniques for creating trails of images on his MotionScript website.
Expression example: Create a bulge between two layers
This example expression synchronizes the Bulge Center argument of the Bulge effect in one layer with the position of another layer. For example, you can create an effect that looks like a magnifying glass moving over a layer, with the contents under the magnifying glass bulging as the lens (that is, the overlying layer) moves. This expression uses the fromWorld method, which makes the expression work correctly regardless of whether you move the magnifying glass layer or the underlying layer. You can rotate or scale the underlying layer, and the expression stays intact.
You can also use other effects, such as Ripple, with this expression.
Expression example: Fade opacity of a 3D layer based on distance from camera
Apply the following expression to the
Opacity property of a 3D layer: startFade = 500; // Start fade 500 pixels from camera.
endFade = 1500; // End fade 1500 pixels from camera.
try{ // Check whether there's a camera.
C = thisComp.activeCamera.toWorld([0,0,0]);
}catch(err){ // No camera, so assume 50mm.
w = thisComp.width * thisComp.pixelAspect;
z = (w/2)/Math.tan(degreesToRadians(19.799));
C = [0,0,-z];
}
P = toWorld(anchorPoint);
d = length(C,P);
linear(d,startFade,endFade,100,0)The fade starts at a distance of 500 pixels from the camera and is complete at 1500 pixels from the camera. The linear interpolation method is used to map distance values to opacity values.
Expression example: Make a 3D layer invisible if facing away from camera
Apply the following expression to the
Opacity property of a 3D layer: if (toCompVec([0, 0, 1])[2] > 0 ) value else 0
Dan Ebberts explains this expression on his MotionScript website.
Expression example: Flip layer horizontally if facing away from camera
Apply the following expression to the
Scale property of a 3D layer: if (toCompVec([0, 0, 1])[2] > 0 ) value else [-value[0], value[1], value[2]]
Expression example: Animate scale at each layer marker
Apply the following expression to a
Scale property to make a layer wobble at each marker: n = 0;
t = 0;
if (marker.numKeys > 0){
n = marker.nearestKey(time).index;
if (marker.key(n).time > time) n--;
}
if (n > 0) t = time - marker.key(n).time;
amp = 15;
freq = 5;
decay = 3.0;
angle = freq * 2 * Math.PI * t;
scaleFact = (100 + amp * Math.sin(angle) / Math.exp(decay * t)) / 100;
[value[0] * scaleFact, value[1] / scaleFact];Expression example: Start or stop wiggle at specific time
You can use any expression in place of the wiggle expression used here, to begin and end the influence of any expression at a specific time.
Expression example: Match camera focal plane to another layer
Apply the following expression to the
Focus Distance property of a camera layer to have its focus distance
match the distance to the anchor point of a layer named “target”: target = thisComp.layer("target");
V1 = target.toWorld(target.anchorPoint) - toWorld([0,0,0]);
V2 = toWorldVec([0,0,1]);
dot(V1,V2);Dan Ebberts explains this expression example in detail on his Motionscript website.
button
to the left of the property name.