005 - Animation System
Das Animation System interpoliert Werte über normalisierte Zeit (0-1).
Das Problem
Animationen in Creative Coding sind komplizierter als sie aussehen:
- Timing – Wann startet was? Wie lange dauert es?
- Easing – Lineare Bewegung wirkt roboterhaft, natürliche Bewegung beschleunigt/bremst
- Koordination – Mehrere Animationen gleichzeitig, aber synchron
- Loops – Endlos, einmal, hin-und-her?
Ohne System landet man bei Spaghetti-Code mit if (frame > 60 && frame < 120).
Die Lösung
Das Animation System trennt Zeit von Wert:
- AnimationClock – Eine Uhr, die von 0 bis 1 läuft (normalisierte Zeit)
- Animation – Übersetzt Zeit in einen Wert (z.B. Scale von 0.8 bis 1.2)
- AnimationComposer – Verwaltet mehrere Animations an einer Clock
Warum normalisierte Zeit? Weil 0.5 immer "in der Mitte" bedeutet, egal ob die Animation 1 Sekunde oder 10 Minuten dauert. Easing-Funktionen erwarten 0-1, Loops springen von 1 zurück auf 0. Alles wird einfacher.
Warum separate Clock? Weil du eine Clock pausieren kannst, ohne jede Animation einzeln anzufassen. Oder zwei Animationen an dieselbe Clock hängen, damit sie synchron laufen.
Konzept
┌───────────────────┐ ┌──────────────────────┐
│ AnimationClock │─────▶│ AnimationComposer │
│ position: 0-1 │ └──────────────────────┘
└───────────────────┘ │
┌────────────┼────────────┐
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Animation │ │ Animation │ │ Animation │
│ 1 │ │ 2 │ │ 3 │
└────────────┘ └────────────┘ └────────────┘
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Wert │ │ Wert │ │ Wert │
└────────────┘ └────────────┘ └────────────┘Kernkonzept:
- Animation definiert: WHEN (Timeline) + HOW (Playback) + WHAT (Value)
- Clock liefert normalisierte Zeit (0-1)
- Composer orchestriert mehrere Animations
- Jede Animation erzeugt interpolierten Wert
Komponenten
| Klasse | Datei | Funktion |
|---|---|---|
AnimationClock |
AnimationClock.ts |
Zentrale Zeitquelle |
AnimationComposer |
AnimationComposer.ts |
Orchestrierung |
Animation |
Animation.ts |
Basis-Klasse |
BreatheAnimation |
BreatheAnimation.ts |
Pulsieren |
RotateAnimation |
RotateAnimation.ts |
Rotation |
ShakeAnimation |
ShakeAnimation.ts |
Vibration |
Easing |
Easing.ts |
Easing-Funktionen |
AnimationClock
Zentrale Zeitquelle mit position 0-1.
Eigenschaften:
| Property | Typ | Beschreibung |
|---|---|---|
position |
number |
0-1, aktuelle Position |
duration |
number |
Dauer in Sekunden |
isPlaying |
boolean |
Läuft gerade? |
loop |
boolean |
Wiederholen? |
pingpong |
boolean |
Hin und her? |
Methoden:
| Methode | Beschreibung |
|---|---|
play() |
Starten |
pause() |
Pausieren |
stop() |
Stoppen & Reset |
seek(pos) |
Zu Position springen |
tick(deltaTime) |
Frame-Update |
Time Modes:
| Mode | Beschreibung |
|---|---|
forward |
0 → 1 |
backward |
1 → 0 |
pingpong |
0 → 1 → 0 |
random |
Zufällige Position |
AnimationComposer
Orchestriert mehrere Animations.
API:
| Methode | Beschreibung |
|---|---|
add(animation) |
Animation hinzufügen |
remove(animation) |
Animation entfernen |
tick(clock) |
Alle updaten |
getValue(id) |
Wert einer Animation |
Animation Basis-Klasse
Gemeinsame Struktur für alle Animation-Typen.
Timeline-Optionen:
| Option | Typ | Default | Beschreibung |
|---|---|---|---|
startTime |
number |
0 | Start (0-1) |
endTime |
number |
1 | Ende (0-1) |
enabled |
boolean |
true | Aktiv? |
Playback-Optionen:
| Option | Typ | Default | Beschreibung |
|---|---|---|---|
loop |
boolean |
true | Wiederholen |
pingpong |
boolean |
false | Hin und her |
easing |
EasingType |
'linear' | Easing-Funktion |
BreatheAnimation
Pulsierender Wert (z.B. für Scale).
Optionen:
| Option | Typ | Default | Beschreibung |
|---|---|---|---|
min |
number |
0.8 | Minimum |
max |
number |
1.2 | Maximum |
mode |
BreatheMode |
'smooth' | Kurvenform |
Modi:
| Mode | Kurve |
|---|---|
smooth |
Sinus-basiert |
sharp |
Dreiecks-Welle |
pulse |
Rechteck-Welle |
Output: number (z.B. 0.8 → 1.2 → 0.8)
RotateAnimation
Kontinuierliche Rotation.
Optionen:
| Option | Typ | Default | Beschreibung |
|---|---|---|---|
startAngle |
number |
0 | Startwinkel (Grad) |
endAngle |
number |
360 | Endwinkel (Grad) |
mode |
RotateMode |
'continuous' | Rotationsmodus |
Modi:
| Mode | Beschreibung |
|---|---|
continuous |
Durchgehend rotieren |
oscillate |
Hin und her |
step |
In Schritten |
Output: number (Winkel in Grad)
ShakeAnimation
Vibration / Zittern.
Optionen:
| Option | Typ | Default | Beschreibung |
|---|---|---|---|
intensity |
number |
10 | Stärke in Pixel |
speed |
number |
1 | Geschwindigkeit |
mode |
ShakeMode |
'random' | Shake-Muster |
Modi:
| Mode | Beschreibung |
|---|---|
random |
Zufällig |
horizontal |
Nur X-Achse |
vertical |
Nur Y-Achse |
circular |
Kreisförmig |
Output: { x: number, y: number } (Offset)
Easing
Easing-Funktionen für sanfte Übergänge.
Verfügbare Easings:
| Kategorie | Typen |
|---|---|
| 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 |
Verwendung:
import { Easing } from '@carstennichte/cc-toolbox';
const eased = Easing.get('easeOutCubic')(t);Tweakpane Integration
Alle Animations haben Tweakpane-Support.
Module-Pattern:
| Blade | Funktion |
|---|---|
enabled |
Animation an/aus |
startTime / endTime |
Zeitfenster |
easing |
Easing-Dropdown |
| Animation-spezifisch | min/max, intensity, etc. |
Legacy: AnimationTimer
Für zeitgesteuerte Throttling (noch von ColorSet genutzt).
| Methode | Beschreibung |
|---|---|
animate(callback) |
Callback mit Interval |
setInterval(ms) |
Interval setzen |
start() / stop() |
Starten/Stoppen |