Lost in Expressions

Years ago, I did a bit of work in Web Design. This was before there was a Dreamweaver or GoLive, when you had to write all the HTML code manually. That was enough to send me running for the hills, and that’s why I got into Broadcast Design where you didn’t have to deal with any of that.

Well, After Effects has had a Javascript-based programming language called Expressions for a couple of versions now. It’s something that I avoided like the plague at first — I mean, how do you make heads or tails of something like this:

columns = 10; //number of columns in grid
tHold= .2; //hold time (must be less than tmin)
tMin = .5; //minimum cycle time (can’t be zero)
tMax = 1; //maximum cycle time
gap = this_comp.width/columns;
origin = [gap,gap];
xGrid = columns – 1;
yGrid = Math.floor(this_comp.height/gap) – 1;
start = 0;
end = 0;
j = 1;
while (time >= end){
j += 1;
start = end;
end += random(tMin,tMax);
targetX = Math.floor(random(0,xGrid));
targetY = Math.floor(random(0,yGrid));
x = random(); //this is a throw-away value
oldX = Math.floor(random(0,xGrid));
oldY = Math.floor(random(0,yGrid));
if(targetX == oldX && targetY == oldY){
origin + [oldX,oldY]*gap;
}else if (time – start < tHold){
origin + [oldX,oldY]*gap;
deltaX = Math.abs(targetX – oldX);
deltaY = Math.abs(targetY – oldY);
xTime = (end – start – tHold)*(deltaX/(deltaX + deltaY));
yTime = (end – start – tHold)*(deltaY/(deltaX + deltaY));
if (time < start + tHold + xTime){
startPos = origin + [oldX,oldY]*gap;
targetPos = origin + [targetX,oldY]*gap;
easeOut((time – start – tHold)/xTime, startPos, targetPos);
startPos = origin + [targetX,oldY]*gap;
targetPos = origin + [targetX,targetY]*gap
easeIn((time – start – tHold – xTime)/yTime, startPos, targetPos);

OK, I know some of you programmers out there are gonna write me and say “oh that’s grade-school level”, but for the rest of us it’s enough to make us put our heads in a 500 degree oven.

Well, the reality is that simple Expressions are actually easy and can save you loads of time when creating animation while opening up a wide range of creative possibilities.

First off, you can use the Expressions LIbrary to have AE plug the code in for you. When you Alt+Click (Opt+Click on Mac) on the Stopwatch icon to set a keyframe for a property, it opens the Expressions Editor for that property. You’ll then see a fly-out menu icon (the little circle with the triangle in it). Click it, and you’ll see all the categories of Expressions.


In addition, some really useful Expressions are very easy. Take “Wiggle”, for example. This puts random motion on a property over time, and the code looks like this:


Not as daunting as that first set of code, eh? What the (4,10) represents, is the frequency & amplitude of the wiggle (frequency=4, amplitude=10). So let’s say you apply this to the Position parameter of the layer, it will move it at a frequency of 4 times per second, at a maximum of 10 pixels each time. Give it a try and see the results. If you want it to move more frequently, set a higher frequency — if you want it to move over a larger area, set a higher amplitude.

If you haven’t already figured it out, I didn’t write the Expression at the beginning of this post. That one came from the AE Expressions Lab on an incredibly useful Expressions & Scripting resource called MotionScript.com. This site, created by Dan Ebberts, has a set of pre-baked Expressions that you can simply copy & paste into your AE projects. This is probably one of the easiest ways to get started with Expressions, and no, not all of Dan’s Expressions are as complex as the one I pasted above.

One last thing — there’s a hidden goodie in one of the Project Templates included with AE7. Go to File>Browse Template Projects, and once Bridge launches, double-click the thumbnail that looks like this:


What you’ll find in Template Project is a set of comps that have loads of neat Expressions (also created by Dan Ebberts) that you can copy & paste into your own projects.

Comments are closed.