effect-motion 0.2.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/README.md +40 -0
- package/dist/Camera.d.ts +49 -0
- package/dist/Camera.js +33 -0
- package/dist/Entity.d.ts +40 -0
- package/dist/Entity.js +32 -0
- package/dist/Fonts.d.ts +31 -0
- package/dist/Fonts.js +11 -0
- package/dist/Instance.d.ts +16 -0
- package/dist/Instance.js +18 -0
- package/dist/Motion.d.ts +74 -0
- package/dist/Motion.js +125 -0
- package/dist/Phaser.d.ts +65 -0
- package/dist/Phaser.js +170 -0
- package/dist/Physics.d.ts +78 -0
- package/dist/Physics.js +117 -0
- package/dist/Renderer.d.ts +69 -0
- package/dist/Renderer.js +90 -0
- package/dist/Runner.d.ts +360 -0
- package/dist/Runner.js +257 -0
- package/dist/Scene.d.ts +241 -0
- package/dist/Scene.js +454 -0
- package/dist/Time.d.ts +38 -0
- package/dist/Time.js +43 -0
- package/dist/Timing.d.ts +96 -0
- package/dist/Timing.js +151 -0
- package/dist/demo.d.ts +186 -0
- package/dist/demo.js +76 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/particles/Particle.d.ts +91 -0
- package/dist/particles/Particle.js +1 -0
- package/dist/particles/ParticleField.d.ts +170 -0
- package/dist/particles/ParticleField.js +69 -0
- package/dist/particles/Prng.d.ts +28 -0
- package/dist/particles/Prng.js +43 -0
- package/dist/particles/constructors.d.ts +78 -0
- package/dist/particles/constructors.js +15 -0
- package/dist/particles/index.d.ts +6 -0
- package/dist/particles/index.js +6 -0
- package/dist/particles/overLife.d.ts +16 -0
- package/dist/particles/overLife.js +21 -0
- package/dist/particles/render.d.ts +13 -0
- package/dist/particles/render.js +33 -0
- package/dist/particles/simulate.d.ts +39 -0
- package/dist/particles/simulate.js +81 -0
- package/dist/particles/step.d.ts +24 -0
- package/dist/particles/step.js +167 -0
- package/dist/shapes/Circle.d.ts +37 -0
- package/dist/shapes/Circle.js +9 -0
- package/dist/shapes/Ellipse.d.ts +41 -0
- package/dist/shapes/Ellipse.js +10 -0
- package/dist/shapes/Group.d.ts +150 -0
- package/dist/shapes/Group.js +82 -0
- package/dist/shapes/Layer.d.ts +9 -0
- package/dist/shapes/Layer.js +23 -0
- package/dist/shapes/Line.d.ts +47 -0
- package/dist/shapes/Line.js +30 -0
- package/dist/shapes/Path.d.ts +38 -0
- package/dist/shapes/Path.js +13 -0
- package/dist/shapes/Rect.d.ts +41 -0
- package/dist/shapes/Rect.js +10 -0
- package/dist/shapes/Shape2D.d.ts +40 -0
- package/dist/shapes/Shape2D.js +41 -0
- package/dist/shapes/Square.d.ts +37 -0
- package/dist/shapes/Square.js +11 -0
- package/dist/shapes/Text.d.ts +60 -0
- package/dist/shapes/Text.js +24 -0
- package/dist/shapes/index.d.ts +10 -0
- package/dist/shapes/index.js +10 -0
- package/dist/svg/SvgDomRenderer.d.ts +28 -0
- package/dist/svg/SvgDomRenderer.js +50 -0
- package/dist/svg/SvgNode.d.ts +13 -0
- package/dist/svg/SvgNode.js +18 -0
- package/dist/svg/SvgRenderer.d.ts +22 -0
- package/dist/svg/SvgRenderer.js +20 -0
- package/dist/svg/camera.d.ts +21 -0
- package/dist/svg/camera.js +43 -0
- package/dist/svg/index.d.ts +6 -0
- package/dist/svg/index.js +6 -0
- package/dist/svg/layers.d.ts +18 -0
- package/dist/svg/layers.js +13 -0
- package/dist/svg/shapes.d.ts +1089 -0
- package/dist/svg/shapes.js +119 -0
- package/package.json +51 -0
package/dist/Timing.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
export const linear = (t) => t;
|
|
2
|
+
/** one full sine cycle: 0 → 1 → 0 */
|
|
3
|
+
export const sin = (t) => (1 - Math.cos(2 * Math.PI * t)) / 2;
|
|
4
|
+
/** one full cosine cycle: 1 → 0 → 1 */
|
|
5
|
+
export const cos = (t) => (1 + Math.cos(2 * Math.PI * t)) / 2;
|
|
6
|
+
export const easeInSine = (t) => 1 - Math.cos((t * Math.PI) / 2);
|
|
7
|
+
export const easeOutSine = (t) => Math.sin((t * Math.PI) / 2);
|
|
8
|
+
export const easeInOutSine = (t) => -(Math.cos(Math.PI * t) - 1) / 2;
|
|
9
|
+
const easeInPow = (p) => (t) => t ** p;
|
|
10
|
+
const easeOutPow = (p) => (t) => 1 - (1 - t) ** p;
|
|
11
|
+
const easeInOutPow = (p) => (t) => t < 0.5 ? 2 ** (p - 1) * t ** p : 1 - (-2 * t + 2) ** p / 2;
|
|
12
|
+
export const easeInQuad = easeInPow(2);
|
|
13
|
+
export const easeOutQuad = easeOutPow(2);
|
|
14
|
+
export const easeInOutQuad = easeInOutPow(2);
|
|
15
|
+
export const easeInCubic = easeInPow(3);
|
|
16
|
+
export const easeOutCubic = easeOutPow(3);
|
|
17
|
+
export const easeInOutCubic = easeInOutPow(3);
|
|
18
|
+
export const easeInQuart = easeInPow(4);
|
|
19
|
+
export const easeOutQuart = easeOutPow(4);
|
|
20
|
+
export const easeInOutQuart = easeInOutPow(4);
|
|
21
|
+
export const easeInQuint = easeInPow(5);
|
|
22
|
+
export const easeOutQuint = easeOutPow(5);
|
|
23
|
+
export const easeInOutQuint = easeInOutPow(5);
|
|
24
|
+
export const easeInExpo = (t) => t === 0 ? 0 : 2 ** (10 * t - 10);
|
|
25
|
+
export const easeOutExpo = (t) => t === 1 ? 1 : 1 - 2 ** (-10 * t);
|
|
26
|
+
export const easeInOutExpo = (t) => t === 0
|
|
27
|
+
? 0
|
|
28
|
+
: t === 1
|
|
29
|
+
? 1
|
|
30
|
+
: t < 0.5
|
|
31
|
+
? 2 ** (20 * t - 10) / 2
|
|
32
|
+
: (2 - 2 ** (-20 * t + 10)) / 2;
|
|
33
|
+
export const easeInCirc = (t) => 1 - Math.sqrt(1 - t ** 2);
|
|
34
|
+
export const easeOutCirc = (t) => Math.sqrt(1 - (t - 1) ** 2);
|
|
35
|
+
export const easeInOutCirc = (t) => t < 0.5
|
|
36
|
+
? (1 - Math.sqrt(1 - (2 * t) ** 2)) / 2
|
|
37
|
+
: (Math.sqrt(1 - (-2 * t + 2) ** 2) + 1) / 2;
|
|
38
|
+
/** `s` is the overshoot amount */
|
|
39
|
+
export const createEaseInBack = (s = 1.70158) => (t) => (s + 1) * t ** 3 - s * t ** 2;
|
|
40
|
+
export const createEaseOutBack = (s = 1.70158) => (t) => 1 + (s + 1) * (t - 1) ** 3 + s * (t - 1) ** 2;
|
|
41
|
+
export const createEaseInOutBack = (s = 1.70158, v = 1.525) => {
|
|
42
|
+
const c = s * v;
|
|
43
|
+
return (t) => t < 0.5
|
|
44
|
+
? ((2 * t) ** 2 * ((c + 1) * 2 * t - c)) / 2
|
|
45
|
+
: ((2 * t - 2) ** 2 * ((c + 1) * (2 * t - 2) + c) + 2) / 2;
|
|
46
|
+
};
|
|
47
|
+
/** `s` is the angular frequency (default 2π/3) */
|
|
48
|
+
export const createEaseInElastic = (s = 2.094395) => (t) => t === 0
|
|
49
|
+
? 0
|
|
50
|
+
: t === 1
|
|
51
|
+
? 1
|
|
52
|
+
: -(2 ** (10 * t - 10)) * Math.sin((t * 10 - 10.75) * s);
|
|
53
|
+
export const createEaseOutElastic = (s = 2.094395) => (t) => t === 0
|
|
54
|
+
? 0
|
|
55
|
+
: t === 1
|
|
56
|
+
? 1
|
|
57
|
+
: 2 ** (-10 * t) * Math.sin((t * 10 - 0.75) * s) + 1;
|
|
58
|
+
/** `s` is the angular frequency (default 2π/4.5) */
|
|
59
|
+
export const createEaseInOutElastic = (s = 1.39626) => (t) => t === 0
|
|
60
|
+
? 0
|
|
61
|
+
: t === 1
|
|
62
|
+
? 1
|
|
63
|
+
: t < 0.5
|
|
64
|
+
? -(2 ** (20 * t - 10) * Math.sin((20 * t - 11.125) * s)) / 2
|
|
65
|
+
: (2 ** (-20 * t + 10) * Math.sin((20 * t - 11.125) * s)) / 2 + 1;
|
|
66
|
+
/** `n` is the bounce stiffness, `d` the interval divisor */
|
|
67
|
+
export const createEaseOutBounce = (n = 7.5625, d = 2.75) => {
|
|
68
|
+
// segment offsets derived from the parameters so f(1) = 1 holds for
|
|
69
|
+
// any stiffness (defaults yield the canonical 0.75/0.9375/0.984375)
|
|
70
|
+
const o1 = 1 - n * (0.5 / d) ** 2;
|
|
71
|
+
const o2 = 1 - n * (0.25 / d) ** 2;
|
|
72
|
+
const o3 = 1 - n * (1 - 2.625 / d) ** 2;
|
|
73
|
+
return (t) => {
|
|
74
|
+
if (t < 1 / d) {
|
|
75
|
+
return n * t ** 2;
|
|
76
|
+
}
|
|
77
|
+
if (t < 2 / d) {
|
|
78
|
+
const u = t - 1.5 / d;
|
|
79
|
+
return n * u ** 2 + o1;
|
|
80
|
+
}
|
|
81
|
+
if (t < 2.5 / d) {
|
|
82
|
+
const u = t - 2.25 / d;
|
|
83
|
+
return n * u ** 2 + o2;
|
|
84
|
+
}
|
|
85
|
+
const u = t - 2.625 / d;
|
|
86
|
+
return n * u ** 2 + o3;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export const createEaseInBounce = (n = 7.5625, d = 2.75) => {
|
|
90
|
+
const out = createEaseOutBounce(n, d);
|
|
91
|
+
return (t) => 1 - out(1 - t);
|
|
92
|
+
};
|
|
93
|
+
export const createEaseInOutBounce = (n = 7.5625, d = 2.75) => {
|
|
94
|
+
const out = createEaseOutBounce(n, d);
|
|
95
|
+
return (t) => (t < 0.5 ? (1 - out(1 - 2 * t)) / 2 : (1 + out(2 * t - 1)) / 2);
|
|
96
|
+
};
|
|
97
|
+
export const easeInBack = createEaseInBack();
|
|
98
|
+
export const easeOutBack = createEaseOutBack();
|
|
99
|
+
export const easeInOutBack = createEaseInOutBack();
|
|
100
|
+
export const easeInElastic = createEaseInElastic();
|
|
101
|
+
export const easeOutElastic = createEaseOutElastic();
|
|
102
|
+
export const easeInOutElastic = createEaseInOutElastic();
|
|
103
|
+
export const easeInBounce = createEaseInBounce();
|
|
104
|
+
export const easeOutBounce = createEaseOutBounce();
|
|
105
|
+
export const easeInOutBounce = createEaseInOutBounce();
|
|
106
|
+
export const timingFunctions = {
|
|
107
|
+
linear,
|
|
108
|
+
sin,
|
|
109
|
+
cos,
|
|
110
|
+
easeInSine,
|
|
111
|
+
easeOutSine,
|
|
112
|
+
easeInOutSine,
|
|
113
|
+
easeInQuad,
|
|
114
|
+
easeOutQuad,
|
|
115
|
+
easeInOutQuad,
|
|
116
|
+
easeInCubic,
|
|
117
|
+
easeOutCubic,
|
|
118
|
+
easeInOutCubic,
|
|
119
|
+
easeInQuart,
|
|
120
|
+
easeOutQuart,
|
|
121
|
+
easeInOutQuart,
|
|
122
|
+
easeInQuint,
|
|
123
|
+
easeOutQuint,
|
|
124
|
+
easeInOutQuint,
|
|
125
|
+
easeInExpo,
|
|
126
|
+
easeOutExpo,
|
|
127
|
+
easeInOutExpo,
|
|
128
|
+
easeInCirc,
|
|
129
|
+
easeOutCirc,
|
|
130
|
+
easeInOutCirc,
|
|
131
|
+
easeInBack,
|
|
132
|
+
easeOutBack,
|
|
133
|
+
easeInOutBack,
|
|
134
|
+
easeInElastic,
|
|
135
|
+
easeOutElastic,
|
|
136
|
+
easeInOutElastic,
|
|
137
|
+
easeInBounce,
|
|
138
|
+
easeOutBounce,
|
|
139
|
+
easeInOutBounce,
|
|
140
|
+
};
|
|
141
|
+
export const resolve = (input) => {
|
|
142
|
+
if (typeof input === "function") {
|
|
143
|
+
return input;
|
|
144
|
+
}
|
|
145
|
+
const fn = timingFunctions[input];
|
|
146
|
+
if (fn === undefined) {
|
|
147
|
+
// unreachable for typed consumers; catches plain-JS typos
|
|
148
|
+
throw new Error(`Timing: unknown timing function "${String(input)}"`);
|
|
149
|
+
}
|
|
150
|
+
return fn;
|
|
151
|
+
};
|
package/dist/demo.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Entity from "./Entity";
|
|
3
|
+
import * as Scene from "./Scene";
|
|
4
|
+
export declare const scene: Scene.Scene<unknown, import("./Runner").Runner | import("effect/Scope").Scope, Entity.Entity<"shapes/Group", Schema.Struct<{
|
|
5
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
6
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
7
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
8
|
+
transform: Schema.withConstructorDefault<Schema.Struct<{
|
|
9
|
+
readonly a: Schema.Number;
|
|
10
|
+
readonly b: Schema.Number;
|
|
11
|
+
readonly c: Schema.Number;
|
|
12
|
+
readonly d: Schema.Number;
|
|
13
|
+
readonly e: Schema.Number;
|
|
14
|
+
readonly f: Schema.Number;
|
|
15
|
+
}>>;
|
|
16
|
+
children: Schema.withConstructorDefault<Schema.$Array<Schema.String>>;
|
|
17
|
+
}>, {
|
|
18
|
+
"~position": Entity.TraitLens<Schema.Struct.ReadonlySide<{
|
|
19
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
20
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
21
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
22
|
+
transform: Schema.withConstructorDefault<Schema.Struct<{
|
|
23
|
+
readonly a: Schema.Number;
|
|
24
|
+
readonly b: Schema.Number;
|
|
25
|
+
readonly c: Schema.Number;
|
|
26
|
+
readonly d: Schema.Number;
|
|
27
|
+
readonly e: Schema.Number;
|
|
28
|
+
readonly f: Schema.Number;
|
|
29
|
+
}>>;
|
|
30
|
+
children: Schema.withConstructorDefault<Schema.$Array<Schema.String>>;
|
|
31
|
+
}, "Type">, Entity.Position>;
|
|
32
|
+
"~opacity": Entity.TraitLens<Schema.Struct.ReadonlySide<{
|
|
33
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
34
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
35
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
36
|
+
transform: Schema.withConstructorDefault<Schema.Struct<{
|
|
37
|
+
readonly a: Schema.Number;
|
|
38
|
+
readonly b: Schema.Number;
|
|
39
|
+
readonly c: Schema.Number;
|
|
40
|
+
readonly d: Schema.Number;
|
|
41
|
+
readonly e: Schema.Number;
|
|
42
|
+
readonly f: Schema.Number;
|
|
43
|
+
}>>;
|
|
44
|
+
children: Schema.withConstructorDefault<Schema.$Array<Schema.String>>;
|
|
45
|
+
}, "Type">, number>;
|
|
46
|
+
}, Omit<{
|
|
47
|
+
readonly x?: number;
|
|
48
|
+
readonly y?: number;
|
|
49
|
+
readonly opacity?: number;
|
|
50
|
+
readonly transform?: Schema.Struct.ReadonlyMakeIn<{
|
|
51
|
+
readonly a: Schema.Number;
|
|
52
|
+
readonly b: Schema.Number;
|
|
53
|
+
readonly c: Schema.Number;
|
|
54
|
+
readonly d: Schema.Number;
|
|
55
|
+
readonly e: Schema.Number;
|
|
56
|
+
readonly f: Schema.Number;
|
|
57
|
+
}>;
|
|
58
|
+
readonly children?: readonly string[];
|
|
59
|
+
}, "transform"> & {
|
|
60
|
+
readonly transform?: readonly (Schema.Struct.ReadonlySide<{
|
|
61
|
+
readonly _tag: Schema.tag<"transform/matrix">;
|
|
62
|
+
readonly a: Schema.Number;
|
|
63
|
+
readonly b: Schema.Number;
|
|
64
|
+
readonly c: Schema.Number;
|
|
65
|
+
readonly d: Schema.Number;
|
|
66
|
+
readonly e: Schema.Number;
|
|
67
|
+
readonly f: Schema.Number;
|
|
68
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
69
|
+
readonly _tag: Schema.tag<"transform/scale">;
|
|
70
|
+
readonly x: Schema.Number;
|
|
71
|
+
readonly y: Schema.Number;
|
|
72
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
73
|
+
readonly _tag: Schema.tag<"transform/translate">;
|
|
74
|
+
readonly x: Schema.Number;
|
|
75
|
+
readonly y: Schema.Number;
|
|
76
|
+
}, "Type">)[];
|
|
77
|
+
}>>;
|
|
78
|
+
export declare const staggered: Scene.Scene<unknown, import("./Phaser").Phaser | import("./Runner").Runner | import("effect/Scope").Scope, Entity.Entity<"shapes/Circle", Schema.Struct<{
|
|
79
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
80
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
81
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
82
|
+
fill: Schema.withConstructorDefault<Schema.String>;
|
|
83
|
+
stroke: Schema.optionalKey<Schema.String>;
|
|
84
|
+
strokeWidth: Schema.optionalKey<Schema.Number>;
|
|
85
|
+
radius: Schema.withConstructorDefault<Schema.Number>;
|
|
86
|
+
}>, {
|
|
87
|
+
readonly "~position": Entity.TraitLens<{
|
|
88
|
+
readonly x: number;
|
|
89
|
+
readonly y: number;
|
|
90
|
+
readonly opacity: number;
|
|
91
|
+
readonly fill: string;
|
|
92
|
+
readonly stroke?: string;
|
|
93
|
+
readonly strokeWidth?: number;
|
|
94
|
+
readonly radius: number;
|
|
95
|
+
}, Entity.Position>;
|
|
96
|
+
readonly "~opacity": Entity.TraitLens<{
|
|
97
|
+
readonly x: number;
|
|
98
|
+
readonly y: number;
|
|
99
|
+
readonly opacity: number;
|
|
100
|
+
readonly fill: string;
|
|
101
|
+
readonly stroke?: string;
|
|
102
|
+
readonly strokeWidth?: number;
|
|
103
|
+
readonly radius: number;
|
|
104
|
+
}, number>;
|
|
105
|
+
}, {
|
|
106
|
+
readonly x?: number;
|
|
107
|
+
readonly y?: number;
|
|
108
|
+
readonly opacity?: number;
|
|
109
|
+
readonly fill?: string;
|
|
110
|
+
readonly stroke?: string;
|
|
111
|
+
readonly strokeWidth?: number;
|
|
112
|
+
readonly radius?: number;
|
|
113
|
+
}> | Entity.Entity<"shapes/Group", Schema.Struct<{
|
|
114
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
115
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
116
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
117
|
+
transform: Schema.withConstructorDefault<Schema.Struct<{
|
|
118
|
+
readonly a: Schema.Number;
|
|
119
|
+
readonly b: Schema.Number;
|
|
120
|
+
readonly c: Schema.Number;
|
|
121
|
+
readonly d: Schema.Number;
|
|
122
|
+
readonly e: Schema.Number;
|
|
123
|
+
readonly f: Schema.Number;
|
|
124
|
+
}>>;
|
|
125
|
+
children: Schema.withConstructorDefault<Schema.$Array<Schema.String>>;
|
|
126
|
+
}>, {
|
|
127
|
+
"~position": Entity.TraitLens<Schema.Struct.ReadonlySide<{
|
|
128
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
129
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
130
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
131
|
+
transform: Schema.withConstructorDefault<Schema.Struct<{
|
|
132
|
+
readonly a: Schema.Number;
|
|
133
|
+
readonly b: Schema.Number;
|
|
134
|
+
readonly c: Schema.Number;
|
|
135
|
+
readonly d: Schema.Number;
|
|
136
|
+
readonly e: Schema.Number;
|
|
137
|
+
readonly f: Schema.Number;
|
|
138
|
+
}>>;
|
|
139
|
+
children: Schema.withConstructorDefault<Schema.$Array<Schema.String>>;
|
|
140
|
+
}, "Type">, Entity.Position>;
|
|
141
|
+
"~opacity": Entity.TraitLens<Schema.Struct.ReadonlySide<{
|
|
142
|
+
x: Schema.withConstructorDefault<Schema.Number>;
|
|
143
|
+
y: Schema.withConstructorDefault<Schema.Number>;
|
|
144
|
+
opacity: Schema.withConstructorDefault<Schema.Number>;
|
|
145
|
+
transform: Schema.withConstructorDefault<Schema.Struct<{
|
|
146
|
+
readonly a: Schema.Number;
|
|
147
|
+
readonly b: Schema.Number;
|
|
148
|
+
readonly c: Schema.Number;
|
|
149
|
+
readonly d: Schema.Number;
|
|
150
|
+
readonly e: Schema.Number;
|
|
151
|
+
readonly f: Schema.Number;
|
|
152
|
+
}>>;
|
|
153
|
+
children: Schema.withConstructorDefault<Schema.$Array<Schema.String>>;
|
|
154
|
+
}, "Type">, number>;
|
|
155
|
+
}, Omit<{
|
|
156
|
+
readonly x?: number;
|
|
157
|
+
readonly y?: number;
|
|
158
|
+
readonly opacity?: number;
|
|
159
|
+
readonly transform?: Schema.Struct.ReadonlyMakeIn<{
|
|
160
|
+
readonly a: Schema.Number;
|
|
161
|
+
readonly b: Schema.Number;
|
|
162
|
+
readonly c: Schema.Number;
|
|
163
|
+
readonly d: Schema.Number;
|
|
164
|
+
readonly e: Schema.Number;
|
|
165
|
+
readonly f: Schema.Number;
|
|
166
|
+
}>;
|
|
167
|
+
readonly children?: readonly string[];
|
|
168
|
+
}, "transform"> & {
|
|
169
|
+
readonly transform?: readonly (Schema.Struct.ReadonlySide<{
|
|
170
|
+
readonly _tag: Schema.tag<"transform/matrix">;
|
|
171
|
+
readonly a: Schema.Number;
|
|
172
|
+
readonly b: Schema.Number;
|
|
173
|
+
readonly c: Schema.Number;
|
|
174
|
+
readonly d: Schema.Number;
|
|
175
|
+
readonly e: Schema.Number;
|
|
176
|
+
readonly f: Schema.Number;
|
|
177
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
178
|
+
readonly _tag: Schema.tag<"transform/scale">;
|
|
179
|
+
readonly x: Schema.Number;
|
|
180
|
+
readonly y: Schema.Number;
|
|
181
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
182
|
+
readonly _tag: Schema.tag<"transform/translate">;
|
|
183
|
+
readonly x: Schema.Number;
|
|
184
|
+
readonly y: Schema.Number;
|
|
185
|
+
}, "Type">)[];
|
|
186
|
+
}>>;
|
package/dist/demo.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Effect, Layer, Schedule, Stream } from "effect";
|
|
2
|
+
import { Svg } from ".";
|
|
3
|
+
import * as Motion from "./Motion";
|
|
4
|
+
import * as Physics from "./Physics";
|
|
5
|
+
import * as Scene from "./Scene";
|
|
6
|
+
import * as Shapes from "./shapes";
|
|
7
|
+
// children live in the group's local coordinates: one motion moves them all
|
|
8
|
+
export const scene = Scene.make(function* () {
|
|
9
|
+
const duo = yield* Scene.instantiate(Shapes.Group, {
|
|
10
|
+
x: 70,
|
|
11
|
+
y: 200,
|
|
12
|
+
children: [
|
|
13
|
+
Scene.instantiate(Shapes.Circle, {
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
radius: 14,
|
|
17
|
+
fill: "#e53170",
|
|
18
|
+
}),
|
|
19
|
+
Scene.instantiate(Shapes.Square, {
|
|
20
|
+
x: 20,
|
|
21
|
+
y: -16,
|
|
22
|
+
size: 28,
|
|
23
|
+
fill: "#a786df",
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
const moveA = Motion.moveTo({ x: 380 }, "1.5 seconds", "easeInOutCubic");
|
|
28
|
+
const moveB = Motion.moveTo({ x: 70 }, "1.5 seconds", "easeInOutCubic");
|
|
29
|
+
yield* Motion.wait("1.5 seconds");
|
|
30
|
+
yield* duo.pipe(Motion.moveTo({ x: 380 }, "1.5 seconds", "easeInOutCubic"), Motion.moveTo({ x: 70 }, "1.5 seconds", "easeInOutCubic"), Motion.wait("1.5 seconds"), Physics.springTo({ y: 80 }, "jump"), Motion.fadeTo(0.15, "1 second"));
|
|
31
|
+
});
|
|
32
|
+
// const program = Effect.gen(function* () {
|
|
33
|
+
// const renderer = yield* Svg.SvgRenderer.Context;
|
|
34
|
+
// const sceneResult = yield* Scene.stream(scene, {
|
|
35
|
+
// }).pipe(
|
|
36
|
+
// Stream.runCollect,
|
|
37
|
+
// Effect.provide(renderer)
|
|
38
|
+
// )
|
|
39
|
+
// console.log(sceneResult);
|
|
40
|
+
// // renderer.render(scene, {
|
|
41
|
+
// // width: 500,
|
|
42
|
+
// // height: 300,
|
|
43
|
+
// // });
|
|
44
|
+
// }).pipe(Effect.provide(shapesLayer));
|
|
45
|
+
// Effect.runPromise(program);
|
|
46
|
+
// schedule-driven composition: a background pulse loops for the scene's
|
|
47
|
+
// duration while three staggered dots define its actual length
|
|
48
|
+
export const staggered = Scene.make(function* () {
|
|
49
|
+
const stage = yield* Scene.instantiate(Shapes.Group, { x: 70, y: 150 });
|
|
50
|
+
yield* Scene.background(Scene.repeat(stage.pipe(Motion.moveTo({ y: 130 }, "500 millis", "easeInOutCubic"), Motion.moveTo({ y: 150 }, "500 millis", "easeInOutCubic")), Schedule.forever));
|
|
51
|
+
const dot = (x) => Effect.gen(function* () {
|
|
52
|
+
const circle = yield* Scene.instantiate(Shapes.Circle, {
|
|
53
|
+
x,
|
|
54
|
+
y: 0,
|
|
55
|
+
radius: 10,
|
|
56
|
+
fill: "#e53170",
|
|
57
|
+
});
|
|
58
|
+
// reparent the freshly-born dot from root into the stage group
|
|
59
|
+
yield* Scene.appendChild(stage, circle);
|
|
60
|
+
yield* Motion.tweenTo(circle, { x: x + 300 }, "1 second", "easeInOutCubic");
|
|
61
|
+
});
|
|
62
|
+
yield* Scene.stagger([dot(0), dot(25), dot(50)], Schedule.spaced("250 millis"));
|
|
63
|
+
});
|
|
64
|
+
const movie = Effect.gen(function* () {
|
|
65
|
+
// const svgRenderer = yield* Svg.SvgRenderer.Context;
|
|
66
|
+
// const frames = yield* Scene.stream(scene).pipe(Stream.runCollect);
|
|
67
|
+
// let n = 0;
|
|
68
|
+
// for (const frame of frames) {
|
|
69
|
+
// console.log(`\x1b[36mframe ${n++}\x1b[0m`);
|
|
70
|
+
// console.log(yield* svgRenderer.render(frame, { width: 500, height: 300 }));
|
|
71
|
+
// }
|
|
72
|
+
const frames = yield* Scene.stream(staggered).pipe(Stream.runCollect);
|
|
73
|
+
console.log(`staggered scene: ${[...frames].length} frames`);
|
|
74
|
+
});
|
|
75
|
+
const layers = Svg.layer.pipe(Layer.provideMerge(Svg.shapesLayer));
|
|
76
|
+
Effect.runPromise(movie.pipe(Effect.provide(layers)));
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * as Camera from "./Camera";
|
|
2
|
+
export * as Entity from "./Entity";
|
|
3
|
+
export * as Fonts from "./Fonts";
|
|
4
|
+
export * as Instance from "./Instance";
|
|
5
|
+
export * as Motion from "./Motion";
|
|
6
|
+
export * as Phaser from "./Phaser";
|
|
7
|
+
export * as Physics from "./Physics";
|
|
8
|
+
export * as Particles from "./particles";
|
|
9
|
+
export * as Renderer from "./Renderer";
|
|
10
|
+
export * as Scene from "./Scene";
|
|
11
|
+
export * as Shapes from "./shapes";
|
|
12
|
+
export * as Svg from "./svg";
|
|
13
|
+
export * as Timing from "./Timing";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * as Camera from "./Camera";
|
|
2
|
+
export * as Entity from "./Entity";
|
|
3
|
+
export * as Fonts from "./Fonts";
|
|
4
|
+
export * as Instance from "./Instance";
|
|
5
|
+
export * as Motion from "./Motion";
|
|
6
|
+
export * as Phaser from "./Phaser";
|
|
7
|
+
export * as Physics from "./Physics";
|
|
8
|
+
export * as Particles from "./particles";
|
|
9
|
+
export * as Renderer from "./Renderer";
|
|
10
|
+
export * as Scene from "./Scene";
|
|
11
|
+
export * as Shapes from "./shapes";
|
|
12
|
+
export * as Svg from "./svg";
|
|
13
|
+
export * as Timing from "./Timing";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type * as Prng from "./Prng";
|
|
2
|
+
/**
|
|
3
|
+
* A single particle's live state. Held in a flat buffer on the
|
|
4
|
+
* ParticleField instance — never its own entity/instance/fiber. Position
|
|
5
|
+
* and velocity are integrated each frame; `age` counts up to `life`
|
|
6
|
+
* (seconds), at which point the particle is dead and its slot is free.
|
|
7
|
+
*
|
|
8
|
+
* `size` and `color` are the values DRAWN at birth (the particle's
|
|
9
|
+
* baseline); over-life curves modulate them at render time as a function
|
|
10
|
+
* of `age/life` and never mutate these fields.
|
|
11
|
+
*
|
|
12
|
+
* `rng` is the particle's own generator state (see Prng). Tier-2 curves
|
|
13
|
+
* never read it.
|
|
14
|
+
* ponytail: reserved so a future Tier-3 `fn(age, rng)` per-property config
|
|
15
|
+
* is purely additive — no buffer layout change. Drop it if Tier 3 is ruled
|
|
16
|
+
* out for good.
|
|
17
|
+
*/
|
|
18
|
+
export interface Particle {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
vx: number;
|
|
22
|
+
vy: number;
|
|
23
|
+
age: number;
|
|
24
|
+
life: number;
|
|
25
|
+
size: number;
|
|
26
|
+
/** baseline opacity drawn at birth; the over-life curve multiplies it */
|
|
27
|
+
opacity: number;
|
|
28
|
+
color: string;
|
|
29
|
+
rng: Prng.PrngState;
|
|
30
|
+
/** false = dead slot, reusable by the next emission */
|
|
31
|
+
alive: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* true for `fill`-mode particles: they never age out and wrap around the
|
|
34
|
+
* fill region's edges instead of dying, so the field stays evenly
|
|
35
|
+
* populated forever. Emitter-mode particles leave this false.
|
|
36
|
+
*/
|
|
37
|
+
wrap: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** an inclusive numeric range `[min, max]`, sampled uniformly at birth */
|
|
40
|
+
export type Range = readonly [min: number, max: number];
|
|
41
|
+
/** an over-life curve: value goes `from` → `to` across age 0→1, eased */
|
|
42
|
+
export interface OverLife {
|
|
43
|
+
readonly from: number;
|
|
44
|
+
readonly to: number;
|
|
45
|
+
/** timing-function name or function; resolved by Timing.resolve */
|
|
46
|
+
readonly ease?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The emitter configuration an author writes. Ranged props are drawn once
|
|
50
|
+
* per particle at birth; `gravity` is a shared force; over-life curves are
|
|
51
|
+
* deterministic functions of particle age.
|
|
52
|
+
*/
|
|
53
|
+
export interface EmitterConfig {
|
|
54
|
+
/** emitter origin */
|
|
55
|
+
readonly x: number;
|
|
56
|
+
readonly y: number;
|
|
57
|
+
/** launch speed range (px/sec) */
|
|
58
|
+
readonly speed: Range;
|
|
59
|
+
/** launch angle range (degrees; 0 = up, clockwise-positive) */
|
|
60
|
+
readonly angle: Range;
|
|
61
|
+
/** lifetime range (seconds) */
|
|
62
|
+
readonly life: Range;
|
|
63
|
+
/** birth size range (px radius) */
|
|
64
|
+
readonly size: Range;
|
|
65
|
+
/** birth opacity range (0..1), drawn per particle; the over-life opacity
|
|
66
|
+
* curve (if any) multiplies this baseline. Omit → every particle 1. */
|
|
67
|
+
readonly opacity?: Range;
|
|
68
|
+
/** shared downward acceleration (px/sec²); not ranged */
|
|
69
|
+
readonly gravity: number;
|
|
70
|
+
/** colors drawn from uniformly at birth */
|
|
71
|
+
readonly palette: ReadonlyArray<string>;
|
|
72
|
+
/**
|
|
73
|
+
* fill mode only — the rectangular region particles scatter across and
|
|
74
|
+
* wrap around, in the field's local coordinates. The animator defaults
|
|
75
|
+
* this to the whole frame when the author doesn't set it.
|
|
76
|
+
*/
|
|
77
|
+
readonly region?: {
|
|
78
|
+
readonly w: number;
|
|
79
|
+
readonly h: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* fill mode only — magnitude of each particle's small isotropic drift
|
|
83
|
+
* velocity (px/sec). Replaces speed+angle launch for evenly-spread
|
|
84
|
+
* floating fields. `[min, max]` of the speed; direction is uniform.
|
|
85
|
+
*/
|
|
86
|
+
readonly drift?: Range;
|
|
87
|
+
/** optional over-life size curve (multiplies drawn size) */
|
|
88
|
+
readonly sizeOverLife?: OverLife;
|
|
89
|
+
/** optional over-life opacity curve (0..1) */
|
|
90
|
+
readonly opacityOverLife?: OverLife;
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|