@beff/aula 0.0.0-stage → 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/README.md +8 -2
- package/dist/animations.d.ts +634 -0
- package/dist/animations.js +1793 -0
- package/dist/braces.d.ts +84 -0
- package/dist/braces.js +253 -0
- package/dist/card.d.ts +17 -0
- package/dist/card.js +90 -0
- package/dist/colors-palette.d.ts +2242 -0
- package/dist/colors-palette.js +2241 -0
- package/dist/colors.d.ts +120 -0
- package/dist/colors.js +403 -0
- package/dist/curves.d.ts +10 -0
- package/dist/curves.js +128 -0
- package/dist/engine.d.ts +1595 -0
- package/dist/engine.js +3364 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +25 -0
- package/dist/generated/aula.conditional-suspending-3-i32-to-void.wasm +0 -0
- package/dist/generated/aula.core.wasm +0 -0
- package/dist/generated/aula.core2.wasm +0 -0
- package/dist/generated/aula.core3.wasm +0 -0
- package/dist/generated/aula.core4.wasm +0 -0
- package/dist/generated/aula.core5.wasm +0 -0
- package/dist/generated/aula.core6.wasm +0 -0
- package/dist/generated/aula.core7.wasm +0 -0
- package/dist/generated/aula.core8.wasm +0 -0
- package/dist/generated/aula.d.ts +80 -0
- package/dist/generated/aula.js +54639 -0
- package/dist/generated/interfaces/aula-engine-engine.d.ts +983 -0
- package/dist/generated/interfaces/aula-engine-host.d.ts +10 -0
- package/dist/generated/interfaces/aula-engine-tts.d.ts +43 -0
- package/dist/generated/interfaces/aula-engine-types.d.ts +60 -0
- package/dist/geometry.d.ts +551 -0
- package/dist/geometry.js +1821 -0
- package/dist/graph.d.ts +117 -0
- package/dist/graph.js +526 -0
- package/dist/graphing.d.ts +597 -0
- package/dist/graphing.js +1504 -0
- package/dist/host.d.ts +19 -0
- package/dist/host.js +85 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +11 -0
- package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
- package/dist/licenses/espeak-ng-COPYING.txt +674 -0
- package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
- package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
- package/dist/load.d.ts +16 -0
- package/dist/load.js +69 -0
- package/dist/logo.d.ts +30 -0
- package/dist/logo.js +186 -0
- package/dist/manim.d.ts +22 -0
- package/dist/manim.js +19 -0
- package/dist/mobjects.d.ts +127 -0
- package/dist/mobjects.js +316 -0
- package/dist/pointcloud.d.ts +144 -0
- package/dist/pointcloud.js +400 -0
- package/dist/rates.d.ts +19 -0
- package/dist/rates.js +54 -0
- package/dist/run.d.ts +82 -0
- package/dist/run.js +245 -0
- package/dist/tables.d.ts +179 -0
- package/dist/tables.js +403 -0
- package/dist/tex.d.ts +8 -0
- package/dist/tex.js +257 -0
- package/dist/text-layouts.d.ts +64 -0
- package/dist/text-layouts.js +225 -0
- package/dist/text.d.ts +35 -0
- package/dist/text.js +52 -0
- package/dist/theme.d.ts +25 -0
- package/dist/theme.js +12 -0
- package/dist/user-code.d.ts +5 -0
- package/dist/user-code.js +20 -0
- package/dist/utils.d.ts +152 -0
- package/dist/utils.js +517 -0
- package/dist/vector-field.d.ts +132 -0
- package/dist/vector-field.js +361 -0
- package/package.json +45 -3
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
// Manim CE's point clouds: PMobject, Mobject1D, Mobject2D, PGroup, PointCloudDot and Point.
|
|
2
|
+
// Each point is a small filled square, `strokeWidth` pixels of the frame wide, as Manim's
|
|
3
|
+
// camera draws it. The points of one colour run are the subpaths of one node, so
|
|
4
|
+
// a cloud of thousands of points is a few nodes. The points and their colours are read back from
|
|
5
|
+
// the nodes, so every Mobject method and animation keeps them right.
|
|
6
|
+
import { BLACK, FRAME_WIDTH, ORIGIN, PIXEL_WIDTH, PURE_YELLOW, TAU, WHITE, Mobject, Polyline, add, mul, norm, raw, sub, wrong, } from "./engine.js";
|
|
7
|
+
import { colorGradient, colorToRgba, rgbaToColor } from "./colors.js";
|
|
8
|
+
import { engine } from "./load.js";
|
|
9
|
+
/** Frame units of one pixel of the frame. */
|
|
10
|
+
const PIXEL = FRAME_WIDTH / PIXEL_WIDTH;
|
|
11
|
+
/** The square subpaths of `points` with side `side`, four lines each. */
|
|
12
|
+
function squares(points, side) {
|
|
13
|
+
const h = side / 2;
|
|
14
|
+
return points.flatMap(([x, y]) => {
|
|
15
|
+
const corners = [
|
|
16
|
+
[x - h, y - h],
|
|
17
|
+
[x + h, y - h],
|
|
18
|
+
[x + h, y + h],
|
|
19
|
+
[x - h, y + h],
|
|
20
|
+
[x - h, y - h],
|
|
21
|
+
];
|
|
22
|
+
return corners.slice(0, 4).flatMap((a, i) => {
|
|
23
|
+
const b = corners[i + 1] ?? a;
|
|
24
|
+
return [a, add(a, mul(sub(b, a), 1 / 3)), add(a, mul(sub(b, a), 2 / 3)), b];
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** The points of a node of squares (the centres of its square subpaths), and their side. */
|
|
29
|
+
function squareCentres(node) {
|
|
30
|
+
const p = node.getPoints();
|
|
31
|
+
const points = [];
|
|
32
|
+
let side = 0;
|
|
33
|
+
for (let i = 0; i + 15 < p.length; i += 16) {
|
|
34
|
+
const a = p[i] ?? ORIGIN;
|
|
35
|
+
const c = p[i + 8] ?? ORIGIN;
|
|
36
|
+
points.push([(a[0] + c[0]) / 2, (a[1] + c[1]) / 2]);
|
|
37
|
+
side = norm(sub(p[i + 4] ?? a, a));
|
|
38
|
+
}
|
|
39
|
+
return { points, side };
|
|
40
|
+
}
|
|
41
|
+
function sameRgba(a, b) {
|
|
42
|
+
return a.every((v, i) => Math.abs(v - (b[i] ?? 0)) < 1e-9);
|
|
43
|
+
}
|
|
44
|
+
function lerpRgba(a, b, t) {
|
|
45
|
+
const at = (i) => a[i] + (b[i] - a[i]) * t;
|
|
46
|
+
return [at(0), at(1), at(2), at(3)];
|
|
47
|
+
}
|
|
48
|
+
/** NumPy's `arange(start, stop, step)`. */
|
|
49
|
+
function arange(start, stop, step) {
|
|
50
|
+
const n = Math.max(0, Math.ceil((stop - start) / step));
|
|
51
|
+
return Array.from({ length: n }, (_, i) => start + i * step);
|
|
52
|
+
}
|
|
53
|
+
/** A cloud of points: Manim's `PMobject`. Its submobjects are the colour runs of its own
|
|
54
|
+
* points (the nodes of the squares), then the clouds that `add` gives it. */
|
|
55
|
+
export class PMobjectMobject extends Mobject {
|
|
56
|
+
#strokeWidth = 4;
|
|
57
|
+
/** The colour of new points (Manim `color`). */
|
|
58
|
+
color = WHITE;
|
|
59
|
+
copy() {
|
|
60
|
+
return this.copyCloud(new PMobjectMobject(raw(this).copy()));
|
|
61
|
+
}
|
|
62
|
+
/** Gives `to`, a copy of the node, the settings of this cloud. */
|
|
63
|
+
copyCloud(to) {
|
|
64
|
+
to.#strokeWidth = this.#strokeWidth;
|
|
65
|
+
to.color = this.color;
|
|
66
|
+
return to;
|
|
67
|
+
}
|
|
68
|
+
/** The own points, in order. */
|
|
69
|
+
#points() {
|
|
70
|
+
return this.#runs().flatMap((r) => squareCentres(r).points);
|
|
71
|
+
}
|
|
72
|
+
/** The own colour of each own point. */
|
|
73
|
+
#rgbas() {
|
|
74
|
+
return this.#runs().flatMap((r) => {
|
|
75
|
+
const rgba = colorToRgba(r.getFillColor(), r.getFillOpacity());
|
|
76
|
+
return squareCentres(r).points.map(() => rgba);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** The nodes of the own points: the submobjects with points and no submobjects. */
|
|
80
|
+
#runs() {
|
|
81
|
+
return this.submobjects.filter((s) => s.submobjects.length === 0 && s.hasPoints());
|
|
82
|
+
}
|
|
83
|
+
/** Draws the own points again: one node for each run of one colour, before the sub-clouds. */
|
|
84
|
+
#draw(points, rgbas) {
|
|
85
|
+
const others = this.submobjects.filter((s) => !this.#runs().includes(s));
|
|
86
|
+
this.remove(...this.submobjects);
|
|
87
|
+
const side = this.#strokeWidth * PIXEL;
|
|
88
|
+
let start = 0;
|
|
89
|
+
for (let i = 1; i <= points.length; i++) {
|
|
90
|
+
const a = rgbas[start] ?? [1, 1, 1, 1];
|
|
91
|
+
if (i < points.length && sameRgba(a, rgbas[i] ?? a))
|
|
92
|
+
continue;
|
|
93
|
+
const run = Polyline(ORIGIN, ORIGIN).setPoints(squares(points.slice(start, i), side));
|
|
94
|
+
run.setFill(rgbaToColor(a), { opacity: a[3] }).setStroke({ width: 0 });
|
|
95
|
+
this.add(run);
|
|
96
|
+
start = i;
|
|
97
|
+
}
|
|
98
|
+
return this.add(...others);
|
|
99
|
+
}
|
|
100
|
+
/** Removes the own points (Manim `reset_points`). */
|
|
101
|
+
resetPoints() {
|
|
102
|
+
return this.#draw([], []);
|
|
103
|
+
}
|
|
104
|
+
/** The names of the arrays of a point cloud (Manim `get_array_attrs`). */
|
|
105
|
+
getArrayAttrs() {
|
|
106
|
+
return ["points", "rgbas"];
|
|
107
|
+
}
|
|
108
|
+
/** Adds points, in `color` with opacity `alpha`, or one `[r, g, b, a]` each (Manim `add_points`). */
|
|
109
|
+
addPoints(points, opts = {}) {
|
|
110
|
+
const { rgbas, color, alpha = 1 } = opts;
|
|
111
|
+
if (rgbas !== undefined && rgbas.length !== points.length) {
|
|
112
|
+
wrong("addPoints", "points and rgbas must have the same length");
|
|
113
|
+
}
|
|
114
|
+
const rgba = colorToRgba(color ?? this.color, alpha);
|
|
115
|
+
const added = rgbas === undefined
|
|
116
|
+
? points.map(() => rgba)
|
|
117
|
+
: rgbas.map((c) => [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0, c[3] ?? 1]);
|
|
118
|
+
return this.#draw([...this.#points(), ...points], [...this.#rgbas(), ...added]);
|
|
119
|
+
}
|
|
120
|
+
/** Gives every point `color` (Manim `set_color`); with `family` (true) also the sub-clouds. */
|
|
121
|
+
setColor(color = PURE_YELLOW, opts = {}) {
|
|
122
|
+
const { alpha = 1, family = true } = opts;
|
|
123
|
+
const rgba = colorToRgba(color, alpha);
|
|
124
|
+
for (const cloud of family ? clouds(this) : [this]) {
|
|
125
|
+
cloud.#draw(cloud.#points(), cloud.#points().map(() => rgba));
|
|
126
|
+
cloud.color = rgbaToColor(rgba);
|
|
127
|
+
}
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/** The size of a point, in pixels of a 1080-pixel-high frame. */
|
|
131
|
+
getStrokeWidth() {
|
|
132
|
+
return this.#strokeWidth;
|
|
133
|
+
}
|
|
134
|
+
/** Sets the size of the points (Manim `set_stroke_width`); with `family` (true) also of the
|
|
135
|
+
* sub-clouds. */
|
|
136
|
+
setStrokeWidth(width, family = true) {
|
|
137
|
+
for (const cloud of family ? clouds(this) : [this]) {
|
|
138
|
+
cloud.#strokeWidth = width;
|
|
139
|
+
cloud.#draw(cloud.#points(), cloud.#rgbas());
|
|
140
|
+
}
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/** Spreads `colors` over the points in order (Manim `set_color_by_gradient`). */
|
|
144
|
+
setColorByGradient(...colors) {
|
|
145
|
+
const points = this.#points();
|
|
146
|
+
return this.#draw(points, colorGradient(colors, points.length).map((c) => colorToRgba(c)));
|
|
147
|
+
}
|
|
148
|
+
/** Colours the points from `innerColor` at `center` to `outerColor` at `radius` (Manim
|
|
149
|
+
* `set_colors_by_radial_gradient`). */
|
|
150
|
+
setColorsByRadialGradient(opts = {}) {
|
|
151
|
+
const { center = this.getCenter(), radius = 1, innerColor = WHITE, outerColor = BLACK } = opts;
|
|
152
|
+
const [a, b] = [colorToRgba(innerColor), colorToRgba(outerColor)];
|
|
153
|
+
for (const cloud of clouds(this)) {
|
|
154
|
+
const points = cloud.#points();
|
|
155
|
+
cloud.#draw(points, points.map((p) => lerpRgba(a, b, norm(sub(p, center)) / radius)));
|
|
156
|
+
}
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/** Takes the colours of the points of `mobject`, in order (Manim `match_colors`). */
|
|
160
|
+
matchColors(mobject) {
|
|
161
|
+
const other = mobject instanceof PMobjectMobject ? mobject.#rgbas() : [];
|
|
162
|
+
const points = this.#points();
|
|
163
|
+
return this.#draw(points, points.map((_, i) => other[Math.min(i, other.length - 1)] ?? colorToRgba(this.color)));
|
|
164
|
+
}
|
|
165
|
+
/** Removes the points where `condition` is true (Manim `filter_out`). */
|
|
166
|
+
filterOut(condition) {
|
|
167
|
+
for (const cloud of clouds(this)) {
|
|
168
|
+
const [points, rgbas] = [cloud.#points(), cloud.#rgbas()];
|
|
169
|
+
const keep = points.map((p) => !condition(p));
|
|
170
|
+
cloud.#draw(points.filter((_, i) => keep[i]), rgbas.filter((_, i) => keep[i]));
|
|
171
|
+
}
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
/** Keeps every `factor`-th point (Manim `thin_out`). */
|
|
175
|
+
thinOut(factor = 5) {
|
|
176
|
+
for (const cloud of clouds(this)) {
|
|
177
|
+
const [points, rgbas] = [cloud.#points(), cloud.#rgbas()];
|
|
178
|
+
cloud.#draw(points.filter((_, i) => i % factor === 0), rgbas.filter((_, i) => i % factor === 0));
|
|
179
|
+
}
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
/** Orders the points by `f` (Manim `sort_points`; by x by default). */
|
|
183
|
+
sortPoints(f = (p) => p[0]) {
|
|
184
|
+
for (const cloud of clouds(this)) {
|
|
185
|
+
const [points, rgbas] = [cloud.#points(), cloud.#rgbas()];
|
|
186
|
+
const order = points.map((p, i) => [f(p), i]).toSorted((a, b) => a[0] - b[0]);
|
|
187
|
+
cloud.#draw(order.map(([, i]) => points[i] ?? ORIGIN), order.map(([, i]) => rgbas[i] ?? [1, 1, 1, 1]));
|
|
188
|
+
}
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
/** Moves the colours `alpha` of the way to `color` (Manim `fade_to`). */
|
|
192
|
+
fadeTo(color, alpha, opts = {}) {
|
|
193
|
+
const target = colorToRgba(color);
|
|
194
|
+
this.#draw(this.#points(), this.#rgbas().map((c) => lerpRgba(c, target, alpha)));
|
|
195
|
+
for (const child of this.submobjects)
|
|
196
|
+
if (child instanceof PMobjectMobject)
|
|
197
|
+
child.fadeTo(color, alpha, opts);
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
/** The colours of the points of the cloud and its sub-clouds (Manim `get_all_rgbas`). */
|
|
201
|
+
getAllRgbas() {
|
|
202
|
+
return clouds(this).flatMap((c) => c.#rgbas());
|
|
203
|
+
}
|
|
204
|
+
/** Takes the points of the sub-clouds as its own, and removes the sub-clouds (Manim
|
|
205
|
+
* `ingest_submobjects`). */
|
|
206
|
+
ingestSubmobjects() {
|
|
207
|
+
const all = clouds(this);
|
|
208
|
+
const points = all.flatMap((c) => c.#points());
|
|
209
|
+
const rgbas = all.flatMap((c) => c.#rgbas());
|
|
210
|
+
this.remove(...this.submobjects);
|
|
211
|
+
return this.#draw(points, rgbas);
|
|
212
|
+
}
|
|
213
|
+
/** The colour of the first point (Manim `get_color`). */
|
|
214
|
+
getColor() {
|
|
215
|
+
const first = this.getAllRgbas()[0];
|
|
216
|
+
return first === undefined ? this.color : rgbaToColor(first);
|
|
217
|
+
}
|
|
218
|
+
/** The point at `alpha` of the list of points (Manim `point_from_proportion`). */
|
|
219
|
+
pointFromProportion(alpha) {
|
|
220
|
+
const points = clouds(this).flatMap((c) => c.#points());
|
|
221
|
+
return points[Math.floor(alpha * (points.length - 1))] ?? this.getCenter();
|
|
222
|
+
}
|
|
223
|
+
/** `m.PMobject` (Manim `get_mobject_type_class`). */
|
|
224
|
+
getMobjectTypeClass() {
|
|
225
|
+
return PMobject;
|
|
226
|
+
}
|
|
227
|
+
/** Repeats points until the cloud has as many as `largerMobject` (Manim
|
|
228
|
+
* `align_points_with_larger`). */
|
|
229
|
+
alignPointsWithLarger(largerMobject) {
|
|
230
|
+
const n = largerMobject instanceof PMobjectMobject ? largerMobject.#points().length : 0;
|
|
231
|
+
const [points, rgbas] = [this.#points(), this.#rgbas()];
|
|
232
|
+
if (points.length === 0 || n <= points.length)
|
|
233
|
+
return this;
|
|
234
|
+
const at = (i) => Math.floor((i * points.length) / n);
|
|
235
|
+
return this.#draw(Array.from({ length: n }, (_, i) => points[at(i)] ?? ORIGIN), Array.from({ length: n }, (_, i) => rgbas[at(i)] ?? [1, 1, 1, 1]));
|
|
236
|
+
}
|
|
237
|
+
/** A one-point cloud at `center` (Manim `get_point_mobject`). */
|
|
238
|
+
getPointMobject(center) {
|
|
239
|
+
return Point(center ?? this.getCenter());
|
|
240
|
+
}
|
|
241
|
+
/** Takes colours and point size `alpha` of the way from `mobject1` to `mobject2` (Manim
|
|
242
|
+
* `interpolate_color`). */
|
|
243
|
+
interpolateColor(mobject1, mobject2, alpha) {
|
|
244
|
+
const a = mobject1 instanceof PMobjectMobject ? mobject1.#rgbas() : [];
|
|
245
|
+
const b = mobject2 instanceof PMobjectMobject ? mobject2.#rgbas() : [];
|
|
246
|
+
const points = this.#points();
|
|
247
|
+
const white = [1, 1, 1, 1];
|
|
248
|
+
const rgbas = points.map((_, i) => lerpRgba(a[i] ?? white, b[i] ?? white, alpha));
|
|
249
|
+
const w1 = mobject1 instanceof PMobjectMobject ? mobject1.#strokeWidth : this.#strokeWidth;
|
|
250
|
+
const w2 = mobject2 instanceof PMobjectMobject ? mobject2.#strokeWidth : this.#strokeWidth;
|
|
251
|
+
this.#strokeWidth = w1 + (w2 - w1) * alpha;
|
|
252
|
+
return this.#draw(points, rgbas);
|
|
253
|
+
}
|
|
254
|
+
/** Becomes the points of `mobject` from proportion `a` to `b` (Manim
|
|
255
|
+
* `pointwise_become_partial`). */
|
|
256
|
+
pointwiseBecomePartial(mobject, a, b) {
|
|
257
|
+
if (!(mobject instanceof PMobjectMobject))
|
|
258
|
+
return this;
|
|
259
|
+
const [points, rgbas] = [mobject.#points(), mobject.#rgbas()];
|
|
260
|
+
const [lo, hi] = [Math.floor(a * points.length), Math.floor(b * points.length)];
|
|
261
|
+
return this.#draw(points.slice(lo, hi), rgbas.slice(lo, hi));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/** The cloud and every cloud inside it. */
|
|
265
|
+
function clouds(m) {
|
|
266
|
+
return m.getFamily().filter((x) => x instanceof PMobjectMobject);
|
|
267
|
+
}
|
|
268
|
+
function makeCloud(make, opts, width) {
|
|
269
|
+
const c = make(engine.vGroup([]));
|
|
270
|
+
c.color = opts.color === undefined ? WHITE : rgbaToColor(colorToRgba(opts.color));
|
|
271
|
+
return c.setStrokeWidth(opts.strokeWidth ?? width, false);
|
|
272
|
+
}
|
|
273
|
+
/** An empty point cloud (Manim `PMobject`): add points with `addPoints`. */
|
|
274
|
+
export function PMobject(opts = {}) {
|
|
275
|
+
return makeCloud((h) => new PMobjectMobject(h), opts, 4);
|
|
276
|
+
}
|
|
277
|
+
/** A point cloud of lines (Manim `Mobject1D`): `addLine` puts `density` points on each unit. */
|
|
278
|
+
export class Mobject1DMobject extends PMobjectMobject {
|
|
279
|
+
density = 10;
|
|
280
|
+
get epsilon() {
|
|
281
|
+
return 1 / this.density;
|
|
282
|
+
}
|
|
283
|
+
copy() {
|
|
284
|
+
const d = this.copyCloud(new Mobject1DMobject(raw(this).copy()));
|
|
285
|
+
d.density = this.density;
|
|
286
|
+
return d;
|
|
287
|
+
}
|
|
288
|
+
/** Adds the points of the line from `start` to `end`, `density` on each unit (Manim `add_line`). */
|
|
289
|
+
addLine(start, end, color) {
|
|
290
|
+
const length = norm(sub(end, start));
|
|
291
|
+
const points = length === 0
|
|
292
|
+
? [start]
|
|
293
|
+
: arange(0, 1, this.epsilon / length).map((t) => add(start, mul(sub(end, start), t)));
|
|
294
|
+
return this.addPoints(points, color === undefined ? {} : { color });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/** `Mobject1D({ density })` (Manim; default density 10). */
|
|
298
|
+
export function Mobject1D(opts = {}) {
|
|
299
|
+
const { density = 10, ...rest } = opts;
|
|
300
|
+
const c = makeCloud((h) => new Mobject1DMobject(h), rest, 4);
|
|
301
|
+
c.density = density;
|
|
302
|
+
return c;
|
|
303
|
+
}
|
|
304
|
+
/** A point cloud of areas (Manim `Mobject2D`). */
|
|
305
|
+
export class Mobject2DMobject extends PMobjectMobject {
|
|
306
|
+
density = 25;
|
|
307
|
+
copy() {
|
|
308
|
+
const d = this.copyCloud(new Mobject2DMobject(raw(this).copy()));
|
|
309
|
+
d.density = this.density;
|
|
310
|
+
return d;
|
|
311
|
+
}
|
|
312
|
+
get epsilon() {
|
|
313
|
+
return 1 / this.density;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** `Mobject2D({ density })` (Manim; default density 25). */
|
|
317
|
+
export function Mobject2D(opts = {}) {
|
|
318
|
+
const { density = 25, ...rest } = opts;
|
|
319
|
+
const c = makeCloud((h) => new Mobject2DMobject(h), rest, 4);
|
|
320
|
+
c.density = density;
|
|
321
|
+
return c;
|
|
322
|
+
}
|
|
323
|
+
/** Point clouds as one (Manim `PGroup`): `PGroup(cloud1, cloud2, opts)`. */
|
|
324
|
+
export function PGroup(...args) {
|
|
325
|
+
const pmobs = args.filter((a) => a instanceof Mobject);
|
|
326
|
+
const opts = args.find((a) => !(a instanceof Mobject)) ?? {};
|
|
327
|
+
for (const p of pmobs) {
|
|
328
|
+
if (!(p instanceof PMobjectMobject))
|
|
329
|
+
wrong("PGroup", "all submobjects must be point clouds (PMobject)");
|
|
330
|
+
}
|
|
331
|
+
return makeCloud((h) => new PMobjectMobject(h), opts, 4).add(...pmobs);
|
|
332
|
+
}
|
|
333
|
+
/** A disc of points (Manim `PointCloudDot`): rings every `1 / density` up to `radius`. */
|
|
334
|
+
export class PointCloudDotMobject extends Mobject1DMobject {
|
|
335
|
+
radius = 2;
|
|
336
|
+
#center = ORIGIN;
|
|
337
|
+
copy() {
|
|
338
|
+
const d = this.copyCloud(new PointCloudDotMobject(raw(this).copy()));
|
|
339
|
+
d.density = this.density;
|
|
340
|
+
d.radius = this.radius;
|
|
341
|
+
d.#center = this.#center;
|
|
342
|
+
return d;
|
|
343
|
+
}
|
|
344
|
+
/** Makes the points again (Manim `init_points`). */
|
|
345
|
+
initPoints() {
|
|
346
|
+
this.resetPoints();
|
|
347
|
+
return this.generatePoints();
|
|
348
|
+
}
|
|
349
|
+
/** Adds the rings of points about the centre (Manim `generate_points`). */
|
|
350
|
+
generatePoints() {
|
|
351
|
+
const e = this.epsilon;
|
|
352
|
+
const points = arange(e, this.radius, e).flatMap((r) => {
|
|
353
|
+
const n = Math.floor((TAU * (r + e)) / e);
|
|
354
|
+
return Array.from({ length: n }, (_, k) => {
|
|
355
|
+
const theta = n === 1 ? 0 : (TAU * k) / (n - 1);
|
|
356
|
+
return add(this.#center, [r * Math.cos(theta), r * Math.sin(theta)]);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
return this.addPoints(points);
|
|
360
|
+
}
|
|
361
|
+
/** The centre for `generatePoints`. */
|
|
362
|
+
setGenerationCenter(center) {
|
|
363
|
+
this.#center = center;
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/** `PointCloudDot({ center, radius, strokeWidth, density, color })` (Manim; defaults
|
|
368
|
+
* `ORIGIN`, 2, 2, 10 and `PURE_YELLOW`). */
|
|
369
|
+
export function PointCloudDot(opts = {}) {
|
|
370
|
+
const { center = ORIGIN, radius = 2, density = 10, color = PURE_YELLOW, strokeWidth = 2 } = opts;
|
|
371
|
+
const c = makeCloud((h) => new PointCloudDotMobject(h), { color, strokeWidth }, 2);
|
|
372
|
+
c.density = density;
|
|
373
|
+
c.radius = radius;
|
|
374
|
+
return c.initPoints().shift(center);
|
|
375
|
+
}
|
|
376
|
+
/** A cloud of one point (Manim `Point`). */
|
|
377
|
+
export class PointMobject extends PMobjectMobject {
|
|
378
|
+
location = ORIGIN;
|
|
379
|
+
copy() {
|
|
380
|
+
const d = this.copyCloud(new PointMobject(raw(this).copy()));
|
|
381
|
+
d.location = this.location;
|
|
382
|
+
return d;
|
|
383
|
+
}
|
|
384
|
+
/** Makes the point again (Manim `init_points`). */
|
|
385
|
+
initPoints() {
|
|
386
|
+
this.resetPoints();
|
|
387
|
+
return this.generatePoints();
|
|
388
|
+
}
|
|
389
|
+
/** Adds the point at `location` (Manim `generate_points`). */
|
|
390
|
+
generatePoints() {
|
|
391
|
+
return this.addPoints([this.location]);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/** `Point(location, { color })` (Manim; defaults `ORIGIN` and `BLACK`). */
|
|
395
|
+
export function Point(location = ORIGIN, opts = {}) {
|
|
396
|
+
const { color = BLACK, ...rest } = opts;
|
|
397
|
+
const p = makeCloud((h) => new PointMobject(h), { color, ...rest }, 4);
|
|
398
|
+
p.location = location;
|
|
399
|
+
return p.initPoints();
|
|
400
|
+
}
|
package/dist/rates.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RateFunc } from "./engine.ts";
|
|
2
|
+
/** Manim `smoothstep`: `3t² - 2t³`. */
|
|
3
|
+
export declare function smoothstep(t: number): number;
|
|
4
|
+
/** Manim `smootherstep`: `6t⁵ - 15t⁴ + 10t³`. */
|
|
5
|
+
export declare function smootherstep(t: number): number;
|
|
6
|
+
/** Manim `smoothererstep`: `35t⁴ - 84t⁵ + 70t⁶ - 20t⁷`. */
|
|
7
|
+
export declare function smoothererstep(t: number): number;
|
|
8
|
+
/** Manim `running_start`: goes back by `pullFactor` first, then forward. */
|
|
9
|
+
export declare function runningStart(t: number, pullFactor?: number): number;
|
|
10
|
+
/** Manim `not_quite_there`: a rate function that stops at `proportion` of `func`. */
|
|
11
|
+
export declare function notQuiteThere(func?: RateFunc, proportion?: number): RateFunc;
|
|
12
|
+
/** Manim `wiggle`: `wiggles` half swings, larger in the middle; 0 at both ends. */
|
|
13
|
+
export declare function wiggle(t: number, wiggles?: number): number;
|
|
14
|
+
/** Manim `squish_rate_func`: `func` plays between `a` and `b` and holds before and after. */
|
|
15
|
+
export declare function squishRateFunc(func: RateFunc, a?: number, b?: number): RateFunc;
|
|
16
|
+
/** Manim `lingering`: linear in the first 80% of the time, then it holds at 1. */
|
|
17
|
+
export declare function lingering(t: number): number;
|
|
18
|
+
/** Manim `exponential_decay`: `1 - e^(-t / halfLife)`. */
|
|
19
|
+
export declare function exponentialDecay(t: number, halfLife?: number): number;
|
package/dist/rates.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// The rate functions of Manim CE's `rate_functions` that the engine does not run: they run in
|
|
2
|
+
// JavaScript, as a custom rate function does. engine.ts has the built-in ones.
|
|
3
|
+
import { smooth, thereAndBack } from "./engine.js";
|
|
4
|
+
/** `f` on 0..1; 0 below and 1 above (Manim's `unit_interval`). */
|
|
5
|
+
function unitInterval(t, f) {
|
|
6
|
+
return t < 0 ? 0 : t > 1 ? 1 : f(t);
|
|
7
|
+
}
|
|
8
|
+
/** Manim `smoothstep`: `3t² - 2t³`. */
|
|
9
|
+
export function smoothstep(t) {
|
|
10
|
+
return unitInterval(t, (u) => 3 * u ** 2 - 2 * u ** 3);
|
|
11
|
+
}
|
|
12
|
+
/** Manim `smootherstep`: `6t⁵ - 15t⁴ + 10t³`. */
|
|
13
|
+
export function smootherstep(t) {
|
|
14
|
+
return unitInterval(t, (u) => 6 * u ** 5 - 15 * u ** 4 + 10 * u ** 3);
|
|
15
|
+
}
|
|
16
|
+
/** Manim `smoothererstep`: `35t⁴ - 84t⁵ + 70t⁶ - 20t⁷`. */
|
|
17
|
+
export function smoothererstep(t) {
|
|
18
|
+
return unitInterval(t, (u) => 35 * u ** 4 - 84 * u ** 5 + 70 * u ** 6 - 20 * u ** 7);
|
|
19
|
+
}
|
|
20
|
+
/** Manim `running_start`: goes back by `pullFactor` first, then forward. */
|
|
21
|
+
export function runningStart(t, pullFactor = -0.5) {
|
|
22
|
+
return unitInterval(t, (u) => {
|
|
23
|
+
const mt = 1 - u;
|
|
24
|
+
return (15 * u ** 2 * mt ** 4 * pullFactor +
|
|
25
|
+
20 * u ** 3 * mt ** 3 * pullFactor +
|
|
26
|
+
15 * u ** 4 * mt ** 2 +
|
|
27
|
+
6 * u ** 5 * mt +
|
|
28
|
+
u ** 6);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Manim `not_quite_there`: a rate function that stops at `proportion` of `func`. */
|
|
32
|
+
export function notQuiteThere(func = smooth, proportion = 0.7) {
|
|
33
|
+
return (t) => proportion * func(t);
|
|
34
|
+
}
|
|
35
|
+
/** Manim `wiggle`: `wiggles` half swings, larger in the middle; 0 at both ends. */
|
|
36
|
+
export function wiggle(t, wiggles = 2) {
|
|
37
|
+
return t < 0 || t > 1 ? 0 : thereAndBack(t) * Math.sin(wiggles * Math.PI * t);
|
|
38
|
+
}
|
|
39
|
+
/** Manim `squish_rate_func`: `func` plays between `a` and `b` and holds before and after. */
|
|
40
|
+
export function squishRateFunc(func, a = 0.4, b = 0.6) {
|
|
41
|
+
return (t) => {
|
|
42
|
+
if (a === b)
|
|
43
|
+
return a;
|
|
44
|
+
return func(t < a ? 0 : t > b ? 1 : (t - a) / (b - a));
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Manim `lingering`: linear in the first 80% of the time, then it holds at 1. */
|
|
48
|
+
export function lingering(t) {
|
|
49
|
+
return unitInterval(t, squishRateFunc((u) => u, 0, 0.8));
|
|
50
|
+
}
|
|
51
|
+
/** Manim `exponential_decay`: `1 - e^(-t / halfLife)`. */
|
|
52
|
+
export function exponentialDecay(t, halfLife = 0.1) {
|
|
53
|
+
return unitInterval(t, (u) => 1 - Math.exp(-u / halfLife));
|
|
54
|
+
}
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ChapterRun, ProjectDefinition, StackFrame } from "./engine.ts";
|
|
2
|
+
import type { Diagnostic, Location, ChapterText, Narration } from "./text.ts";
|
|
3
|
+
export { importUserModule } from "./user-code.ts";
|
|
4
|
+
export { renderScene } from "./engine.ts";
|
|
5
|
+
export type { Leaf, SceneRun } from "./engine.ts";
|
|
6
|
+
export type { StackFrame } from "./engine.ts";
|
|
7
|
+
/** How a host reads stack frames and names their files. */
|
|
8
|
+
export interface Host {
|
|
9
|
+
/** The frames of an error: of a call that the core keeps, or of a thrown error. The first
|
|
10
|
+
* frame is the function that made the error. */
|
|
11
|
+
frames(error: Error): StackFrame[];
|
|
12
|
+
/** The name of a frame's file in diagnostics (a path from the workspace root), or undefined
|
|
13
|
+
* for a frame that is not a workspace file. */
|
|
14
|
+
name(file: string): string | undefined;
|
|
15
|
+
/** True when `path`, from the working directory (as the paths in diagnostics are), is a
|
|
16
|
+
* file. The paragraph checks get it (`CheckedChapter.exists`). The CLI reads the file
|
|
17
|
+
* system; the web app has no files, and gives true. */
|
|
18
|
+
exists(path: string): boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Frames per second of the Lottie files: the engine's rate (`engine.fps()`, which
|
|
21
|
+
* `constants.test.ts` checks), as a value here: an import does not load the engine. */
|
|
22
|
+
export declare const FPS = 15;
|
|
23
|
+
/** `tts`: the narrator engine (tokens to audio), after `loadEngine()`. */
|
|
24
|
+
export { loadEngine, tts } from "./load.ts";
|
|
25
|
+
/** The name of chapter 0, the title card. */
|
|
26
|
+
export declare const TITLE = "title";
|
|
27
|
+
/** The slug of a title or heading: lower-case words joined by `-`. */
|
|
28
|
+
export declare function slugOf(text: string): string;
|
|
29
|
+
/** The chapter names of a project in narration order: the title card, then `NN-<heading slug>`. */
|
|
30
|
+
export declare function chapterNames(project: Pick<ProjectDefinition, "chapters">): string[];
|
|
31
|
+
/** The frames of an error from the V8 text of its stack (Node), with `file:` URLs as paths. */
|
|
32
|
+
export declare function v8Frames(made: Error): StackFrame[];
|
|
33
|
+
/** The place of a define call (`defineChapter`, `defineProject`): the frame of its caller, as
|
|
34
|
+
* `host` reads it. */
|
|
35
|
+
export declare function definedAt(definition: {
|
|
36
|
+
readonly call: Error;
|
|
37
|
+
}, host?: Host): StackFrame;
|
|
38
|
+
/** An error diagnostic. */
|
|
39
|
+
export declare function error(message: string, more?: {
|
|
40
|
+
location?: Location;
|
|
41
|
+
hint?: string;
|
|
42
|
+
}): Diagnostic;
|
|
43
|
+
/** The diagnostic of a thrown value: the first frame in the chapter file `chapterFile` (as the stack names
|
|
44
|
+
* it) is the location, the workspace frames before it are the stack. When a callback threw inside
|
|
45
|
+
* the engine call, that error is the one reported, with its own stack. */
|
|
46
|
+
export declare function diagnosticOf(value: unknown, chapterFile: string, host: Host): Diagnostic;
|
|
47
|
+
/** The result of a read or a drawing: `ok` is false when there are errors; `value` is there when the chapter
|
|
48
|
+
* ran to its end. */
|
|
49
|
+
export interface ChapterResult<T> {
|
|
50
|
+
ok: boolean;
|
|
51
|
+
diagnostics: Diagnostic[];
|
|
52
|
+
value?: T | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** How aula reads a chapter. */
|
|
55
|
+
export interface ReadOptions {
|
|
56
|
+
/** How aula reads the stack frames and names their files (default: V8 frames, each file
|
|
57
|
+
* named by its path). */
|
|
58
|
+
host?: Host | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Reads chapter `index` (from 1) of `project`: its text and its text problems, with no move
|
|
61
|
+
* run. The paragraph checks run only when the chapter is checked (`checkChapter`). */
|
|
62
|
+
export declare function readChapter(project: Pick<ProjectDefinition, "title" | "chapters">, index: number, options?: ReadOptions): ChapterResult<ChapterText>;
|
|
63
|
+
/** Checks chapter `index` (0 is the title card) of `project`, as `aula check` does: it runs
|
|
64
|
+
* the moves in list order with no clock and no narration, and gives the text problems, the
|
|
65
|
+
* engine's checks of the picture after each animation, the kit findings and the paragraph
|
|
66
|
+
* checks. With sync by construction, no check depends on the length of a `say`. */
|
|
67
|
+
export declare function checkChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "theme" | "card">, index: number, options?: ReadOptions): ChapterResult<{
|
|
68
|
+
diagnostics: Diagnostic[];
|
|
69
|
+
}>;
|
|
70
|
+
/** How aula draws a chapter against a narration. */
|
|
71
|
+
export interface RenderOptions extends ReadOptions {
|
|
72
|
+
/** The narration of this chapter. With fewer cues than the chapter's text (a prefix, as the
|
|
73
|
+
* web app narrates a chapter while it plays), the chapter is drawn up to the narrated end. */
|
|
74
|
+
narration: Narration;
|
|
75
|
+
/** Draw no frames: only the clock (the waits and the narration on the clock of the
|
|
76
|
+
* picture). */
|
|
77
|
+
lint?: boolean | undefined;
|
|
78
|
+
}
|
|
79
|
+
/** Draws chapter `index` (0 is the title card) of `project` on its narration: its Lottie, its
|
|
80
|
+
* length in frames, the waits of the narration and the warnings at the moves that the
|
|
81
|
+
* narration waits for. */
|
|
82
|
+
export declare function renderChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "theme" | "card">, index: number, options: RenderOptions): ChapterResult<ChapterRun>;
|