website-astro/src/content/articles/en/after-effects-expressions.mdx

117 lines
5.2 KiB
Plaintext
Raw Normal View History

2022-12-28 10:36:15 +01:00
---
title: After Effects Expressions
subtitle: Animation on steroïds.
lang: en
slug: "after-effects-expressions"
excerpt: Expressions in After Effects have always been blurry for me. I know they exist, I know they're powerful, I know it could save a lot of time and clean complex keyframe filled compositions but… They are hard to learn!
tags: ["Design"]
createdAt: "2019-04-24T09:00:00.000Z"
code: true
---
import AstroImage from "../../../components/AstroImage.astro";
export const basicExpression =
"https://assets.nardu.in/basic_expression_d81b12f1ac.jpeg";
export const shortcut = "https://assets.nardu.in/shortcut_39cc19d383.jpeg";
## An ever lasting battle
There is very little documentation and the existing one is hard to find or very old. Very often I just don't have the time to dive into expression learning while animating even though it could help the entire project on the long term.
So the last time I had to do a complex animation, **I took the damn time!**
## The begining of the end (of keyframes).
Everyone uses expressions whether they know it or not. Most of the time it's a rather transparent process for the animator. For example: when parenting a property to another one, After Effects creates an expression for us.
<AstroImage
src={basicExpression}
width="728"
height="80"
alt="Parenting the position of the form to a null creates an expression."
/>
Over the last updates, Adobe has made an effort to make expressions more accessible to everyone. For example, the expression box is now resembling a code editor thanks to code-coloring and auto-completion features. After Effects expression feel like JavaScript with custom functions.
Those custom functions can be called through a menu once you enabled the expressions on a property. It offers organized shortcut and proper syntax to all of AE native functions and a bunch of JavaScript standard ones.
<AstroImage
src={shortcut}
width="728"
height="322"
alt="Alt + Click the stopwatch to access the shortcuts."
/>
## So I need to learn javascript to do motion design now?
### Why bother?
I know that most animators don't have any kind of development background. However, if Adobe thought it best to let us use expressions, I think we ought to, at least, try.
> A lot of incredible professionals like [Mt Mograph](https://www.mtmograph.com/) and [Video Copilot](https://videocopilot.net/) use expressions.
Like every optimization process, building an expressions knowledge takes time. However, like all optimization process, you will benefit from it afterwards.
### Where to learn
I've gathered a list of my favourite learning grounds. Plenty more exist, **go get'em!**
- [Adobe official expression starter guide (FR)](https://helpx.adobe.com/fr/after-effects/using/expression-language-reference.html)
- [Adobe official expression basic (EN)](https://helpx.adobe.com/after-effects/using/expression-basics.html)
- [Adobe forums for expressions](https://community.adobe.com/t5/after-effects/bd-p/after-effects?page=1&sort=latest_replies&filter=all&topics=label-expressions)
- [Creative Cow expressions forums](https://creativecow.net/forums/forum/adobe-after-effects-expressions/)
- [Youtube channel about expressions](https://www.youtube.com/playlist?list=PLvr5U5ZSt6IzHyvSL9fo0M9NRPsTvra31)
- [All expressions explained](http://aescript.jecool.net/reference/)
- [All expressions explained again](http://expressions.aenhancers.com/index.html)
- [Nice examples of basic expressions](https://www.schoolofmotion.com/tutorials/amazing-expressions-in-after-effects)
## Real world example
### Number counter
Let's say you need to animate a rather simple counter from 0% to 100%.
- Start by creating a text layer. Define your typographic choices, colours, etc.
- On the effect menu add expression options > slider control
- Alt + Click the Source text property
<video width="728" loop controls preload="metadata">
<source src="https://assets.nardu.in/alt-counter.mp4" type="video/mp4" />
</video>
- Parent the source text to the slider control through the pickwhip.
<video width="462" loop controls preload="metadata">
<source src="https://assets.nardu.in/pickwhip.mp4" type="video/mp4" />
</video>
You should get something like this in the expressions panel:
```javascript
effect("Slider Control")("Slider")
```
- Set two keyframes on the slider from 0 to 100. The text should update accordingly.
- By default, After Effects does not round numbers. In the expression panel, wrap your expression with the `Math.round()` function.
<video width="728" loop controls preload="metadata">
<source src="https://assets.nardu.in/round.mp4" type="video/mp4" />
</video>
```javascript
Math.round(effect("Slider Control")("Slider"))
```
Great! We have a working counter. But we wanted a percentage counter. We could add a % glyph in another text layer but let's not.
Still in the expression panel, we're going to add a string containing the % glyph, using basic JavaScript concatenation: `+ '%'`
```javascript
Math.round(effect("Slider Control")("Slider")) + '%'
```
<video width="538" loop controls preload="metadata">
<source src="https://assets.nardu.in/percent.mp4" type="video/mp4" />
</video>
**And there we go!** A fully functioning and customizable counter using a slider controller and expressions.