005 - Animation System
The Animation System interpolates values over normalized time (0-1).
The Problem
Animations in creative coding are more complicated than they appear:
- Timing – When does what start? How long does it last?
- Easing – Linear movement feels robotic, natural movement accelerates/decelerates
- Coordination – Multiple animations simultaneously, but synchronized
- Loops – Endless, once, back-and-forth?
Without a system, you end up with spaghetti code with if (frame > 60 && frame < 120).
The Solution
The Animation System separates time from value:
- AnimationClock – A clock that runs from 0 to 1 (normalized time)
- Animation – Translates time into a value (e.g., scale from 0.8 to 1.2)
- AnimationComposer – Manages multiple animations on one clock
Why normalized time? Because 0.5 always means "in the middle," whether the animation lasts 1 second or 10 minutes. Easing functions expect 0-1, loops jump from 1 back to 0. Everything becomes simpler.
Why separate Clock? Because you can pause a clock without touching each animation individually. Or attach two animations to the same clock so they run in sync.
Concept
┌───────────────────┐ ┌──────────────────────┐
│ AnimationClock │─────▶│ AnimationComposer │
│ position: 0-1 │ └──────────────────────┘
└───────────────────┘ │
┌────────────┼────────────┐
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Animation │ │ Animation │ │ Animation │
│ 1 │ │ 2 │ │ 3 │
└────────────┘ └────────────┘ └────────────┘
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Value │ │ Value │ │ Value │
└────────────┘ └────────────┘ └────────────┘Core Concept:
- Animation defines: WHEN (Timeline) + HOW (Playback) + WHAT (Value)
- Clock provides normalized time (0-1)
- Composer orchestrates multiple animations
- Each animation produces an interpolated value
Components
| Class | File | Function |
|---|---|---|
AnimationClock |
AnimationClock.ts |
Central Time Source |
AnimationComposer |
AnimationComposer.ts |
Orchestration |
Animation |
Animation.ts |
Base Class |
BreatheAnimation |
BreatheAnimation.ts |
Pulsing |
RotateAnimation |
RotateAnimation.ts |
Rotation |
ShakeAnimation |
ShakeAnimation.ts |
Vibration |
Easing |
Easing.ts |
Easing Functions |
AnimationClock
Central time source with position 0-1.
Properties:
| Property | Type | Description |
|---|---|---|
position |
number |
0-1, current position |
duration |
number |
Duration in seconds |
isPlaying |
boolean |
Currently playing? |
loop |
boolean |
Repeat? |
pingpong |
boolean |
Back and forth? |
Methods:
| Method | Description |
|---|---|
play() |
Start |
pause() |
Pause |
stop() |
Stop & Reset |
seek(pos) |
Jump to position |
tick(deltaTime) |
Frame Update |
Time Modes:
| Mode | Description |
|---|---|
forward |
0 → 1 |
backward |
1 → 0 |
pingpong |
0 → 1 → 0 |
random |
Random position |
AnimationComposer
Orchestrates multiple animations.
API:
| Method | Description |
|---|---|
add(animation) |
Add Animation |
remove(animation) |
Remove Animation |
tick(clock) |
Update All |
getValue(id) |
Get Animation Value |
Animation Base Class
Common structure for all animation types.
Timeline Options:
| Option | Type | Default | Description |
|---|---|---|---|
startTime |
number |
0 | Start (0-1) |
endTime |
number |
1 | End (0-1) |
enabled |
boolean |
true | Active? |
Playback Options:
| Option | Type | Default | Description |
|---|---|---|---|
loop |
boolean |
true | Repeat |
pingpong |
boolean |
false | Back and forth |
easing |
EasingType |
'linear' | Easing Function |
BreatheAnimation
Pulsing value (e.g., for scale).
Options:
| Option | Type | Default | Description |
|---|---|---|---|
min |
number |
0.8 | Minimum |
max |
number |
1.2 | Maximum |
mode |
BreatheMode |
'smooth' | Curve Shape |
Modes:
| Mode | Curve |
|---|---|
smooth |
Sine-based |
sharp |
Triangle Wave |
pulse |
Square Wave |
Output: number (e.g., 0.8 → 1.2 → 0.8)
RotateAnimation
Continuous rotation.
Options:
| Option | Type | Default | Description |
|---|---|---|---|
startAngle |
number |
0 | Start Angle (degrees) |
endAngle |
number |
360 | End Angle (degrees) |
mode |
RotateMode |
'continuous' | Rotation Mode |
Modes:
| Mode | Description |
|---|---|
continuous |
Rotate continuously |
oscillate |
Back and forth |
step |
In steps |
Output: number (angle in degrees)
ShakeAnimation
Vibration / Trembling.
Options:
| Option | Type | Default | Description |
|---|---|---|---|
intensity |
number |
10 | Strength in pixels |
speed |
number |
1 | Speed |
mode |
ShakeMode |
'random' | Shake Pattern |
Modes:
| Mode | Description |
|---|---|
random |
Random |
horizontal |
X-axis only |
vertical |
Y-axis only |
circular |
Circular |
Output: { x: number, y: number } (offset)
Easing
Easing functions for smooth transitions.
Available Easings:
| Category | Types |
|---|---|
| Linear | linear |
| Quad | easeInQuad, easeOutQuad, easeInOutQuad |
| Cubic | easeInCubic, easeOutCubic, easeInOutCubic |
| Quart | easeInQuart, easeOutQuart, easeInOutQuart |
| Sine | easeInSine, easeOutSine, easeInOutSine |
| Expo | easeInExpo, easeOutExpo, easeInOutExpo |
| Bounce | easeInBounce, easeOutBounce, easeInOutBounce |
| Elastic | easeInElastic, easeOutElastic, easeInOutElastic |
Usage:
import { Easing } from '@carstennichte/cc-toolbox';
const eased = Easing.get('easeOutCubic')(t);Tweakpane Integration
All animations have Tweakpane support.
Module Pattern:
| Blade | Function |
|---|---|
enabled |
Animation on/off |
startTime / endTime |
Time Window |
easing |
Easing Dropdown |
| Animation-specific | min/max, intensity, etc. |
Legacy: AnimationTimer
For time-controlled throttling (still used by ColorSet).
| Method | Description |
|---|---|
animate(callback) |
Callback with Interval |
setInterval(ms) |
Set Interval |
start() / stop() |
Start/Stop |