eKeys
Keyframe animation in Expressions, with full control over easing
jsanimate(keyframes);
The problem
When making templates in After Effects, you often need to set the time and/or value of keyframes dynamically.
This is traditionally done by remapping either time, or the animated value using the interpolation functions linear() and ease().
While it works, this involves a lot of boilerplate code, and you're unable to have control of the easing within expressions.
The solution
eKeys is a library for animating with expressions, with the same level of control as keyframes.
js// Import eKeys libraryconst { animate } = footage("eKeys.jsx").sourceData;// Create an array of keyframesconst keyframes = [{keyTime: 0,keyValue: [0, 0],easeOut: 66,},{keyTime: thisComp.duration,keyValue: otherLayer.transform.position,easeIn: 90,},];// Animateanimate(keyframes);
With eKeys you create your keyframes as an array of JavaScript objects, allowing you to set each of their properties dynamically.
Usage
Import
Download the library .jsx file and import it into your After Effects project.
It's also a good idea to place the file in any compositions where it's used, so that After Effects will count it as used when reducing the project.
Reference the library
The animate function takes an array of keyframes, and returns the animated value.
javascriptconst { animate } = footage("eKeys.jsx").sourceData;
Create keyframes
javascript// Example keyframe arrayconst keys = [{keyTime: 1,keyValue: [0, 0],easeIn: 0,easeOut: 66,},{keyTime: 2,keyValue: [thisComp.width / 2, 0],easeIn: 90,easeOut: 0,},];
While it is recommended you order the keyframes according to their keyTime for the sake of readability, it is not required as they are sorted before the animation is calculated.
Animate
The final animated value can be returned by calling the animate function with an array of keyframes.
jsanimate(keys);
Custom Interpolators
eKeys uses a bezier algorithm to interpolate between keyframe values with custom easing and velocity. In some cases, you may want to opt out of this interpolation and use a different method instead.
You can do this by passing a custom interpolation function to animate that takes in the current progress value and returns a new one.
For example, simple linear easing:
js// Interpolate with linear progressanimate(keys, { interpolator: (t) => t });
While eKeys is fast, it will be a lot faster if you use a simple interpolation method rather than the complex bezier algorithm.
Or to use After Effects built in easing functions:
js// Interpolate with the ae easing functionanimate(keys, { interpolator: (t) => ease(t, 0, 1) });
Exported Interpolators
eKeys also exports a variety of popular easing functions you can use.
These are exported as properties on the interpolators object.
jsimport { animate, interpolators } = footage('eKeys.jsx').sourceData;const keys = [] // Keyframesanimate(keys, { interpolator: interpolators.easeInElastic })
API
Animate
function
tsanimate(keys: Keyframe[], options: AnimateOptions): KeyValueType;
Parameters
keysThe keyframes to animate betweenoptions(specified below)
Returns
The animated value, of the same type as the key values. eKeys will error if the values aren't of the same type.
Keyframes
type
tstype Keyframe = {keyTime: number;keyValue: number | number[];easeIn?: number = 33;easeOut?: number = 33;velocityIn?: number = 0;velocityOut?: number = 0;};
Properties
keyTimeThis location of the key in timekeyValueThe value to set at the key timeeaseInThe amount to ease in to the keyframeeaseOutThe amount to ease out of the keyframevelocityInThe velocity to enter the keyframe atvelocityOutThe velocity to exit the keyframe at
ease and velocity properties are a percentage between 0 and 100.
Options
type
tstype AnimateOptions = {inputTime: number;interpolator: (progress: number, easeOut?: number, easeIn?: number) => number;};
Properties
inputTmeThe time value to get the animation at, which defaults to the current time. For example, to increase the animation speed passinputTime: time * 2interpolatorThe function to use to interpolate between keyframes, which takes the animation progress and easings as input and returns a modified progress value. For example, for linear easing passinterpolator: x => x
Checking the version
All of our libraries expose a version string you can use to check if it's up to date:
jsthrow footage("lib.jsx").sourceData.version;