beautypg.com

Expression examples, Example: make a layer revolve in a circle, Example: rotate the hands of a clock – Adobe After Effects CS3 User Manual

Page 587

background image

AFTER EFFECTS CS3

User Guide

582

For example, if you have a parameter named “background color”, then you can use the following expression to access
its value at the nearest marker:

thisComp.marker.nearestKey(time).parameters["background color"]

Expression examples

Many of the examples in this section are based on expressions provided by Dan Ebberts. Dan Ebberts also has an
excellent collection of example expressions and tutorials for learning how to work with expressions on his website:

www.adobe.com/go/learn_ae_motionscripthome

.

Colin Brailey provides a tutorial and example project that show how to use expressions to make one layer repel others
in a natural-seeming manner:

www.adobe.com/go/learn_ae_colinrepelexpression

.

The AE Enhancers forum provides lots of examples and useful information about expressions, as well as scripts and
animation presets. In this post, Paul Tuersley provides a tutorial and example project that show how to use expres-
sions to animate several layers in a swarm:

www.adobe.com/go/learn_ae_paulswarmexpression

.

Rick Gerard provides an example that demonstrates rolling a square object along a floor so that the sides stayed in
contact with the floor plane:

www.adobe.com/go/learn_ae_ricksquarewheels

.

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.

1

Select a layer, press P to reveal its Position property in the Timeline panel, and Alt-click (Windows) or Option-

click (Mac OS) the stopwatch to the left of the property name.

2

Enter the following in the expression field:

[(thisComp.width/2), (thisComp.height/2)] + [Math.sin(time)*50, -Math.cos(time)*50]

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.

1

Import or create two long, narrow solid-color layers: an hour hand and a minute hand. (See “Create or modify a

solid-color layer” on page 136.)

2

Set the anchor points at the ends of the layers. (See “Work with layer anchor points” on page 154.)

3

Move the layers so that the anchor points are at the center of the composition. (See “Move layers in space” on

page 139.)

4

Set Rotation keyframes for the hour hand. (See “Set keyframes” on page 187.)

5

Select the Rotation property for the minute hand and choose Animation > Add Expression.

6

Drag the pick whip to the hour hand’s Rotation property. The following expression appears:

thisComp.layer("hour hand").rotation

7

To make the minute hand rotate 12 times as fast as the hour hand, add

*12

at the end of the expression as follows: