Some After Effects scripts

These are a VERY useful collection of scripts which can make life a LOT easier for visual effects work and compositing.

### A collection of AFX Expressions:

Random number in a range and hold it:

`seedRandom(index,true);`

random(1000,2000);

Random for text Color

random([1,1,1,1])

If you want it to hold the random color rather than change every frame you’d do this:

`seedRandom(index,true);`

random([1,1,1,1])

The expression can be applied to anything in After Effects with a ‘position’ property to create a variety of effects.

For Circular:

`radius=300`

angle=time*200

x=radius*Math.cos(degreesToRadians(angle))

y=radius*Math.sin(degreesToRadians(angle))

z=0

centre=[640,360,0]

add(centre,[x,y,z])

For Spiral:

`shrink=time+1`

radius=1000/shrink

angle=time*200

x=radius*Math.cos(degreesToRadians(angle))

y=radius*Math.sin(degreesToRadians(angle))

//z=0 // no depth

z=time*time // with depth

centre=[640,360,0]

add(centre,[x,y,z])

Apply the following expression to a property to wiggle it beginning at time 2 seconds:

`timeToStart = 2;`

if (time > timeToStart){

wiggle(3,25);

}else{

value;

}

Apply the following expression to a property to stop wiggling it at time 4 seconds:

`timeToStop = 4;`

if (time > timeToStop){

value;

}else{

wiggle(3,25);

}

Apply the following expression to a property to start wiggling it at time 2 seconds and stop wiggling it at time 4 seconds:

`timeToStart = 2;`

timeToStop = 4;

```
```

```
if ((time > timeToStart) && (time < timeToStop)){
wiggle(3,25);
}else{
value;
}
```

Variations:

```
```timeToStart = 2;

frameToStart = 12;

timeToStop = 4;

frameToStop = 12;

`d = thisComp.frameDuration;`

if ((time > (timeToStart + frameToStart*d)) && (time < (timeToStop + frameToStop*d))){
wiggle(3,25);
}else{
value;
}
timeToStop = 5;
frameToStop = 5;
d = thisComp.frameDuration;
if (time > (timeToStop + frameToStop*d)){

value;

}else{

wiggle(8,30);

}

Creative Cow - After Effects Expressions Simplified

How to loop back and forth

by Rick Gerard

Just writing loopOut() sets the loop option to cycle which is not what you want. To thange the behavior to back and forth write:

`loopOut("pingpong") `

Strangely enough if you go to Help>Expression Language and search for loop you'll find a complete listing of the loop functions and links to additional functions.

cycle | (default) Repeats the specified segment. |

pingpong | Repeats the specified segment, alternating between forward and backward. |

offset | Repeats the specified segment, but offsets each cycle by the difference in the value of the property at the start and end of the segment, multiplied by the number of times the segment has looped. |

continue | Does not repeat the specified segment, but continues to animate a property based on the velocity at the first or last keyframe. For example, if the last keyframe of a Scale property of a layer is 100%, the layer continues to scale from 100% to the Out point, instead of looping directly back to the Out point. This type does not accept akeyframes or duration argument. |

Just another FYI to throw in the back of your memory, loopOut("cycle") needs 3 keyframes to create a seamless loop, first keyframe, second keyframe, then a copy of the first keyframe one frame later. If your animation needs to pingpong instead of cycle you only need 2.

### Key frames - move by twos.

Is there a convenient way of making the transition between 2 keyframes occur not smoothly (frame by frame) but on a 2-frame basis ? (a change every 2 frames).

Apply this expression if you're working with position keyframes:

`n = 2;`

posterizeTime(1/n/thisComp.frameDuration);

transform.position

If you want this stuttered motion to occur only between two keyframes it might get a little more complicated:

`n = 2;`

k1 = key(1).time;

k2 = key(2).time;

if((time<=k2)&&(time>=k1)) posterizeTime(1/n/thisComp.frameDuration);

transform.position;

This would only apply the stuttering motion between the first and second keyframes as defined by the number in the key(x) parentheses.

When using the posterizeTime() function you can't use the 'value' parameter to return the posterized value, so you'll have to pickwhip the property to itself to generate the last line (i.e. "transform.position").

Darby Edelen

Using the LINEAR for blurring

altering an effect every odd/even frame:

n = effect("Directional Blur")("Blur Length")

n1 = 0;

n2 = 24;

f = timeToFrames();

if (f%2 == 0) n = n1 else n = n2

run expression every 2 frames.. every 3 frames etc?

If a page is reduced to 80%, what percent enlargement would return to its original size ?

25%

you want 100% from 80:

100/80 = 1,25

100 is 125% of 80, or increase of 25%

http://openstudy.com/updates/5241a6f4e4b0900154184023