> ## Documentation Index
> Fetch the complete documentation index at: https://www.tella.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tella Motion expressions

> The expression language of Tella Motion: JavaScript expression syntax over After Effects' helpers, with all 134 functions, units, working recipes and each difference from JavaScript and After Effects.

An expression makes a value follow something else on every frame: a dot riding the tip of a line as it draws, a badge pinned to a card that resizes, a number counting up, a shape that drifts or pulses without keys. It is written as text in JavaScript expression syntax, with the helpers After Effects expressions have, and stored as the values the renderer evaluates, so it renders the same in the editor and in every export.

Agents get this page as `get_motion_schema` with `schema: "expressions"` (REST: `GET /v1/motion/schema?schema=expressions`).

## Where an expression goes

* `bindProperty {node, property, to}` binds a numeric property (x, y, rotation, scale, opacity, a `field:…`) or a title's `text` to an expression, in the units commands take.
* `setCurve {name, value}` names an expression (or keys, or a number) every node of the canvas reads as `curve(name)`: one value for many fields.
* In an op (`node.patch`, `node.insert`), `{expression: text}` stands wherever a stored number or vector goes, as `{seconds: n}` stands for ticks.
* An expression is the whole value of its field and gives what the field holds: one number for a property (take `.x` or `.y` of a point), a vector where the field is one.
* A bound `x` or `y` is added to where the node is drawn, so what follows a point is drawn around 0,0. `scale` and `rotation` turn around the node's anchor, the centre of what it draws unless `anchorX` and `anchorY` say otherwise: a scale needs no x or y to hold the node in place.
* A wrong expression changes nothing: the error says where the text stopped and what to write, and the room checks that every node, curve and width it reads exists before anything is stored.

## Syntax

* An expression is JavaScript expression syntax for one value: a number, a vector of 2 to 16 numbers, a list or a path. It is converted to the tree of values the document stores, never run, so it reads back field by field and renders the same everywhere.
* Numbers are `2`, `.5`, `1e3`; `true` and `false` are 1 and 0; a vector is `[x, y]`, and a colour is `[r, g, b, a]` with each channel 0 to 1.
* `+ - * /`, `**`, `== != < <= > >=` (and `===`, `!==`), `!`, a leading `-` and `c ? a : b` bind as in JavaScript. A comparison gives 1 or 0, and `c ? a : b` evaluates only the branch it takes.
* `+ - * /` work on vectors component by component, and a number applies to every component: `[1, 2] * 2` is `[2, 4]`.
* `v.x`, `v.y`, `v.z`, `v.w` and `v[n]` read one component of a vector, and `.left`, `.top`, `.width`, `.height` the same four of a box, as After Effects names a rectangle's. A place that takes one number (a position's x, an opacity) needs one: `pointOnPath(p, t).x`.
* Everything else is a function call. Strings, in either kind of quotes, name nodes, curves, clocks and modes.
* Name a value with `const name = value;` on a line before the last, whose value is the expression's, as After Effects reads an expression. `(() => { const a = 1; return a * 2; })()` names values anywhere a value goes. A name is set once.
* `Math.PI`, `Math.E`, `Math.LN2`, `Math.LN10`, `Math.LOG2E`, `Math.LOG10E`, `Math.SQRT2`, `Math.SQRT1_2`, and `Math.abs`, `acos`, `asin`, `atan`, `atan2`, `ceil`, `cos`, `exp`, `floor`, `fround`, `log`, `max`, `min`, `pow`, `round`, `sign`, `sin`, `sqrt`, `tan`, `trunc` give what JavaScript gives.
* `// ...` and `/* ... */` are comments.

## Units

* Time is seconds, as in After Effects: `time` and every clock, every time a function takes (valueAtTime, timeShift, ref, toComp, nodePath, sampleImage) and every time one gives (inPoint, outPoint, marker, keyTime). A time lands on the frame it falls in.
* Rotations are degrees; sin, cos, tan and atan2 work in radians, as in JavaScript. degreesToRadians and radiansToDegrees convert.
* Lengths and positions are px. A node's local space starts at the top-left of its layout box, before its transform.
* Opacity, scale, a trim's start and end, and a point on a path are fractions: 0.5 is half.
* A colour is \[r, g, b, a], each from 0 to 1.

## Recipes

Every recipe runs in Tella's test suite as shown.

### Ride the tip of a line as it draws

One curve is the progress: the line's trim and the dot both read it, so they cannot drift apart whatever the easing or the path's shape. `nodePath` is the line's whole path, before its trim, in the line's own space; `toComp(point, "route")` takes a point of it to where the line shows, so the dot stays on it when the line is moved, scaled or animated. A binding to `x` and `y` is added to where the shape is drawn: draw the rider around 0,0 (a 24 px dot has the box `-12, -12, 24, 24`). The rotation line turns an arrow or a vehicle along the path.

On a document that holds:

```json theme={"system"}
[
  {
    "type": "addPath",
    "nodeId": "route",
    "start": 0,
    "duration": 4,
    "path": "M 300,800 C 700,100 1200,1000 1600,300",
    "paint": "stroke",
    "color": "#ffffff",
    "strokeWidth": 6
  },
  {
    "type": "addEffect",
    "node": "route",
    "kind": "trimPath",
    "effectId": "trim",
    "params": {
      "end": 0
    }
  },
  {
    "type": "addShape",
    "nodeId": "dot",
    "start": 0,
    "duration": 4,
    "shape": "circle",
    "box": {
      "x": -12,
      "y": -12,
      "width": 24,
      "height": 24
    },
    "color": "#ff3b30"
  }
]
```

send:

```json theme={"system"}
[
  {
    "type": "setCurve",
    "name": "draw",
    "value": [
      {
        "at": 0.5,
        "value": 0,
        "easing": "ease"
      },
      {
        "at": 3.5,
        "value": 1
      }
    ]
  },
  {
    "type": "bindProperty",
    "node": "route",
    "property": "field:@e.trim/effect/end",
    "to": "curve(\"draw\")"
  },
  {
    "type": "bindProperty",
    "node": "dot",
    "property": "x",
    "to": "toComp(pointOnPath(nodePath(\"route\"), curve(\"draw\")), \"route\").x"
  },
  {
    "type": "bindProperty",
    "node": "dot",
    "property": "y",
    "to": "toComp(pointOnPath(nodePath(\"route\"), curve(\"draw\")), \"route\").y"
  },
  {
    "type": "bindProperty",
    "node": "dot",
    "property": "rotation",
    "to": "const t = toCompVec(tangentOnPath(nodePath(\"route\"), curve(\"draw\")), \"route\");\nradiansToDegrees(Math.atan2(t.y, t.x))"
  }
]
```

### A second rider a beat behind the first

`valueAtTime` reads any value at another time, in seconds, so a trail is the same expression read a little earlier.

On a document that holds:

```json theme={"system"}
[
  {
    "type": "addPath",
    "nodeId": "route",
    "start": 0,
    "duration": 4,
    "path": "M 300,800 C 700,100 1200,1000 1600,300",
    "paint": "stroke",
    "color": "#ffffff",
    "strokeWidth": 6
  },
  {
    "type": "addEffect",
    "node": "route",
    "kind": "trimPath",
    "effectId": "trim",
    "params": {
      "end": 0
    }
  },
  {
    "type": "addShape",
    "nodeId": "dot",
    "start": 0,
    "duration": 4,
    "shape": "circle",
    "box": {
      "x": -12,
      "y": -12,
      "width": 24,
      "height": 24
    },
    "color": "#ff3b30"
  },
  {
    "type": "addShape",
    "nodeId": "echo",
    "start": 0,
    "duration": 4,
    "shape": "circle",
    "box": {
      "x": -8,
      "y": -8,
      "width": 16,
      "height": 16
    },
    "color": "#ff9500"
  },
  {
    "type": "setCurve",
    "name": "draw",
    "value": [
      {
        "at": 0.5,
        "value": 0,
        "easing": "ease"
      },
      {
        "at": 3.5,
        "value": 1
      }
    ]
  }
]
```

send:

```json theme={"system"}
[
  {
    "type": "bindProperty",
    "node": "echo",
    "property": "x",
    "to": "toComp(pointOnPath(nodePath(\"route\"), valueAtTime(curve(\"draw\"), time - 0.2)), \"route\").x"
  },
  {
    "type": "bindProperty",
    "node": "echo",
    "property": "y",
    "to": "toComp(pointOnPath(nodePath(\"route\"), valueAtTime(curve(\"draw\"), time - 0.2)), \"route\").y"
  }
]
```

### Pin a badge to the corner of a node that moves or resizes

`nodeBox` measures what another node draws on this frame as a box with `.left`, `.top`, `.width` and `.height`, here its painted box on the canvas (`"composition"`), so the badge follows the card through its animation, its scale and its text reflowing.

On a document that holds:

```json theme={"system"}
[
  {
    "type": "addShape",
    "nodeId": "card",
    "start": 0,
    "duration": 4,
    "shape": "rect",
    "box": {
      "x": 160,
      "y": 760,
      "width": 800,
      "height": 160
    },
    "color": "#111827"
  },
  {
    "type": "addShape",
    "nodeId": "badge",
    "start": 0,
    "duration": 4,
    "shape": "circle",
    "box": {
      "x": -16,
      "y": -16,
      "width": 32,
      "height": 32
    },
    "color": "#34c759"
  }
]
```

send:

```json theme={"system"}
[
  {
    "type": "bindProperty",
    "node": "badge",
    "property": "x",
    "to": "const box = nodeBox(\"painted\", \"composition\", \"card\");\nbox.left + box.width"
  },
  {
    "type": "bindProperty",
    "node": "badge",
    "property": "y",
    "to": "nodeBox(\"painted\", \"composition\", \"card\").top"
  }
]
```

### Count a number up in a title

Bound to a title's `text`, the title shows the number. `linear(t, tMin, tMax, value1, value2)` maps the clock onto the count and holds at both ends.

On a document that holds:

```json theme={"system"}
[
  {
    "type": "addTitle",
    "nodeId": "count",
    "start": 0,
    "duration": 4,
    "text": "0"
  }
]
```

send:

```json theme={"system"}
[
  {
    "type": "bindProperty",
    "node": "count",
    "property": "text",
    "to": "round(easeOut(time, 0.5, 2.5, 0, 1200))",
    "text": {
      "prefix": "$",
      "decimals": 0
    }
  }
]
```

### Pulse and drift without keys

A sine of the clock loops forever; `wiggle(value, frequency, amplitude)` drifts around a value, here 12 px either side of where the shape is drawn, twice a second.

On a document that holds:

```json theme={"system"}
[
  {
    "type": "addPath",
    "nodeId": "route",
    "start": 0,
    "duration": 4,
    "path": "M 300,800 C 700,100 1200,1000 1600,300",
    "paint": "stroke",
    "color": "#ffffff",
    "strokeWidth": 6
  },
  {
    "type": "addEffect",
    "node": "route",
    "kind": "trimPath",
    "effectId": "trim",
    "params": {
      "end": 0
    }
  },
  {
    "type": "addShape",
    "nodeId": "dot",
    "start": 0,
    "duration": 4,
    "shape": "circle",
    "box": {
      "x": -12,
      "y": -12,
      "width": 24,
      "height": 24
    },
    "color": "#ff3b30"
  }
]
```

send:

```json theme={"system"}
[
  {
    "type": "bindProperty",
    "node": "dot",
    "property": "scale",
    "to": "1 + 0.1 * Math.sin(time * Math.PI * 2)"
  },
  {
    "type": "bindProperty",
    "node": "dot",
    "property": "x",
    "to": "wiggle(0, 2, 12)"
  }
]
```

### An expression in any field, with an op

`bindProperty` covers the properties commands name. Anywhere else a stored value goes (any field `inspect_motion_node` shows as a number), an op takes `{expression: text}` and stores what it reads as. Here a shape fades in over its first half second with no keys.

On a document that holds:

```json theme={"system"}
[
  {
    "type": "addPath",
    "nodeId": "route",
    "start": 0,
    "duration": 4,
    "path": "M 300,800 C 700,100 1200,1000 1600,300",
    "paint": "stroke",
    "color": "#ffffff",
    "strokeWidth": 6
  },
  {
    "type": "addEffect",
    "node": "route",
    "kind": "trimPath",
    "effectId": "trim",
    "params": {
      "end": 0
    }
  },
  {
    "type": "addShape",
    "nodeId": "dot",
    "start": 0,
    "duration": 4,
    "shape": "circle",
    "box": {
      "x": -12,
      "y": -12,
      "width": 24,
      "height": 24
    },
    "color": "#ff3b30"
  }
]
```

send:

```json theme={"system"}
[
  {
    "type": "node.patch",
    "node": "dot",
    "patch": {
      "common": {
        "opacity": {
          "expression": "clamp(time / 0.5, 0, 1)"
        }
      }
    }
  }
]
```

## What an expression reads

| Write | Gives | | | |
| - | - | - | - | - |
| `time` | seconds on the composition clock, After Effects' time | | | |
| \`time("local" | "composition" | "timeline" | "life")\` | seconds on a clock: `local` since this node's own start (so its animation moves with it), `composition` the clock of the composition it sits in, `timeline` the canvas clock, `life` a particle's life from 0 to 1 |
| `canvas.width, canvas.height` | the canvas size in px | | | |
| `curve(name)` | a named curve of the composition, After Effects' expression control: one value many fields read | | | |
| `prop(name)` | a prop of the composition this value is in; a colour prop reads as \[r, g, b, a] | | | |
| `ref(node, pointer, [seconds])` | the value stored at a JSON pointer into another node of the same composition ("/common/opacity", "/common/transform/translateX", "/common/effects/0/effect/end"), evaluated as that node evaluates it, now or at a second of the composition clock: After Effects' thisComp.layer(name) property. It reads what is stored, not where the node ends up; toComp, nodeBox and nodePath read what is drawn. The canvas's own nodes read each other the same way, from schema version 18 | | | |
| \`node("index" | "count" | "start" | "end", \[node])\` | a fact about a node (this one by default): its place among its siblings from 0, how many siblings there are with it, and the second it starts and ends at on the composition clock; index(), numLayers(), inPoint() and outPoint() give the same. Of a composition's nodes, or of the canvas's own from schema version 18 |
| `call(function, ...arguments)` | runs a curve that is a function with these arguments | | | |
| `particle(property)` | a particle's own value, inside a particle system's look | | | |
| \`textSelector("rank" | "index" | "total" | "selectorValue")\` | the text unit being styled, inside a text animator's expression selector |
| `json({...})` | any stored value written as its JSON (keyframes, a measurement, a marker), for what has no shorter spelling; get\_motion\_schema's document schema gives the shapes | | | |

## Helpers

After Effects' expression helpers, and a few of Motion's own. Each stands for stored values, which is how the document view prints it back.

| Write | Gives | | | | | | | | |
| - | - | - | - | - | - | - | - | - | - |
| `wiggle(value, frequency, amplitude, [octaves = 1], [amplitudeMultiplier = 0.5], [seconds = time])` | value plus smooth noise of `frequency` wiggles a second and `amplitude`, each component its own; octaves (at most 8) add finer noise, each scaled by amplitudeMultiplier | | | | | | | | |
| `posterizeTime(value, framesPerSecond)` | value held at the start of each frame of a `framesPerSecond` grid on the composition clock | | | | | | | | |
| `valueAtTime(value, seconds)` | value read with the composition clock at `seconds`, every clock moved alike | | | | | | | | |
| `smooth(value, [width = 0.2], [samples = 5])` | the mean of `samples` (at most 16) readings of value spread over `width` seconds around now | | | | | | | | |
| \`loopOut(keys, \["cycle" | "pingpong" | "offset" | "continue"], \[keyframes])\` | keyframes that repeat their last `keyframes` keys (all by default) after the last one | | | | | |
| \`loopIn(keys, \["cycle" | "pingpong" | "offset" | "continue"], \[keyframes])\` | keyframes that repeat their first `keyframes` keys (all by default) before the first one | | | | | |
| `lookAt(from, to)` | the angle in degrees of the direction from point `from` to point `to`, for a 2D rotation | | | | | | | | |
| `lookAt3d(from, to)` | the orientation \[x, y, z] in degrees that turns a 3D layer at point `from` to face point `to`, both in world space, as After Effects' lookAt | | | | | | | | |
| \`activeCamera("position" | "direction" | "zoom" | "focusDistance" | "aperture")\` | a value of the camera showing the 3D scene: its world position, unit view direction, zoom, focus distance or aperture in px | | | | |
| `timeToFrames(seconds, framesPerSecond)` | the whole frame `seconds` falls in | | | | | | | | |
| `framesToTime(frames, framesPerSecond)` | the seconds at which frame `frames` starts | | | | | | | | |
| `gaussRandom(seed, ...)` | a normally distributed number (mean 0, deviation 1) hashed from up to 7 seeds | | | | | | | | |
| `index([node])` | the node's place among its siblings, from 0 | | | | | | | | |
| `numLayers([node])` | how many siblings the node has, itself included | | | | | | | | |
| `inPoint([node])` | the second the node starts on the composition clock | | | | | | | | |
| `outPoint([node])` | the second the node ends on the composition clock | | | | | | | | |
| \`marker(node, marker, \["start" | "end"])\` | the second a marker starts (or ends) on the composition clock | | | | | | | |
| `toComp(point, [node], [seconds])` | a point of the node's own space (this node's by default) in its composition as shown, now or at `seconds` on the composition clock; for a node in a 3D scene where the camera shows it, and with a point of 3 numbers its depth ahead of the camera as z | | | | | | | | |
| `fromComp(point, [node], [seconds])` | a point of the composition's space in the node's own space; for a node in a 3D scene, a point of 2 lands on its plane and a point of 3 is x, y and depth ahead of the camera | | | | | | | | |
| `toWorld(point, [node], [seconds])` | a point of the node's own space in its composition's 3D scene, \[x, y, z]; for a node outside a 3D scene, on the canvas with z 0 | | | | | | | | |
| `fromWorld(point, [node], [seconds])` | a point of the 3D scene (of the canvas, outside one) in the node's own space, \[x, y, z] | | | | | | | | |
| `toCompVec(vector, [node], [seconds])` | a direction of the node's own space in its composition's space, without translation | | | | | | | | |
| `fromCompVec(vector, [node], [seconds])` | a direction of the composition's space in the node's own space | | | | | | | | |
| `toWorldVec(vector, [node], [seconds])` | a direction of the node's own space in its composition's 3D scene (on the canvas, outside one), \[x, y, z] | | | | | | | | |
| `fromWorldVec(vector, [node], [seconds])` | a direction of the 3D scene (of the canvas, outside one) in the node's own space, \[x, y, z] | | | | | | | | |
| \`transformPoint(point, "local" | "parent" | "composition" | "canvas" | "world", "local" | "parent" | "composition" | "canvas" | "world", \[node], \[seconds])\` | a point of one of the node's spaces in another |
| `compositionPosition([node], [seconds])` | where the node's own origin \[0, 0] is in its composition's space | | | | | | | | |
| `compositionRotation([node], [seconds])` | the angle in degrees the node's evaluated transform turns its x axis by, in its composition's space | | | | | | | | |
| `compositionScale([node], [seconds])` | \[sx, sy] of the node's evaluated transform in its composition's space; sy is negative when it mirrors | | | | | | | | |
| `compositionMatrix([node], [seconds])` | the 3x3 matrix, row by row, taking the node's own space to its composition's | | | | | | | | |
| `regionMean(node, point, [radius = 0.5], [seconds])` | the average straight \[r, g, b, a] of the node's own drawing over point ± radius in its local space, before its transform and opacity, at a second of the composition clock or now; any other node reference (composited, or a layer stage) is written as json(...) | | | | | | | | |
| `sampleImage(node, point, [radius = 0.5], [seconds])` | After Effects' name for regionMean | | | | | | | | |
| `nodePath(node, [contour = 0], [seconds])` | a contour of a shape node's path as a path value, After Effects' content("Path").path: the whole path, before the node's effects (a trim, dashes) and in the node's own space, so toComp(point, node) is where a point of it shows | | | | | | | | |
| `nodePathLength(node, [seconds])` | the length in px of a shape node's path, every contour, before its effects and its transform | | | | | | | | |
| \`nodeBox("layout" | "content" | "painted" | "lines", "local" | "parent" | "composition", \[node], \[seconds])\` | \[left, top, width, height] of one of a node's boxes (this node's by default) in one of its spaces, read as .left, .top, .width and .height like After Effects' sourceRectAtTime: `layout` is the box layout gave it, `content` what it holds, `painted` what it draws, `lines` its text lines joined | | | |
| `createPath(points, [inTangents], [outTangents], [isClosed])` | makePath: a path of one contour through the points, with each vertex's handles relative to it | | | | | | | | |
| `points(path)` | pathVertices: the path's vertices as a list | | | | | | | | |
| `inTangents(path)` | pathInHandles: each vertex's in handle, relative to it | | | | | | | | |
| `outTangents(path)` | pathOutHandles: each vertex's out handle, relative to it | | | | | | | | |
| `isClosed(path)` | pathClosed: 1 for a closed path, else 0 | | | | | | | | |
| `pointOnPath(path, [percentage = 0.5])` | pathPoint: the point a fraction of the way along the path's length | | | | | | | | |
| `tangentOnPath(path, [percentage = 0.5])` | pathTangent: the unit tangent a fraction of the way along the path | | | | | | | | |
| `normalOnPath(path, [percentage = 0.5])` | pathNormal: the unit normal a fraction of the way along the path | | | | | | | | |
| `list(count, item, [initial])` | a list of `count` (at most 1024) items, each `item` with loopIndex() its index and, given `initial`, loopValue() the item before | | | | | | | | |
| `loopIndex([outer = 0])` | the pass of the enclosing list, fold or accumulate, `outer` loops further out | | | | | | | | |
| `loopValue([outer = 0])` | the value so far of the enclosing loop: a list's item before, a fold's accumulator | | | | | | | | |
| `sub(a, b)` | a - b | | | | | | | | |
| `mul(a, b)` | a \* b | | | | | | | | |
| `div(a, b)` | a / b | | | | | | | | |
| `degreesToRadians(degrees)` | degrees in radians | | | | | | | | |
| `radiansToDegrees(radians)` | radians in degrees | | | | | | | | |

## Operators

The functions the document stores. `+ - * /`, comparisons and `c ? a : b` are shorthands for theirs.

| Write | Gives |
| - | - |
| `add(a, b, ...)` | a + b, componentwise |
| `subtract(a, b, ...)` | a - b, componentwise |
| `multiply(a, b, ...)` | a \* b, componentwise |
| `divide(a, b, ...)` | a / b, componentwise |
| `min(a, b, ...)` | the smallest |
| `max(a, b, ...)` | the largest |
| `abs(a)` | without its sign |
| `clamp(value, min, max)` | value held between min and max |
| `negate(a)` | -a |
| `sin(radians)` | sine |
| `cos(radians)` | cosine |
| `pow(base, exponent)` | base \*\* exponent |
| `sqrt(a)` | square root |
| `floor(a)` | the whole number at or below |
| `ceil(a)` | the whole number at or above |
| `round(a)` | the nearest whole number, halves away from zero (Math.round takes halves up, as JavaScript does) |
| `fround(a)` | rounded to 32-bit precision, as Math.fround |
| `mod(a, b)` | the remainder of a / b that is never negative, so mod(time, 2) loops through 0 to 2 before time 0 as well |
| `mix(a, b, t)` | a + (b - a) \* t: a at t 0, b at t 1, and beyond outside them |
| `smoothstep(edge0, edge1, x)` | 0 below edge0, 1 above edge1, and a smooth S between |
| `step(edge, x)` | 0 when x is below edge, else 1 |
| `random(seed, ...)` | a number from 0 to 1 hashed from its arguments, the same on every render: random(index(), 7) differs per node, random(floor(time \* 4)) changes four times a second |
| `noise(x, [seed = 0])` | smooth noise from -1 to 1 with one wiggle per unit of x |
| `linear(t, tMin, tMax, value1, value2)` | t from tMin..tMax mapped onto value1..value2 and held outside; linear(t, value1, value2) maps t from 0..1 |
| `ease(t, tMin, tMax, value1, value2)` | linear with an eased start and end; ease(t, value1, value2) maps t from 0..1 |
| `easeIn(t, tMin, tMax, value1, value2)` | linear with an eased start |
| `easeOut(t, tMin, tMax, value1, value2)` | linear with an eased end |
| `timeShift(value, seconds)` | value read with every clock moved by seconds: timeShift(curve("x"), -0.2) trails the curve by 0.2 s; valueAtTime(value, t) is timeShift(value, t - time) |
| `tan(radians)` | tangent |
| `asin(a)` | arcsine in radians |
| `acos(a)` | arccosine in radians |
| `atan(a)` | arctangent in radians |
| `atan2(y, x)` | the angle in radians of the direction \[x, y] |
| `exp(a)` | e \*\* a |
| `log(a)` | natural logarithm |
| `sign(a)` | -1, 0 or 1 |
| `degrees(radians)` | radians in degrees |
| `radians(degrees)` | degrees in radians |
| `lessThan(a, b)` | a \< b as 1 or 0 |
| `lessOrEqual(a, b)` | a \<= b as 1 or 0 |
| `greaterThan(a, b)` | a > b as 1 or 0 |
| `greaterOrEqual(a, b)` | a >= b as 1 or 0 |
| `equal(a, b)` | a == b as 1 or 0 |
| `notEqual(a, b)` | a != b as 1 or 0 |
| `and(a, b, ...)` | 1 when none is 0, else 0; every argument is evaluated |
| `or(a, b, ...)` | 1 when any is not 0, else 0; every argument is evaluated |
| `not(a)` | !a: 1 for 0, else 0 |
| `if(condition, then, otherwise)` | condition ? then : otherwise, evaluating only the branch taken |
| `vector(a, b, ...)` | its arguments joined into one vector: vector(point, 1) is \[point.x, point.y, 1] |
| `component(vector, index)` | vector\[index], from 0 |
| `length(vector)` | the vector's length; length(a, b) is distance(a, b) |
| `distance(a, b)` | the distance between two points |
| `dot(a, b)` | dot product |
| `normalize(vector)` | the vector at length 1 |
| `cross(a, b)` | cross product of two 3-vectors |
| `indices(value)` | \[0, 1, ...], as wide as value |
| `velocity(value)` | value's change per second now |
| `keyCount(keys)` | how many keyframes a keyframed value, or a curve or ref that is one, has |
| `keyTime(keys, index)` | the second of keyframe index on the composition clock, from 0 |
| `keyValue(keys, index)` | the value of keyframe index, from 0 |
| `nearestKey(keys)` | the index of the keyframe nearest now |
| `choose(index, a, b, ...)` | the argument at floor(index) after the index, from 0, held to the first and last; only that one is evaluated |
| `itemCount(list)` | how many items a list has |
| `item(list, index)` | the list's item at index, from 0, held to the list |
| `makePath(points, [inTangents], [outTangents], [isClosed])` | a path of one contour; createPath is After Effects' name for it |
| `pathVertices(path)` | points(path) |
| `pathInHandles(path)` | inTangents(path) |
| `pathOutHandles(path)` | outTangents(path) |
| `pathClosed(path)` | isClosed(path) |
| `pathPoint(path, [fraction = 0.5])` | pointOnPath(path, fraction) |
| `pathTangent(path, [fraction = 0.5])` | tangentOnPath(path, fraction) |
| `pathNormal(path, [fraction = 0.5])` | normalOnPath(path, fraction) |

## Limits

* The canvas's own nodes read each other through what is drawn (`nodePath`, `nodeBox`, `toComp`) and through curves. A node's path and its local points are in its own space: `toComp(point, node)` gives where they show. `ref`, `marker`, `index()`, `numLayers()`, `inPoint()` and `outPoint()` read within a composition (a template's nodes) and between the canvas's own nodes. A document whose writer cannot store a read between canvas nodes yet refuses it naming the schema version: there, keep the shared value in a curve and read `curve(name)` from both.
* A curve cannot hold a measurement (`nodePath`, `nodeBox`, `toComp`): measure in the property that needs it, and keep the progress, not the point, in the curve.
* A measurement is read after layout, so what layout depends on cannot read one: a title's `text`, a node's visibility, a prop. A title cannot show `nodePathLength` or a box's width; x, y, rotation, scale, opacity, effect parameters and shader uniforms can read them.
* `view_motion_document` shows every expression in this form, so what you wrote reads back as you wrote it, commands included.

## Differences from JavaScript and After Effects

The language keeps JavaScript's syntax and After Effects' names wherever they mean the same thing. Where it differs, this is why:

| From | There | Here | Why |
| - | - | - | - |
| JavaScript | statements, loops, functions, objects, strings as values | one value; `const` names parts of it, and list(count, item), fold and accumulate (as json) loop a bounded number of times | the text is converted to a tree, never run: every value finishes at a cost known before rendering, is checked before rendering, and stays editable field by field |
| JavaScript | a % b | mod(a, b) | the renderer's remainder is never negative, which is what a looping phase needs; JavaScript's takes the sign of a, so `%` with the renderer's answer would be a silent difference and is refused with this hint |
| JavaScript | a && b, a \|\| b | and(a, b), or(a, b), or c ? a : b | JavaScript's give one of their operands and skip the other; the renderer's give 1 or 0 and evaluate both, so the symbols are refused instead of meaning something else |
| JavaScript | Math.random() | random(seed, ...) | every render of a frame has to agree (the editor, each export segment), so randomness is hashed from what it is given |
| JavaScript | \[1, 2] \* 2 is NaN | \[2, 4] | After Effects' vector arithmetic: positions and colours are vectors |
| JavaScript | 1 / 0 is Infinity | an error: the frame does not render, and an export stops there | a field cannot draw a number that is not finite, and a frame drawn with a made-up one would be wrong without saying so; guard a divisor that can reach 0 with c ? a : b, which evaluates one branch, or max(d, 0.001) |
| JavaScript | x = x + 1 | const y = x + 1 | a value is a tree, not a program with state; a value that carries on from the frame before is accumulate |
| After Effects | thisComp.layer("a").transform.opacity, effect("Blur")("Amount") | ref("a", "/common/opacity") | a document has stored fields, not layer objects: the pointer is the field's place in the node, the one name it already has in node.patch, in a `field:` property and in the schema, so there is no second vocabulary to keep in step. A ref reads within one composition, the canvas's own nodes being one |
| After Effects | wiggle(2, 30), loopOut("cycle"), value, thisProperty | wiggle(value, 2, 30), loopOut(keys, "cycle"), valueAtTime(value, seconds) | an expression is the whole value of its field, with no value underneath for `value` to mean, so a helper is given what it acts on (the setExpression command adds a wiggle or a loop over a property's own keys) |
| After Effects | opacity 50, scale \[50, 50] | 0.5 | Tella writes fractions everywhere, in commands and in the document, so there is one unit |
| After Effects | index and key(n) count from 1 | index(), keyTime(keys, n), item(list, n) and v\[n] count from 0 | every index counts as JavaScript's do, and index() \* 0.1 gives the first node no delay |
| After Effects | random(), random(max), random(min, max), seedRandom(n) | random(seed, ...) from 0 to 1; scale it with mix(min, max, random(seed)) | there is no hidden seed to set: the arguments are the seed, so the same expression gives the same number on every machine |
| After Effects | timeToFrames(t) and framesToTime(f) at the composition's frame rate | timeToFrames(seconds, framesPerSecond), framesToTime(frames, framesPerSecond) | a document has no frame rate of its own: it renders at the rate asked for |
| After Effects | layer.sourceRectAtTime(t), layer.toComp(point), content("Path").path | nodeBox(box, space, \[node], \[seconds]), toComp(point, \[node], \[seconds]), nodePath(node) | values are numbers and vectors, not objects with methods, so the node is an argument; left out, it is the node the expression is on |
| After Effects | lookAt(from, to) gives a 3D orientation | one angle in degrees | a node's rotation in its plane is one number |
| After Effects | toWorld is toComp for a 2D layer | toWorld goes on through nested compositions to the canvas | it is the one space every node shares, which After Effects has no name for |


## Related topics

- [Tella Motion](https://www.tella.com/docs/mcp-tools/motion.md)
- [Tella Motion commands](https://www.tella.com/docs/mcp-tools/motion-commands.md)
- [Tella Motion properties, easing and fonts](https://www.tella.com/docs/mcp-tools/motion-values.md)
- [Get a Tella Motion JSON schema](https://www.tella.com/docs/api-reference/tella-motion/get-a-tella-motion-json-schema.md)
- [Edit a Tella Motion document](https://www.tella.com/docs/api-reference/tella-motion/edit-a-tella-motion-document.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.