Expressions
After Effects built-in variables, properties, functions, and syntax
Overview
After Effects expressions use JavaScript syntax to automate animation, link properties, and create dynamic effects. Below are the most useful variables, properties, functions, operators, and syntax for writing expressions.
Tips
- • Use
value
to refer to the current property. - • Use
time
for time-based animation. - • Most math and logic from JavaScript is available.
- • Use
wiggle()
for random movement. - • Use
loopOut()
andloopIn()
for looping keyframes.
Variables
Name / Code | Example | Description |
---|---|---|
time | time * 30 | Current composition time in seconds. |
value | value + 10 | Current property value. |
index | thisComp.layer(index + 1) | Layer index in the comp. |
thisComp | thisComp.width | Reference to the current composition. |
thisLayer | thisLayer.opacity | Reference to the current layer. |
parent | parent.position | Reference to the parent layer. |
Properties
Name / Code | Example | Description |
---|---|---|
rotation | rotation + 45 | Layer rotation property. |
opacity | opacity * 0.5 | Layer opacity property. |
position | position + [100,0] | Layer position property. |
scale | scale * 2 | Layer scale property. |
anchorPoint | anchorPoint + [0,50] | Layer anchor point property. |
Functions & Methods
Name / Code | Example | Description |
---|---|---|
comp(name) | comp("Main") | Gets a composition by name. |
layer(name or index) | layer("Logo") | Gets a layer by name or index. |
wiggle(freq,amp) | wiggle(2,50) | Randomly wiggle a property. |
seedRandom(seed, timeless) | seedRandom(123,true) | Sets the seed for randomization. |
loopOut() | loopOut() | Loops keyframes after last keyframe. |
loopIn() | loopIn() | Loops keyframes before first keyframe. |
ease(t, tMin, tMax, value1, value2) | ease(time,0,1,0,100) | Interpolates between two values over time. |
linear(t, tMin, tMax, value1, value2) | linear(time,0,1,0,100) | Linear interpolation between two values. |
clamp(val, min, max) | clamp(x,0,100) | Restricts a value to a range. |
toComp([x, y]) | toComp([0,0]) | Converts layer space coordinates to comp space. |
toWorld([x, y]) | toWorld([0,0]) | Converts layer space coordinates to world space. |
lookAt(from, to) | lookAt(thisLayer.position, target.position) | Returns orientation from one point to another. |
random(min, max) | random(0,100) | Returns a random number between min and max. |
Math.sin(x) | Math.sin(time) | Sine function from JavaScript Math. |
Math.cos(x) | Math.cos(time) | Cosine function from JavaScript Math. |
Math.abs(x) | Math.abs(x) | Absolute value. |
Math.floor(x) | Math.floor(time) | Rounds down to nearest integer. |
Math.round(x) | Math.round(time) | Rounds to nearest integer. |
Math.max(a, b) | Math.max(a,b) | Returns the larger of two values. |
Math.min(a, b) | Math.min(a,b) | Returns the smaller of two values. |
Math.random() | Math.random() | Random number between 0 and 1. |
Operators
Name / Code | Example | Description |
---|---|---|
+, -, *, / | a + b | Math operators: add, subtract, multiply, divide. |
==, !=, >, <, >=, <= | x >= 10 | Comparison operators. |
&&, ||, ! | a && b | Logical operators: and, or, not. |
Syntax & Statements
Name / Code | Example | Description |
---|---|---|
if (cond) { ... } else { ... } | if (x > 10) { y = 1; } | Conditional logic. |
// comment | // This is a comment | Single-line comment. |
for (var i=0; i<10; i++) { ... } | for (var i=0; i<10; i++) { x += i; } | For loop. |
while (cond) { ... } | while (x < 100) { x++; } | While loop. |
var x = 10; | var y = 5; | Variable declaration. |