@redwilly/anima 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/SceneLoader.d.ts +22 -0
- package/dist/cli/SceneLoader.js +47 -0
- package/dist/cli/commands/export-frame.d.ts +13 -0
- package/dist/cli/commands/export-frame.js +60 -0
- package/dist/cli/commands/list-scenes.d.ts +5 -0
- package/dist/cli/commands/list-scenes.js +22 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.js +11 -0
- package/dist/cli/commands/render.d.ts +16 -0
- package/dist/cli/commands/render.js +76 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +63 -0
- package/dist/core/animations/Animation.d.ts +41 -0
- package/dist/core/animations/Animation.js +76 -0
- package/dist/core/animations/camera/Follow.d.ts +70 -0
- package/dist/core/animations/camera/Follow.js +69 -0
- package/dist/core/animations/camera/Shake.d.ts +90 -0
- package/dist/core/animations/camera/Shake.js +87 -0
- package/dist/core/animations/camera/index.d.ts +2 -0
- package/dist/core/animations/camera/index.js +2 -0
- package/dist/core/animations/categories/ExitAnimation.d.ts +17 -0
- package/dist/core/animations/categories/ExitAnimation.js +15 -0
- package/dist/core/animations/categories/IntroductoryAnimation.d.ts +16 -0
- package/dist/core/animations/categories/IntroductoryAnimation.js +14 -0
- package/dist/core/animations/categories/TransformativeAnimation.d.ts +25 -0
- package/dist/core/animations/categories/TransformativeAnimation.js +25 -0
- package/dist/core/animations/categories/index.d.ts +3 -0
- package/dist/core/animations/categories/index.js +3 -0
- package/dist/core/animations/composition/Parallel.d.ts +37 -0
- package/dist/core/animations/composition/Parallel.js +79 -0
- package/dist/core/animations/composition/Sequence.d.ts +41 -0
- package/dist/core/animations/composition/Sequence.js +95 -0
- package/dist/core/animations/composition/index.d.ts +2 -0
- package/dist/core/animations/composition/index.js +3 -0
- package/dist/core/animations/draw/Draw.d.ts +30 -0
- package/dist/core/animations/draw/Draw.js +122 -0
- package/dist/core/animations/draw/Unwrite.d.ts +30 -0
- package/dist/core/animations/draw/Unwrite.js +120 -0
- package/dist/core/animations/draw/Write.d.ts +35 -0
- package/dist/core/animations/draw/Write.js +119 -0
- package/dist/core/animations/draw/index.d.ts +3 -0
- package/dist/core/animations/draw/index.js +3 -0
- package/dist/core/animations/draw/partialPath.d.ts +6 -0
- package/dist/core/animations/draw/partialPath.js +138 -0
- package/dist/core/animations/easing/bounce.d.ts +13 -0
- package/dist/core/animations/easing/bounce.js +37 -0
- package/dist/core/animations/easing/index.d.ts +7 -0
- package/dist/core/animations/easing/index.js +11 -0
- package/dist/core/animations/easing/manim.d.ts +46 -0
- package/dist/core/animations/easing/manim.js +102 -0
- package/dist/core/animations/easing/registry.d.ts +8 -0
- package/dist/core/animations/easing/registry.js +25 -0
- package/dist/core/animations/easing/standard.d.ts +113 -0
- package/dist/core/animations/easing/standard.js +151 -0
- package/dist/core/animations/easing/types.d.ts +6 -0
- package/dist/core/animations/easing/types.js +0 -0
- package/dist/core/animations/fade/FadeIn.d.ts +17 -0
- package/dist/core/animations/fade/FadeIn.js +22 -0
- package/dist/core/animations/fade/FadeOut.d.ts +17 -0
- package/dist/core/animations/fade/FadeOut.js +23 -0
- package/dist/core/animations/fade/index.d.ts +2 -0
- package/dist/core/animations/fade/index.js +2 -0
- package/dist/core/animations/index.d.ts +11 -0
- package/dist/core/animations/index.js +17 -0
- package/dist/core/animations/keyframes/KeyframeAnimation.d.ts +33 -0
- package/dist/core/animations/keyframes/KeyframeAnimation.js +40 -0
- package/dist/core/animations/keyframes/KeyframeTrack.d.ts +31 -0
- package/dist/core/animations/keyframes/KeyframeTrack.js +83 -0
- package/dist/core/animations/keyframes/index.d.ts +4 -0
- package/dist/core/animations/keyframes/index.js +5 -0
- package/dist/core/animations/keyframes/types.d.ts +25 -0
- package/dist/core/animations/keyframes/types.js +6 -0
- package/dist/core/animations/morph/MorphTo.d.ts +22 -0
- package/dist/core/animations/morph/MorphTo.js +42 -0
- package/dist/core/animations/morph/index.d.ts +1 -0
- package/dist/core/animations/morph/index.js +1 -0
- package/dist/core/animations/transform/MoveTo.d.ts +24 -0
- package/dist/core/animations/transform/MoveTo.js +38 -0
- package/dist/core/animations/transform/Rotate.d.ts +23 -0
- package/dist/core/animations/transform/Rotate.js +34 -0
- package/dist/core/animations/transform/Scale.d.ts +23 -0
- package/dist/core/animations/transform/Scale.js +35 -0
- package/dist/core/animations/transform/index.d.ts +3 -0
- package/dist/core/animations/transform/index.js +3 -0
- package/dist/core/animations/types.d.ts +52 -0
- package/dist/core/animations/types.js +6 -0
- package/dist/core/camera/Camera.d.ts +87 -0
- package/dist/core/camera/Camera.js +175 -0
- package/dist/core/camera/CameraFrame.d.ts +242 -0
- package/dist/core/camera/CameraFrame.js +322 -0
- package/dist/core/camera/index.d.ts +4 -0
- package/dist/core/camera/index.js +3 -0
- package/dist/core/camera/types.d.ts +17 -0
- package/dist/core/camera/types.js +1 -0
- package/dist/core/errors/AnimationErrors.d.ts +12 -0
- package/dist/core/errors/AnimationErrors.js +37 -0
- package/dist/core/errors/index.d.ts +1 -0
- package/dist/core/errors/index.js +1 -0
- package/dist/core/math/Vector2/Vector2.d.ts +23 -0
- package/dist/core/math/Vector2/Vector2.js +46 -0
- package/dist/core/math/Vector2/index.d.ts +1 -0
- package/dist/core/math/Vector2/index.js +1 -0
- package/dist/core/math/bezier/BezierPath.d.ts +38 -0
- package/dist/core/math/bezier/BezierPath.js +264 -0
- package/dist/core/math/bezier/evaluators.d.ts +9 -0
- package/dist/core/math/bezier/evaluators.js +36 -0
- package/dist/core/math/bezier/index.d.ts +8 -0
- package/dist/core/math/bezier/index.js +6 -0
- package/dist/core/math/bezier/length.d.ts +5 -0
- package/dist/core/math/bezier/length.js +27 -0
- package/dist/core/math/bezier/morphing.d.ts +16 -0
- package/dist/core/math/bezier/morphing.js +151 -0
- package/dist/core/math/bezier/sampling.d.ts +7 -0
- package/dist/core/math/bezier/sampling.js +153 -0
- package/dist/core/math/bezier/split.d.ts +19 -0
- package/dist/core/math/bezier/split.js +44 -0
- package/dist/core/math/bezier/types.d.ts +8 -0
- package/dist/core/math/bezier/types.js +0 -0
- package/dist/core/math/color/Color.d.ts +28 -0
- package/dist/core/math/color/Color.js +60 -0
- package/dist/core/math/color/conversions.d.ts +17 -0
- package/dist/core/math/color/conversions.js +100 -0
- package/dist/core/math/color/index.d.ts +2 -0
- package/dist/core/math/color/index.js +2 -0
- package/dist/core/math/index.d.ts +4 -0
- package/dist/core/math/index.js +5 -0
- package/dist/core/math/matrix/Matrix3x3.d.ts +23 -0
- package/dist/core/math/matrix/Matrix3x3.js +91 -0
- package/dist/core/math/matrix/factories.d.ts +12 -0
- package/dist/core/math/matrix/factories.js +44 -0
- package/dist/core/math/matrix/index.d.ts +2 -0
- package/dist/core/math/matrix/index.js +2 -0
- package/dist/core/renderer/FrameRenderer.d.ts +37 -0
- package/dist/core/renderer/FrameRenderer.js +75 -0
- package/dist/core/renderer/ProgressReporter.d.ts +19 -0
- package/dist/core/renderer/ProgressReporter.js +58 -0
- package/dist/core/renderer/Renderer.d.ts +36 -0
- package/dist/core/renderer/Renderer.js +102 -0
- package/dist/core/renderer/drawMobject.d.ts +8 -0
- package/dist/core/renderer/drawMobject.js +109 -0
- package/dist/core/renderer/formats/index.d.ts +3 -0
- package/dist/core/renderer/formats/index.js +3 -0
- package/dist/core/renderer/formats/png.d.ts +5 -0
- package/dist/core/renderer/formats/png.js +7 -0
- package/dist/core/renderer/formats/sprite.d.ts +6 -0
- package/dist/core/renderer/formats/sprite.js +24 -0
- package/dist/core/renderer/formats/video.d.ts +8 -0
- package/dist/core/renderer/formats/video.js +51 -0
- package/dist/core/renderer/index.d.ts +7 -0
- package/dist/core/renderer/index.js +9 -0
- package/dist/core/renderer/types.d.ts +87 -0
- package/dist/core/renderer/types.js +13 -0
- package/dist/core/scene/Scene.d.ts +104 -0
- package/dist/core/scene/Scene.js +225 -0
- package/dist/core/scene/index.d.ts +2 -0
- package/dist/core/scene/index.js +1 -0
- package/dist/core/scene/types.d.ts +23 -0
- package/dist/core/scene/types.js +0 -0
- package/dist/core/serialization/animation.d.ts +23 -0
- package/dist/core/serialization/animation.js +176 -0
- package/dist/core/serialization/easingLookup.d.ts +13 -0
- package/dist/core/serialization/easingLookup.js +65 -0
- package/dist/core/serialization/index.d.ts +23 -0
- package/dist/core/serialization/index.js +29 -0
- package/dist/core/serialization/mobject.d.ts +23 -0
- package/dist/core/serialization/mobject.js +248 -0
- package/dist/core/serialization/prettyPrint.d.ts +12 -0
- package/dist/core/serialization/prettyPrint.js +16 -0
- package/dist/core/serialization/primitives.d.ts +24 -0
- package/dist/core/serialization/primitives.js +98 -0
- package/dist/core/serialization/registry.d.ts +29 -0
- package/dist/core/serialization/registry.js +39 -0
- package/dist/core/serialization/scene.d.ts +28 -0
- package/dist/core/serialization/scene.js +114 -0
- package/dist/core/serialization/types.d.ts +152 -0
- package/dist/core/serialization/types.js +6 -0
- package/dist/core/timeline/Timeline.d.ts +70 -0
- package/dist/core/timeline/Timeline.js +144 -0
- package/dist/core/timeline/index.d.ts +5 -0
- package/dist/core/timeline/index.js +4 -0
- package/dist/core/timeline/types.d.ts +29 -0
- package/dist/core/timeline/types.js +0 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +22 -0
- package/dist/mobjects/Mobject.d.ts +98 -0
- package/dist/mobjects/Mobject.js +343 -0
- package/dist/mobjects/VGroup/VGroup.d.ts +51 -0
- package/dist/mobjects/VGroup/VGroup.js +142 -0
- package/dist/mobjects/VGroup/index.d.ts +3 -0
- package/dist/mobjects/VGroup/index.js +2 -0
- package/dist/mobjects/VGroup/layout.d.ts +20 -0
- package/dist/mobjects/VGroup/layout.js +139 -0
- package/dist/mobjects/VMobject.d.ts +106 -0
- package/dist/mobjects/VMobject.js +216 -0
- package/dist/mobjects/geometry/Arc.d.ts +8 -0
- package/dist/mobjects/geometry/Arc.js +46 -0
- package/dist/mobjects/geometry/Arrow.d.ts +7 -0
- package/dist/mobjects/geometry/Arrow.js +34 -0
- package/dist/mobjects/geometry/Circle.d.ts +4 -0
- package/dist/mobjects/geometry/Circle.js +10 -0
- package/dist/mobjects/geometry/Line.d.ts +8 -0
- package/dist/mobjects/geometry/Line.js +19 -0
- package/dist/mobjects/geometry/Point.d.ts +5 -0
- package/dist/mobjects/geometry/Point.js +11 -0
- package/dist/mobjects/geometry/Polygon.d.ts +7 -0
- package/dist/mobjects/geometry/Polygon.js +21 -0
- package/dist/mobjects/geometry/Rectangle.d.ts +6 -0
- package/dist/mobjects/geometry/Rectangle.js +18 -0
- package/dist/mobjects/geometry/index.d.ts +7 -0
- package/dist/mobjects/geometry/index.js +7 -0
- package/dist/mobjects/graph/Graph.d.ts +28 -0
- package/dist/mobjects/graph/Graph.js +119 -0
- package/dist/mobjects/graph/GraphEdge.d.ts +26 -0
- package/dist/mobjects/graph/GraphEdge.js +64 -0
- package/dist/mobjects/graph/GraphNode.d.ts +19 -0
- package/dist/mobjects/graph/GraphNode.js +63 -0
- package/dist/mobjects/graph/index.d.ts +5 -0
- package/dist/mobjects/graph/index.js +5 -0
- package/dist/mobjects/graph/layouts/circular.d.ts +8 -0
- package/dist/mobjects/graph/layouts/circular.js +23 -0
- package/dist/mobjects/graph/layouts/forceDirected.d.ts +9 -0
- package/dist/mobjects/graph/layouts/forceDirected.js +102 -0
- package/dist/mobjects/graph/layouts/index.d.ts +3 -0
- package/dist/mobjects/graph/layouts/index.js +3 -0
- package/dist/mobjects/graph/layouts/tree.d.ts +9 -0
- package/dist/mobjects/graph/layouts/tree.js +99 -0
- package/dist/mobjects/graph/types.d.ts +35 -0
- package/dist/mobjects/graph/types.js +0 -0
- package/dist/mobjects/index.d.ts +6 -0
- package/dist/mobjects/index.js +6 -0
- package/dist/mobjects/text/Glyph.d.ts +11 -0
- package/dist/mobjects/text/Glyph.js +72 -0
- package/dist/mobjects/text/Text.d.ts +19 -0
- package/dist/mobjects/text/Text.js +76 -0
- package/dist/mobjects/text/index.d.ts +4 -0
- package/dist/mobjects/text/index.js +3 -0
- package/dist/mobjects/text/types.d.ts +12 -0
- package/dist/mobjects/text/types.js +8 -0
- package/package.json +51 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { TransformativeAnimation } from '../categories';
|
|
2
|
+
import { CameraFrame } from '../../camera/CameraFrame';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Shake animation.
|
|
5
|
+
*/
|
|
6
|
+
interface ShakeConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Maximum displacement distance in world units.
|
|
9
|
+
* Higher values create more violent shaking.
|
|
10
|
+
* @default 0.2
|
|
11
|
+
*/
|
|
12
|
+
intensity?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Number of oscillations per second.
|
|
15
|
+
* Higher values create faster, more frantic shaking.
|
|
16
|
+
* @default 10
|
|
17
|
+
*/
|
|
18
|
+
frequency?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Controls how quickly the shake diminishes over time.
|
|
21
|
+
* - 0 = no decay (constant intensity throughout)
|
|
22
|
+
* - 1 = linear decay
|
|
23
|
+
* - Higher values = faster decay (shake fades quickly)
|
|
24
|
+
* @default 1
|
|
25
|
+
*/
|
|
26
|
+
decay?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Camera shake effect animation.
|
|
30
|
+
* Creates procedural displacement using layered sine waves to simulate
|
|
31
|
+
* impacts, explosions, or earthquakes.
|
|
32
|
+
*
|
|
33
|
+
* The shake automatically returns to the original position when complete.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Basic shake effect
|
|
37
|
+
* this.play(new Shake(this.frame).duration(0.5));
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Intense explosion shake with quick decay
|
|
41
|
+
* this.play(new Shake(this.frame, {
|
|
42
|
+
* intensity: 0.5,
|
|
43
|
+
* frequency: 20,
|
|
44
|
+
* decay: 2
|
|
45
|
+
* }).duration(0.3));
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Subtle earthquake with slow decay
|
|
49
|
+
* this.play(new Shake(this.frame, {
|
|
50
|
+
* intensity: 0.1,
|
|
51
|
+
* frequency: 5,
|
|
52
|
+
* decay: 0.5
|
|
53
|
+
* }).duration(3));
|
|
54
|
+
*/
|
|
55
|
+
export declare class Shake extends TransformativeAnimation<CameraFrame> {
|
|
56
|
+
private originalPosition;
|
|
57
|
+
private readonly intensity;
|
|
58
|
+
private readonly frequency;
|
|
59
|
+
private readonly decay;
|
|
60
|
+
private readonly seedX;
|
|
61
|
+
private readonly seedY;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new Shake animation.
|
|
64
|
+
*
|
|
65
|
+
* @param frame - The CameraFrame to shake
|
|
66
|
+
* @param config - Configuration options for intensity, frequency, and decay
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const shake = new Shake(scene.frame, { intensity: 0.3 });
|
|
70
|
+
* this.play(shake.duration(0.5));
|
|
71
|
+
*/
|
|
72
|
+
constructor(frame: CameraFrame, config?: ShakeConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Captures the original position before shake begins.
|
|
75
|
+
*/
|
|
76
|
+
protected captureStartState(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Applies procedural shake displacement each frame.
|
|
79
|
+
* @param progress - Animation progress (0 to 1)
|
|
80
|
+
*/
|
|
81
|
+
interpolate(progress: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Generates pseudo-random noise using layered sine waves.
|
|
84
|
+
* @param t - Time value
|
|
85
|
+
* @param seed - Random seed for variation
|
|
86
|
+
* @returns Noise value between -1 and 1
|
|
87
|
+
*/
|
|
88
|
+
private noise;
|
|
89
|
+
}
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TransformativeAnimation } from '../categories';
|
|
2
|
+
/**
|
|
3
|
+
* Camera shake effect animation.
|
|
4
|
+
* Creates procedural displacement using layered sine waves to simulate
|
|
5
|
+
* impacts, explosions, or earthquakes.
|
|
6
|
+
*
|
|
7
|
+
* The shake automatically returns to the original position when complete.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Basic shake effect
|
|
11
|
+
* this.play(new Shake(this.frame).duration(0.5));
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Intense explosion shake with quick decay
|
|
15
|
+
* this.play(new Shake(this.frame, {
|
|
16
|
+
* intensity: 0.5,
|
|
17
|
+
* frequency: 20,
|
|
18
|
+
* decay: 2
|
|
19
|
+
* }).duration(0.3));
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Subtle earthquake with slow decay
|
|
23
|
+
* this.play(new Shake(this.frame, {
|
|
24
|
+
* intensity: 0.1,
|
|
25
|
+
* frequency: 5,
|
|
26
|
+
* decay: 0.5
|
|
27
|
+
* }).duration(3));
|
|
28
|
+
*/
|
|
29
|
+
export class Shake extends TransformativeAnimation {
|
|
30
|
+
originalPosition;
|
|
31
|
+
intensity;
|
|
32
|
+
frequency;
|
|
33
|
+
decay;
|
|
34
|
+
seedX;
|
|
35
|
+
seedY;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new Shake animation.
|
|
38
|
+
*
|
|
39
|
+
* @param frame - The CameraFrame to shake
|
|
40
|
+
* @param config - Configuration options for intensity, frequency, and decay
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const shake = new Shake(scene.frame, { intensity: 0.3 });
|
|
44
|
+
* this.play(shake.duration(0.5));
|
|
45
|
+
*/
|
|
46
|
+
constructor(frame, config = {}) {
|
|
47
|
+
super(frame);
|
|
48
|
+
this.intensity = config.intensity ?? 0.2;
|
|
49
|
+
this.frequency = config.frequency ?? 10;
|
|
50
|
+
this.decay = config.decay ?? 1;
|
|
51
|
+
this.seedX = Math.random() * 1000;
|
|
52
|
+
this.seedY = Math.random() * 1000;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Captures the original position before shake begins.
|
|
56
|
+
*/
|
|
57
|
+
captureStartState() {
|
|
58
|
+
this.originalPosition = this.target.position;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Applies procedural shake displacement each frame.
|
|
62
|
+
* @param progress - Animation progress (0 to 1)
|
|
63
|
+
*/
|
|
64
|
+
interpolate(progress) {
|
|
65
|
+
this.ensureInitialized();
|
|
66
|
+
if (progress >= 1) {
|
|
67
|
+
this.target.pos(this.originalPosition.x, this.originalPosition.y);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const decayFactor = 1 - Math.pow(progress, this.decay);
|
|
71
|
+
const time = progress * this.durationSeconds * this.frequency;
|
|
72
|
+
const offsetX = this.noise(time, this.seedX) * this.intensity * decayFactor;
|
|
73
|
+
const offsetY = this.noise(time, this.seedY) * this.intensity * decayFactor;
|
|
74
|
+
this.target.pos(this.originalPosition.x + offsetX, this.originalPosition.y + offsetY);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Generates pseudo-random noise using layered sine waves.
|
|
78
|
+
* @param t - Time value
|
|
79
|
+
* @param seed - Random seed for variation
|
|
80
|
+
* @returns Noise value between -1 and 1
|
|
81
|
+
*/
|
|
82
|
+
noise(t, seed) {
|
|
83
|
+
return Math.sin(t * 2 + seed) * 0.5 +
|
|
84
|
+
Math.sin(t * 3.7 + seed * 1.3) * 0.3 +
|
|
85
|
+
Math.sin(t * 7.1 + seed * 0.7) * 0.2;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Animation } from '../Animation';
|
|
2
|
+
import type { AnimationLifecycle } from '../types';
|
|
3
|
+
import type { Mobject } from '../../../mobjects/Mobject';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for animations that exit/remove an object from the scene.
|
|
6
|
+
*
|
|
7
|
+
* Exit animations:
|
|
8
|
+
* - Require the target to already be registered with the scene
|
|
9
|
+
* - Throw an error if the target is not in the scene
|
|
10
|
+
* - Typically animate opacity or scale to 0
|
|
11
|
+
* - May optionally auto-remove the target from the scene after completion
|
|
12
|
+
*
|
|
13
|
+
* Examples: FadeOut, ShrinkToCenter, Uncreate
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class ExitAnimation<T extends Mobject = Mobject> extends Animation<T> {
|
|
16
|
+
readonly lifecycle: AnimationLifecycle;
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Animation } from '../Animation';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for animations that exit/remove an object from the scene.
|
|
4
|
+
*
|
|
5
|
+
* Exit animations:
|
|
6
|
+
* - Require the target to already be registered with the scene
|
|
7
|
+
* - Throw an error if the target is not in the scene
|
|
8
|
+
* - Typically animate opacity or scale to 0
|
|
9
|
+
* - May optionally auto-remove the target from the scene after completion
|
|
10
|
+
*
|
|
11
|
+
* Examples: FadeOut, ShrinkToCenter, Uncreate
|
|
12
|
+
*/
|
|
13
|
+
export class ExitAnimation extends Animation {
|
|
14
|
+
lifecycle = 'exit';
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Animation } from '../Animation';
|
|
2
|
+
import type { AnimationLifecycle } from '../types';
|
|
3
|
+
import type { Mobject } from '../../../mobjects/Mobject';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for animations that introduce an object to the scene.
|
|
6
|
+
*
|
|
7
|
+
* Introductory animations:
|
|
8
|
+
* - Automatically register the target with the scene if not already present
|
|
9
|
+
* - Do not require the target to be in the scene beforehand
|
|
10
|
+
* - Typically animate opacity or drawing from 0 to visible
|
|
11
|
+
*
|
|
12
|
+
* Examples: FadeIn, Write, Draw, GrowFromCenter, SpinIn
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class IntroductoryAnimation<T extends Mobject = Mobject> extends Animation<T> {
|
|
15
|
+
readonly lifecycle: AnimationLifecycle;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Animation } from '../Animation';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for animations that introduce an object to the scene.
|
|
4
|
+
*
|
|
5
|
+
* Introductory animations:
|
|
6
|
+
* - Automatically register the target with the scene if not already present
|
|
7
|
+
* - Do not require the target to be in the scene beforehand
|
|
8
|
+
* - Typically animate opacity or drawing from 0 to visible
|
|
9
|
+
*
|
|
10
|
+
* Examples: FadeIn, Write, Draw, GrowFromCenter, SpinIn
|
|
11
|
+
*/
|
|
12
|
+
export class IntroductoryAnimation extends Animation {
|
|
13
|
+
lifecycle = 'introductory';
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Animation } from '../Animation';
|
|
2
|
+
import type { AnimationLifecycle } from '../types';
|
|
3
|
+
import type { Mobject } from '../../../mobjects/Mobject';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for animations that transform an existing scene object.
|
|
6
|
+
*
|
|
7
|
+
* Transformative animations:
|
|
8
|
+
* - Require the target to already be registered with the scene
|
|
9
|
+
* - Throw an error if the target is not in the scene
|
|
10
|
+
* - Operate on objects that are already visible or have been introduced
|
|
11
|
+
* - Use lazy initialization to capture start state when animation becomes active
|
|
12
|
+
*
|
|
13
|
+
* Examples: MoveTo, Rotate, Scale, MorphTo, Transform
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class TransformativeAnimation<T extends Mobject = Mobject> extends Animation<T> {
|
|
16
|
+
readonly lifecycle: AnimationLifecycle;
|
|
17
|
+
protected initialized: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Captures the start state from the target.
|
|
20
|
+
* Called once when the animation first becomes active.
|
|
21
|
+
*/
|
|
22
|
+
protected abstract captureStartState(): void;
|
|
23
|
+
ensureInitialized(): void;
|
|
24
|
+
reset(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Animation } from '../Animation';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for animations that transform an existing scene object.
|
|
4
|
+
*
|
|
5
|
+
* Transformative animations:
|
|
6
|
+
* - Require the target to already be registered with the scene
|
|
7
|
+
* - Throw an error if the target is not in the scene
|
|
8
|
+
* - Operate on objects that are already visible or have been introduced
|
|
9
|
+
* - Use lazy initialization to capture start state when animation becomes active
|
|
10
|
+
*
|
|
11
|
+
* Examples: MoveTo, Rotate, Scale, MorphTo, Transform
|
|
12
|
+
*/
|
|
13
|
+
export class TransformativeAnimation extends Animation {
|
|
14
|
+
lifecycle = 'transformative';
|
|
15
|
+
initialized = false;
|
|
16
|
+
ensureInitialized() {
|
|
17
|
+
if (!this.initialized) {
|
|
18
|
+
this.captureStartState();
|
|
19
|
+
this.initialized = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
reset() {
|
|
23
|
+
this.initialized = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Mobject } from '../../../mobjects/Mobject';
|
|
2
|
+
import { Animation } from '../Animation';
|
|
3
|
+
import type { AnimationLifecycle } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Executes animations in parallel, all starting at the same time.
|
|
6
|
+
* Total duration equals the maximum of all child animation durations.
|
|
7
|
+
*
|
|
8
|
+
* This is a composition animation - its lifecycle is determined by its children.
|
|
9
|
+
* By default, uses 'transformative' lifecycle if children are mixed.
|
|
10
|
+
*
|
|
11
|
+
* All children are initialized together before any interpolation begins,
|
|
12
|
+
* ensuring they all capture state at the same moment.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Parallel extends Animation<Mobject> {
|
|
15
|
+
private readonly children;
|
|
16
|
+
private readonly maxChildDuration;
|
|
17
|
+
/**
|
|
18
|
+
* The lifecycle of Parallel is 'introductory' only if ALL children are introductory.
|
|
19
|
+
* Otherwise, it defaults to 'transformative'.
|
|
20
|
+
*/
|
|
21
|
+
readonly lifecycle: AnimationLifecycle;
|
|
22
|
+
constructor(animations: Animation[]);
|
|
23
|
+
getDuration(): number;
|
|
24
|
+
getChildren(): readonly Animation[];
|
|
25
|
+
/**
|
|
26
|
+
* Ensures all children are initialized together.
|
|
27
|
+
* This captures start state for all parallel animations at the same moment.
|
|
28
|
+
*/
|
|
29
|
+
ensureInitialized(): void;
|
|
30
|
+
reset(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Interpolates all child animations at the given progress.
|
|
33
|
+
* Each child's progress is scaled based on its duration relative to the container.
|
|
34
|
+
*/
|
|
35
|
+
interpolate(progress: number): void;
|
|
36
|
+
update(progress: number): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Mobject } from '../../../mobjects/Mobject';
|
|
2
|
+
import { Animation } from '../Animation';
|
|
3
|
+
/**
|
|
4
|
+
* Executes animations in parallel, all starting at the same time.
|
|
5
|
+
* Total duration equals the maximum of all child animation durations.
|
|
6
|
+
*
|
|
7
|
+
* This is a composition animation - its lifecycle is determined by its children.
|
|
8
|
+
* By default, uses 'transformative' lifecycle if children are mixed.
|
|
9
|
+
*
|
|
10
|
+
* All children are initialized together before any interpolation begins,
|
|
11
|
+
* ensuring they all capture state at the same moment.
|
|
12
|
+
*/
|
|
13
|
+
export class Parallel extends Animation {
|
|
14
|
+
children;
|
|
15
|
+
maxChildDuration;
|
|
16
|
+
/**
|
|
17
|
+
* The lifecycle of Parallel is 'introductory' only if ALL children are introductory.
|
|
18
|
+
* Otherwise, it defaults to 'transformative'.
|
|
19
|
+
*/
|
|
20
|
+
lifecycle;
|
|
21
|
+
constructor(animations) {
|
|
22
|
+
super(new Mobject());
|
|
23
|
+
this.children = animations;
|
|
24
|
+
this.maxChildDuration = animations.reduce((max, a) => Math.max(max, a.getDuration()), 0);
|
|
25
|
+
this.durationSeconds = this.maxChildDuration;
|
|
26
|
+
// Lifecycle is introductory only if ALL children are introductory
|
|
27
|
+
this.lifecycle = animations.every(a => a.lifecycle === 'introductory')
|
|
28
|
+
? 'introductory'
|
|
29
|
+
: 'transformative';
|
|
30
|
+
}
|
|
31
|
+
getDuration() {
|
|
32
|
+
return this.durationSeconds;
|
|
33
|
+
}
|
|
34
|
+
getChildren() {
|
|
35
|
+
return this.children;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ensures all children are initialized together.
|
|
39
|
+
* This captures start state for all parallel animations at the same moment.
|
|
40
|
+
*/
|
|
41
|
+
ensureInitialized() {
|
|
42
|
+
for (const child of this.children) {
|
|
43
|
+
child.ensureInitialized();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
reset() {
|
|
47
|
+
for (const child of this.children) {
|
|
48
|
+
child.reset();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Interpolates all child animations at the given progress.
|
|
53
|
+
* Each child's progress is scaled based on its duration relative to the container.
|
|
54
|
+
*/
|
|
55
|
+
interpolate(progress) {
|
|
56
|
+
if (this.children.length === 0 || this.maxChildDuration === 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const globalTime = progress * this.maxChildDuration;
|
|
60
|
+
for (const child of this.children) {
|
|
61
|
+
const childDuration = child.getDuration();
|
|
62
|
+
if (childDuration === 0) {
|
|
63
|
+
child.update(1);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Calculate local progress for this child
|
|
67
|
+
const localProgress = Math.min(1, globalTime / childDuration);
|
|
68
|
+
child.update(localProgress);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
update(progress) {
|
|
72
|
+
// Pre-initialize ALL children before ANY interpolation
|
|
73
|
+
// This ensures parallel animations capture state at the same moment
|
|
74
|
+
this.ensureInitialized();
|
|
75
|
+
const clampedProgress = Math.max(0, Math.min(1, progress));
|
|
76
|
+
// Composition animations should not apply easing to their children
|
|
77
|
+
this.interpolate(clampedProgress);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Mobject } from '../../../mobjects/Mobject';
|
|
2
|
+
import { Animation } from '../Animation';
|
|
3
|
+
import type { AnimationLifecycle } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Executes animations in sequence, one after another.
|
|
6
|
+
* Total duration equals the sum of all child animation durations.
|
|
7
|
+
*
|
|
8
|
+
* This is a composition animation - its lifecycle is determined by its children.
|
|
9
|
+
* Only the first child is initialized when the sequence starts; subsequent
|
|
10
|
+
* children are initialized when they become active.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Sequence extends Animation<Mobject> {
|
|
13
|
+
private readonly children;
|
|
14
|
+
private readonly childDurations;
|
|
15
|
+
private readonly totalChildDuration;
|
|
16
|
+
/**
|
|
17
|
+
* The lifecycle of Sequence is determined by its FIRST child animation.
|
|
18
|
+
* If the first animation is introductory, it will register the target,
|
|
19
|
+
* allowing subsequent transformative animations to work.
|
|
20
|
+
*/
|
|
21
|
+
readonly lifecycle: AnimationLifecycle;
|
|
22
|
+
constructor(animations: Animation[]);
|
|
23
|
+
getDuration(): number;
|
|
24
|
+
getChildren(): readonly Animation[];
|
|
25
|
+
/**
|
|
26
|
+
* Initializes only the first child.
|
|
27
|
+
* Later children are initialized when they become active in interpolate().
|
|
28
|
+
*/
|
|
29
|
+
ensureInitialized(): void;
|
|
30
|
+
reset(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Interpolates the sequence at the given progress.
|
|
33
|
+
* Maps global progress to the correct child animation.
|
|
34
|
+
*
|
|
35
|
+
* IMPORTANT: We only update children that have started or completed.
|
|
36
|
+
* Children that haven't started yet are NOT updated to avoid
|
|
37
|
+
* premature initialization with incorrect state.
|
|
38
|
+
*/
|
|
39
|
+
interpolate(progress: number): void;
|
|
40
|
+
update(progress: number): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Mobject } from '../../../mobjects/Mobject';
|
|
2
|
+
import { Animation } from '../Animation';
|
|
3
|
+
/**
|
|
4
|
+
* Executes animations in sequence, one after another.
|
|
5
|
+
* Total duration equals the sum of all child animation durations.
|
|
6
|
+
*
|
|
7
|
+
* This is a composition animation - its lifecycle is determined by its children.
|
|
8
|
+
* Only the first child is initialized when the sequence starts; subsequent
|
|
9
|
+
* children are initialized when they become active.
|
|
10
|
+
*/
|
|
11
|
+
export class Sequence extends Animation {
|
|
12
|
+
children;
|
|
13
|
+
childDurations;
|
|
14
|
+
totalChildDuration;
|
|
15
|
+
/**
|
|
16
|
+
* The lifecycle of Sequence is determined by its FIRST child animation.
|
|
17
|
+
* If the first animation is introductory, it will register the target,
|
|
18
|
+
* allowing subsequent transformative animations to work.
|
|
19
|
+
*/
|
|
20
|
+
lifecycle;
|
|
21
|
+
constructor(animations) {
|
|
22
|
+
super(new Mobject());
|
|
23
|
+
this.children = animations;
|
|
24
|
+
this.childDurations = animations.map((a) => a.getDuration());
|
|
25
|
+
this.totalChildDuration = this.childDurations.reduce((sum, d) => sum + d, 0);
|
|
26
|
+
this.durationSeconds = this.totalChildDuration;
|
|
27
|
+
// Lifecycle is determined by FIRST animation in the sequence
|
|
28
|
+
// If first is introductory, it registers the target for subsequent animations
|
|
29
|
+
const first = animations[0];
|
|
30
|
+
this.lifecycle = first?.lifecycle === 'introductory' ? 'introductory' : 'transformative';
|
|
31
|
+
}
|
|
32
|
+
getDuration() {
|
|
33
|
+
return this.durationSeconds;
|
|
34
|
+
}
|
|
35
|
+
getChildren() {
|
|
36
|
+
return this.children;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Initializes only the first child.
|
|
40
|
+
* Later children are initialized when they become active in interpolate().
|
|
41
|
+
*/
|
|
42
|
+
ensureInitialized() {
|
|
43
|
+
if (this.children.length > 0) {
|
|
44
|
+
this.children[0].ensureInitialized();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
reset() {
|
|
48
|
+
for (const child of this.children) {
|
|
49
|
+
child.reset();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Interpolates the sequence at the given progress.
|
|
54
|
+
* Maps global progress to the correct child animation.
|
|
55
|
+
*
|
|
56
|
+
* IMPORTANT: We only update children that have started or completed.
|
|
57
|
+
* Children that haven't started yet are NOT updated to avoid
|
|
58
|
+
* premature initialization with incorrect state.
|
|
59
|
+
*/
|
|
60
|
+
interpolate(progress) {
|
|
61
|
+
if (this.children.length === 0 || this.totalChildDuration === 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const globalTime = progress * this.totalChildDuration;
|
|
65
|
+
let accumulatedTime = 0;
|
|
66
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
67
|
+
const child = this.children[i];
|
|
68
|
+
const childDuration = this.childDurations[i];
|
|
69
|
+
if (child === undefined || childDuration === undefined) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const childStart = accumulatedTime;
|
|
73
|
+
const childEnd = accumulatedTime + childDuration;
|
|
74
|
+
if (globalTime < childStart) {
|
|
75
|
+
// Before this child starts - DO NOT UPDATE
|
|
76
|
+
// Updating would prematurely initialize with wrong state
|
|
77
|
+
}
|
|
78
|
+
else if (globalTime >= childEnd) {
|
|
79
|
+
// This child is complete
|
|
80
|
+
child.update(1);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// This child is active
|
|
84
|
+
const localProgress = (globalTime - childStart) / childDuration;
|
|
85
|
+
child.update(localProgress);
|
|
86
|
+
}
|
|
87
|
+
accumulatedTime = childEnd;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
update(progress) {
|
|
91
|
+
const clampedProgress = Math.max(0, Math.min(1, progress));
|
|
92
|
+
// Composition animations should not apply easing to their children
|
|
93
|
+
this.interpolate(clampedProgress);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IntroductoryAnimation } from '../categories';
|
|
2
|
+
import { VMobject } from '../../../mobjects/VMobject';
|
|
3
|
+
/**
|
|
4
|
+
* Animation that first draws the border progressively, then fills the shape.
|
|
5
|
+
* The first 50% of the animation draws the stroke, the second 50% fades in the fill.
|
|
6
|
+
*
|
|
7
|
+
* Supports VGroup (including Text): animates each child's paths progressively.
|
|
8
|
+
*
|
|
9
|
+
* This is an introductory animation - it auto-registers the target with the scene.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const rect = new Rectangle(2, 1);
|
|
13
|
+
* scene.play(new Draw(rect)); // Border draws, then fill fades in
|
|
14
|
+
*/
|
|
15
|
+
export declare class Draw<T extends VMobject = VMobject> extends IntroductoryAnimation<T> {
|
|
16
|
+
private readonly isVGroup;
|
|
17
|
+
/** For non-VGroup targets: original paths on the target itself. */
|
|
18
|
+
private readonly originalPaths;
|
|
19
|
+
private readonly originalFillOpacity;
|
|
20
|
+
private readonly originalOpacity;
|
|
21
|
+
/** For VGroup targets: original state of each child. */
|
|
22
|
+
private readonly childStates;
|
|
23
|
+
constructor(target: T);
|
|
24
|
+
/** Interpolates stroke drawing (0-0.5) and then fill fade (0.5-1). */
|
|
25
|
+
interpolate(progress: number): void;
|
|
26
|
+
/** Interpolates a single VMobject (non-VGroup). */
|
|
27
|
+
private interpolateVMobject;
|
|
28
|
+
/** Interpolates a VGroup by animating each child's paths. */
|
|
29
|
+
private interpolateVGroup;
|
|
30
|
+
}
|