Introduction

Expressions are a programming language inside After Effects, based on Java Script. They can be enabled by an Alt+ click on the stopwatch of a different property which generates the bar for writing expressions. The expression is the value used to fill in that property, like,for example, the wiggle expression.

Let's take for example an expression for the rotation property of a redrectangle: Alt + click on the stopwatch triggers the expressions bar. By writing 40/5 in the bar, the rectangle will obtain a rotation of 0x + 8.0. Using the pickwhip, you can drag and assign the value to another property, like for example the position.

 

 

The equal (=) sign enables and disables the expression.

The advantage of using expressions is that with them you only change a single value, whereas with keyframes you have to change every single keyframe, therefore it saves a lot of time and energy. 

Expressions Syntax

Expressions syntax works a little like this:

thisComp.layer  (Medium Gray - Royal Blue Solid 1"). transform.opacity

which means that within this composition there is a layer named MediumGray - Royal Blue Solid 1 and the opacity property is being modified within theTransform menu.

Some properties like position and scale have two values. A list of values is referred to as an array. For example [position[xvalue],y value] is an array of the xposition and the y position values. The scale property is a one dimensional array. If we take the pickwhip and drag it to opacity, which is a one dimensional value, then in the expressions bar a variable and a two dimensional array will be created [temp,temp].

Types of Expressions

The wiggle expression can apply to all dimensions of an array (x,y, z). wiggle(3,4) for example, applied to a Camera, which is a three dimensional array, gives the footage a slight handycam effect. With the wiggle you can add an expression to a layer even if there are keyframes already, and they remain intact. It just wiggles the keyframe values.

ex: [position[0],wiggle(2,4)[1]]

 

 

 

There are a lot of other useful expressions that we could use to make work a lot easier, such as the random, the index, and the time expressions.

The random expression generates random values, like for example  random(0,720) , which randomizes the property of the layer (position, scale, rotation etc) between 0 and 720 every single frame.

The index expression just gives you the number of the layer. If the number of the layer is 3, then the index expressions added on a property of that layer returns avalue of 3. If the layer is moved at  the bottom, then the value would be the number of this last layer.

You can also multiply it, like index*5.  For example, we can write an expression for position using the index: [position[0],position[1],index*5] which means that  x and y are normal, and then the z positionis controlled by the index times 5. If you duplicate the layer, it creates a duplicate in z space. It's good for creating 3d ensembles and patterns.

You can also multiply it, like index*5.  For example, we can write an expression for position using the index: [position[0],position[1],index*5] which means that  x and y are normal, and then the z position is controlled by the index times 5.

The time expression just expresses the time in seconds. Adding the time expression to the opacity for example, modifies this property as the footage plays, frame by frame.

You can also use expressions inside expressions:

wiggle(time,time) applied to the position, means that the frequency and amplitude will increase over time, frame by frame, creating an earthquake effect.  

 

Expression Controls

For a better control over expressions,  Expression Controls  can be applied as effects to a null object.  For example, if we want to have more control over a wiggle expression, we can add a slider control (from the effects andpresets panel) to a null object.

With the pickwhip you can connect the wiggle expression to the slider from the slider control effect.  By creating new keyframes in the null object and modifying the slider value for each created keyframe  you can control the amplitude of the wiggling better.

 

If I am going to create 4 oval shapes in the composition, and I would like them to rotate and wiggle at the same time with the same values, without adding any keyframes, I will use an Angle Control from  Effect-> Expression Controls -> Angle Control , and I will add it to the newly created null object on top of all my layers.

I have already added wiggle(5,6) to the expression boxes of all the layers, which is making the oval shapes wiggle with an amplitude of 5 on the x axis and 6 on the yaxis. The next step is to select the pickwhip from the rotation property of one of our layers, and drag it to the angle property of the angle control effect.  

 

 

 

As you can see, the parameters of the expression changed into what means: the value from this property comes from another property called Angle, which is the propertyof another effect called Angle Control, from the layer Null 2.

Now, when I rotate the Angle Control dial, I can see that one of my layers is also rotating. To make all the other layers rotate aswell, just copy the Rotation property into all the other layers.  

Now I‘ll just click on the stopwatch of the angle dial, and rotate all the layers at once.

I also want my layers to change color as they rotate, so Iwill add a Hue/Saturation effect from the Color Correction effects to one of my red ovals. I will also click the Colorize option and set the Colorize saturation to 100, then Alt+click on the Colorize hue stopwatch, which will add an expression in the timeline. 

 

 

 

Then I will use the pickwhip from the Colorize hue expression and drag it to the Angle property in the Null object. As I move the cursor through the timeline, I can see that the layer is changing color as it rotates. All I have to do now is copy and paste the Hue Saturation effect to all of the other layers.