21st April 2008

Today we started looking at expressions within after effects. Expressions are a form of Javascript used to help animate in after effects. Expressions make it possible for each layer to react to one another and create complex animations when it would otherwise of been very difficult and complicated to do so.

The first technique we looked as was a way to make layers follow each other around the work space. The way we did that was create some code to make the layer look at previous layer and copy its position and scale from a set amount of frames before it.

To do this, we used the valueAtTime function. This gives us the value of a property on a layer at a certain time.

First of all, we created a simple animation of a circle moving around the screen. We then duplicated this layer and switched off the keyframes. We then created a new expression on the position parameter. We did this by pressing shift,alt,=.

The code we wrote was this

thisComp.layer(index-1).transform.position.valueAtTime(time-0.5)

we used the pickwhip tool to select the previous layer to make the writing easier. This code means, look at the layer before this one, and the value of the position of the layer half a second ago. We added the same thing to the scale parameter.

Once we had done this, we simply duplicated the layer 10 or so times. This gave us this animation.

The next thing we looked at was using “sliders” and variables within out expressions. This technique enables us to change numbers within our expressions without having to go back type in new numbers. This can save a lot of time. To create a new slider, firstly, we create a null. We then add a new slider to that null from the effects and presets box making sure we name the slider something memorable.

The next thing to do is turn this slider into a variable within our expression. We created two, one for horizontal and one for verticle distance. To make a variable linked to the slider called “H” and “v” we use the following code.

H=thisComp.layer(“Null 1″).effect(“H”)(“Slider”)

v=thisComp.layer(“Null 1″).effect(“v”)(“Slider”)

All we type is “distance=” then pickwhip the slider we created. This creates the variable we can now use in our expression.

The following is the expression used to create a slider that changes the distance of layers on top of each other.

H=thisComp.layer(“Null 1″).effect(“H”)(“Slider”)
v=thisComp.layer(“Null 1″).effect(“v”)(“Slider”)

thisComp.layer(index-1).transform.position+[H,+v]

We then keyframed the sliders and came up with this.

We then combined our knowelege of variable and sliders to come up with the following animation using the brightness effect. The code written worked so that the further the layer was from the first layer, the darker the layer was.

The code for the brightness effect is as follows…

a=thisComp.layer(“yellow”).transform.position[0]
b=transform.position[0]

0-(a-b)/

We then did the same thing using the blur effect.

Published in:  on April 21, 2008 at 2:16 pm Leave a Comment