The Easing class contains every easing method, as well as a number of static methods used to easily generate new Easing objects and a handful of predefined Easing objects for easy accessibility.
The constructor for Easing objects takes an inFunction, the function used to calculate eased time into the curve. The out and inOut functions can be generated using the given in function.
import { Easing } from 'eaz';
const myEasing: Easing = new Easing((t: number) => t ** 2);
import { Easing } from 'eaz';
const myEasing = new Easing(t => t ** 2);
An easing function should ideally return a value equal to or approximately 0 at time = 0, and a value equal to or approximately 1 at time = 1.
Methods
in(t: number): number
The function used to calculate eased time into the curve
import { Easing } from 'eaz';
const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.in(0.5); // Expected value: 0.125
import { Easing } from 'eaz';
const cubicEasing = Easing.cubic;
const result = cubicEasing.in(0.5); // Expected value: 0.125
The in method is evaluated over the first half of the curve, when time < 0.5, and will usually have upwards concavity
out(t: number): number
The function used to calculate eased time out of the curve, generated using the in function
import { Easing } from 'eaz';
const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.out(0.5); // Expected value: 0.875
import { Easing } from 'eaz';
const cubicEasing = Easing.cubic;
const result = cubicEasing.out(0.5); // Expected value: 0.875
The out method is evaluated over the first half of the curve, when time > 0.5, and will usually have downwards concavity
inOut(t: number): number
The function used to calculate the eased time into the function (where time < 0.5) and subsequently out of the function (where time > 0.5)
import { Easing } from 'eaz';
const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.inOut(0.4); // Expected value: 0.256
import { Easing } from 'eaz';
const cubicEasing = Easing.cubic;
const result = cubicEasing.inOut(0.4); // Expected value: 0.256
inverse(): Easing
Returns a new Easing object for which the in and out functions are reversed
import { Easing } from 'eaz';
const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.in(0.5); // Expected value: 0.125
const inverseResult: number = cubicEasing.inverse().out(0.5); // expected value: 0.125
import { Easing } from 'eaz';
const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.in(0.5); // Expected value: 0.125
const inverseResult: number = cubicEasing.inverse().out(0.5); // expected value: 0.125
Static Methods
inOut(inEasing: Easing, outEasing: Easing, t: number): number
Calculates the in-out eased time of the curve using two different Easing objects for the in and out functions
interpolate(inEasing: Easing, outEasing: Easing, t: number, smoothing: number = 0.25): number
Calculates the in-out eased time of the curve using two different Easing objects for the in and out functions with a smooth the transition between the in and out function