Basic Expressions in After Effects
Here are some beginner-friendly expressions that you can use to add simple yet powerful animations and effects to your projects:
Tips for Using Expressions
Alt/Option + Click on the stopwatch icon to open the expression editor for a property.
Use the Pick Whip tool to easily link properties between layers.
Test and tweak parameters (e.g., frequency, amplitude) for the desired effect.
Comment your expressions for clarity using //.
Wiggle (Random Movement)
wiggle(frequency, amplitude)
Description: Creates random motion for a property.
Example: wiggle(3, 50)
Moves the layer randomly 3 times per second with an intensity of 50 pixels/units.
Time (Linear Animation)
time * value
Description: Animates a property over time.
Example: time * 50
Makes the property increase by 50 units every second.
Loop Out (Repeating Keyframes)
loopOut(type = "cycle", numKeyframes = 0)
Description: Repeats the keyframes indefinitely.
Types:
"cycle": Loops keyframes in order.
"pingpong": Alternates back and forth.
"offset": Adds the last value to the start of the next loop.
"continue": Extends the motion beyond keyframes.
Example: loopOut("pingpong")
Creates a back-and-forth looping animation.
Random (Generate Random Values)
random(minValue, maxValue)
Description: Generates a random value between the specified range.
Example: random(0, 360)
Generates a random value between 0 and 360.
Looping Wiggle (by Dan Ebberts)
freq = 1;
amp = 110;
loopTime = 3;
t = time % loopTime;
wiggle1 = wiggle(freq, amp, 1, 0.5, t);
wiggle2 = wiggle(freq, amp, 1, 0.5, t - loopTime);
linear(t, 0, loopTime, wiggle1, wiggle2)
Description: Creates a smooth transition between values.
Example: ease(time, 0, 100)
Animates smoothly from 0 to 100.
Value At Time (Offset Timing)
valueAtTime(time - offset)
Description: Uses the property’s value from a different time.
Example: valueAtTime(time - 0.5)
Offsets the animation by half a second.
Linear (Map One Range to Another)
linear(input, inputLow, inputHigh, outputLow, outputHigh)
Description: Maps an input value from one range to another.
Example: linear(time, 0, 1, 0, 100)
Transitions from 0 to 100 over 1 second.
Bounce
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time){
n--;
}
}
if (n == 0){
t = 0;
}else{
t = time - key(n).time;
}
if (n > 0 && t < 1){
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
amp = .05;
freq = 4.0;
decay = 8.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}
Description: Creates a bouncy effect after a keyframe.
Example: Use this on position or scale for a spring-like bounce.
Overshoot (by Dan Ebberts)
freq = 3;
decay = 5;
t = time - inPoint;
startVal = [0,0];
endVal = [200,200];
dur = 0.1;
if (t < dur){
linear(t,0,dur,startVal,endVal);
}else{
amp = (endVal - startVal)/dur;
w = freq*Math.PI*2;
endVal + amp*(Math.sin((t-dur)*w)/Math.exp(decay*(t-dur))/w);
}
Description: Creates a bouncy effect after a keyframe.
Example: Use this on position or scale for a spring-like bounce.
Blinking Effect
frequency = 2;
Math.sin(time * frequency * Math.PI * 2) > 0 ? 100 : 0
Description: It makes opacity blink on and off.
Example: Use this on opacity to create a blinking effect at 2 times per second.
Loop Path Keyframes
if (numKeys >1 && time > key(numKeys).time) {
t1 = key(1).time;
t2 = key(numKeys).time;
span = t2 - t1;
delta = time - t2;
t = delta%span;
valueAtTime(t1 + t)
} else {
value
}
Seamlessly loop keyframes on a Path Property for shape layers or masks.
Behaves like loopOut('cycle')
Comentarios