Online resources for expression
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.

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.

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.

Expression example: Position one
layer between two others

Animate the positions of the first two layers in the Timeline panel. (See Motion paths.)

Select the third layer, press P to reveal the Position
property, and Alt-click (Windows) or Option-click (Mac OS) the stopwatch button
to the left of the property name.

Enter the following in the expression field:

(thisComp.layer(1).position + thisComp.layer(2).position)/2

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.

Select the second layer, press P to reveal the Position
property, and Alt-click (Windows) or Option-click (Mac OS) the stopwatch button
to the left of the property name.

Enter the following in the expression field:

thisComp.layer(thisLayer, -1).position.valueAtTime(time - .5)

Duplicate the last layer five times by selecting it and
pressing Ctrl+D (Windows) or Command+D (Mac OS) five times.

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.

Start with two layers. Make one layer a magnifying
glass or similar object with a hole in the middle and name it Magnifier.
(See Creating
layers.)

Animate the position of the magnifying glass layer. (See Motion
paths.)