Skip to content

easing

Import from @pierre/ecs/modules/easing.

The standard Robert Penner easing curves — pure, domain-free, zero-dependency functions that reshape normalized time.

type Easing = (t: number) => number; // t ∈ [0,1] → eased progress

Compose an easing with a value interpolation (lerp from modules/math, or the modules/tween primitive which does this for you):

import { easeOutCubic } from '@pierre/ecs/modules/easing';
import { lerp } from '@pierre/ecs/modules/math';
const value = lerp(from, to, easeOutCubic(t));

Every family ships easeIn*, easeOut*, easeInOut*, plus linear:

linear · Quad · Cubic · Quart · Quint · Sine · Expo · Circ · Back · Elastic · Bounce (31 functions total).

  • easeIn* accelerates from rest; easeOut* decelerates to rest; easeInOut* is symmetric (exactly 0.5 at t = 0.5).
  • All pin f(0) = 0 and f(1) = 1.
  • Back and Elastic deliberately overshoot [0, 1] (anticipation / spring). Compose clamp01 from modules/math if your target can’t exceed its bounds.
import { easeOutBack, easeInOutSine } from '@pierre/ecs/modules/easing';
// Pop-in with a little overshoot:
sprite.scale = lerp(0, 1, easeOutBack(progress));
// Smooth camera bob:
camera.y = lerp(low, high, easeInOutSine(progress));

Import via @pierre/ecs/modules/easing. Depends on nothing.