@beff/aula 0.8.2 → 0.9.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/generated/aula.core5.wasm +0 -0
- package/dist/index.d.ts +7304 -6
- package/dist/index.js +14864 -11
- package/dist/index.js.map +1 -0
- package/package.json +8 -25
- package/dist/animations.d.ts +0 -635
- package/dist/animations.js +0 -1778
- package/dist/braces.d.ts +0 -84
- package/dist/braces.js +0 -253
- package/dist/card.d.ts +0 -17
- package/dist/card.js +0 -90
- package/dist/colors-palette.d.ts +0 -2242
- package/dist/colors-palette.js +0 -2241
- package/dist/colors.d.ts +0 -120
- package/dist/colors.js +0 -403
- package/dist/curves.d.ts +0 -10
- package/dist/curves.js +0 -128
- package/dist/engine.d.ts +0 -1705
- package/dist/engine.js +0 -3561
- package/dist/errors.d.ts +0 -19
- package/dist/errors.js +0 -25
- package/dist/geometry.d.ts +0 -551
- package/dist/geometry.js +0 -1555
- package/dist/graph.d.ts +0 -117
- package/dist/graph.js +0 -526
- package/dist/graphing.d.ts +0 -597
- package/dist/graphing.js +0 -1504
- package/dist/host.d.ts +0 -19
- package/dist/host.js +0 -85
- package/dist/lexicon.d.ts +0 -10
- package/dist/lexicon.js +0 -23
- package/dist/load.d.ts +0 -21
- package/dist/load.js +0 -109
- package/dist/logo.d.ts +0 -30
- package/dist/logo.js +0 -186
- package/dist/manim.d.ts +0 -22
- package/dist/manim.js +0 -19
- package/dist/media.d.ts +0 -34
- package/dist/media.js +0 -391
- package/dist/mobjects.d.ts +0 -127
- package/dist/mobjects.js +0 -316
- package/dist/picture.d.ts +0 -23
- package/dist/picture.js +0 -291
- package/dist/pointcloud.d.ts +0 -144
- package/dist/pointcloud.js +0 -384
- package/dist/rates.d.ts +0 -19
- package/dist/rates.js +0 -54
- package/dist/run.d.ts +0 -101
- package/dist/run.js +0 -323
- package/dist/tables.d.ts +0 -179
- package/dist/tables.js +0 -403
- package/dist/tex.d.ts +0 -8
- package/dist/tex.js +0 -257
- package/dist/text-layouts.d.ts +0 -64
- package/dist/text-layouts.js +0 -225
- package/dist/text.d.ts +0 -61
- package/dist/text.js +0 -78
- package/dist/theme.d.ts +0 -25
- package/dist/theme.js +0 -12
- package/dist/user-code.d.ts +0 -5
- package/dist/user-code.js +0 -20
- package/dist/utils.d.ts +0 -152
- package/dist/utils.js +0 -517
- package/dist/vector-field.d.ts +0 -132
- package/dist/vector-field.js +0 -361
package/dist/pointcloud.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { type Color, type Point as EnginePoint, Mobject } from "./engine.ts";
|
|
2
|
-
import { type ParsableManimColor } from "./colors.ts";
|
|
3
|
-
/** A point: `[x, y]`. `m.Point(location)` is also Manim's one-point cloud. */
|
|
4
|
-
export type Point = EnginePoint;
|
|
5
|
-
/** `[r, g, b, a]`, each from 0 to 1. */
|
|
6
|
-
type Rgba = [number, number, number, number];
|
|
7
|
-
/** A cloud of points: Manim's `PMobject`. Its submobjects are the colour runs of its own
|
|
8
|
-
* points (the nodes of the squares), then the clouds that `add` gives it. */
|
|
9
|
-
export declare class PMobjectMobject extends Mobject {
|
|
10
|
-
#private;
|
|
11
|
-
/** The colour of new points (Manim `color`). */
|
|
12
|
-
color: Color;
|
|
13
|
-
copy(): PMobjectMobject;
|
|
14
|
-
/** Gives `to`, a copy of the node, the settings of this cloud. */
|
|
15
|
-
protected copyCloud<T extends PMobjectMobject>(to: T): T;
|
|
16
|
-
/** Removes the own points (Manim `reset_points`). */
|
|
17
|
-
resetPoints(): this;
|
|
18
|
-
/** The names of the arrays of a point cloud (Manim `get_array_attrs`). */
|
|
19
|
-
getArrayAttrs(): string[];
|
|
20
|
-
/** Adds points, in `color` with opacity `alpha`, or one `[r, g, b, a]` each (Manim `add_points`). */
|
|
21
|
-
addPoints(points: readonly Point[], opts?: {
|
|
22
|
-
rgbas?: readonly (readonly number[])[];
|
|
23
|
-
color?: ParsableManimColor;
|
|
24
|
-
alpha?: number;
|
|
25
|
-
}): this;
|
|
26
|
-
/** Gives every point `color` (Manim `set_color`); with `family` (true) also the sub-clouds. */
|
|
27
|
-
setColor(color?: ParsableManimColor, opts?: {
|
|
28
|
-
alpha?: number;
|
|
29
|
-
family?: boolean;
|
|
30
|
-
}): this;
|
|
31
|
-
/** The size of a point, in pixels of the 854×480 frame. */
|
|
32
|
-
getStrokeWidth(): number;
|
|
33
|
-
/** Sets the size of the points (Manim `set_stroke_width`); with `family` (true) also of the
|
|
34
|
-
* sub-clouds. */
|
|
35
|
-
setStrokeWidth(width: number, family?: boolean): this;
|
|
36
|
-
/** Spreads `colors` over the points in order (Manim `set_color_by_gradient`). */
|
|
37
|
-
setColorByGradient(...colors: ParsableManimColor[]): this;
|
|
38
|
-
/** Colours the points from `innerColor` at `center` to `outerColor` at `radius` (Manim
|
|
39
|
-
* `set_colors_by_radial_gradient`). */
|
|
40
|
-
setColorsByRadialGradient(opts?: {
|
|
41
|
-
center?: Point;
|
|
42
|
-
radius?: number;
|
|
43
|
-
innerColor?: ParsableManimColor;
|
|
44
|
-
outerColor?: ParsableManimColor;
|
|
45
|
-
}): this;
|
|
46
|
-
/** Takes the colours of the points of `mobject`, in order (Manim `match_colors`). */
|
|
47
|
-
matchColors(mobject: Mobject): this;
|
|
48
|
-
/** Removes the points where `condition` is true (Manim `filter_out`). */
|
|
49
|
-
filterOut(condition: (p: Point) => boolean): this;
|
|
50
|
-
/** Keeps every `factor`-th point (Manim `thin_out`). */
|
|
51
|
-
thinOut(factor?: number): this;
|
|
52
|
-
/** Orders the points by `f` (Manim `sort_points`; by x by default). */
|
|
53
|
-
sortPoints(f?: (p: Point) => number): this;
|
|
54
|
-
/** Moves the colours `alpha` of the way to `color` (Manim `fade_to`). */
|
|
55
|
-
fadeTo(color: ParsableManimColor, alpha: number, opts?: {
|
|
56
|
-
family?: boolean;
|
|
57
|
-
}): this;
|
|
58
|
-
/** The colours of the points of the cloud and its sub-clouds (Manim `get_all_rgbas`). */
|
|
59
|
-
getAllRgbas(): Rgba[];
|
|
60
|
-
/** Takes the points of the sub-clouds as its own, and removes the sub-clouds (Manim
|
|
61
|
-
* `ingest_submobjects`). */
|
|
62
|
-
ingestSubmobjects(): this;
|
|
63
|
-
/** The colour of the first point (Manim `get_color`). */
|
|
64
|
-
getColor(): Color;
|
|
65
|
-
/** The point at `alpha` of the list of points (Manim `point_from_proportion`). */
|
|
66
|
-
pointFromProportion(alpha: number): Point;
|
|
67
|
-
/** `m.PMobject` (Manim `get_mobject_type_class`). */
|
|
68
|
-
getMobjectTypeClass(): typeof PMobject;
|
|
69
|
-
/** Repeats points until the cloud has as many as `largerMobject` (Manim
|
|
70
|
-
* `align_points_with_larger`). */
|
|
71
|
-
alignPointsWithLarger(largerMobject: Mobject): this;
|
|
72
|
-
/** A one-point cloud at `center` (Manim `get_point_mobject`). */
|
|
73
|
-
getPointMobject(center?: Point): PointMobject;
|
|
74
|
-
/** Takes colours and point size `alpha` of the way from `mobject1` to `mobject2` (Manim
|
|
75
|
-
* `interpolate_color`). */
|
|
76
|
-
interpolateColor(mobject1: Mobject, mobject2: Mobject, alpha: number): this;
|
|
77
|
-
/** Becomes the points of `mobject` from proportion `a` to `b` (Manim
|
|
78
|
-
* `pointwise_become_partial`). */
|
|
79
|
-
pointwiseBecomePartial(mobject: Mobject, a: number, b: number): this;
|
|
80
|
-
}
|
|
81
|
-
/** The options of a point cloud (Manim's keyword arguments). */
|
|
82
|
-
export interface PMobjectOptions {
|
|
83
|
-
/** The size of a point, in pixels of the 854×480 frame (default 4). */
|
|
84
|
-
strokeWidth?: number;
|
|
85
|
-
/** The colour of new points (default white). */
|
|
86
|
-
color?: ParsableManimColor;
|
|
87
|
-
}
|
|
88
|
-
/** An empty point cloud (Manim `PMobject`): add points with `addPoints`. */
|
|
89
|
-
export declare function PMobject(opts?: PMobjectOptions): PMobjectMobject;
|
|
90
|
-
/** A point cloud of lines (Manim `Mobject1D`): `addLine` puts `density` points on each unit. */
|
|
91
|
-
export declare class Mobject1DMobject extends PMobjectMobject {
|
|
92
|
-
density: number;
|
|
93
|
-
get epsilon(): number;
|
|
94
|
-
copy(): Mobject1DMobject;
|
|
95
|
-
/** Adds the points of the line from `start` to `end`, `density` on each unit (Manim `add_line`). */
|
|
96
|
-
addLine(start: Point, end: Point, color?: ParsableManimColor): this;
|
|
97
|
-
}
|
|
98
|
-
/** `Mobject1D({ density })` (Manim; default density 10). */
|
|
99
|
-
export declare function Mobject1D(opts?: PMobjectOptions & {
|
|
100
|
-
density?: number;
|
|
101
|
-
}): Mobject1DMobject;
|
|
102
|
-
/** A point cloud of areas (Manim `Mobject2D`). */
|
|
103
|
-
export declare class Mobject2DMobject extends PMobjectMobject {
|
|
104
|
-
density: number;
|
|
105
|
-
copy(): Mobject2DMobject;
|
|
106
|
-
get epsilon(): number;
|
|
107
|
-
}
|
|
108
|
-
/** `Mobject2D({ density })` (Manim; default density 25). */
|
|
109
|
-
export declare function Mobject2D(opts?: PMobjectOptions & {
|
|
110
|
-
density?: number;
|
|
111
|
-
}): Mobject2DMobject;
|
|
112
|
-
/** Point clouds as one (Manim `PGroup`): `PGroup(cloud1, cloud2, opts)`. */
|
|
113
|
-
export declare function PGroup(...args: (PMobjectMobject | PMobjectOptions)[]): PMobjectMobject;
|
|
114
|
-
/** A disc of points (Manim `PointCloudDot`): rings every `1 / density` up to `radius`. */
|
|
115
|
-
export declare class PointCloudDotMobject extends Mobject1DMobject {
|
|
116
|
-
#private;
|
|
117
|
-
radius: number;
|
|
118
|
-
copy(): PointCloudDotMobject;
|
|
119
|
-
/** Makes the points again (Manim `init_points`). */
|
|
120
|
-
initPoints(): this;
|
|
121
|
-
/** Adds the rings of points about the centre (Manim `generate_points`). */
|
|
122
|
-
generatePoints(): this;
|
|
123
|
-
/** The centre for `generatePoints`. */
|
|
124
|
-
setGenerationCenter(center: Point): this;
|
|
125
|
-
}
|
|
126
|
-
/** `PointCloudDot({ center, radius, strokeWidth, density, color })` (Manim; defaults
|
|
127
|
-
* `ORIGIN`, 2, 2, 10 and `PURE_YELLOW`). */
|
|
128
|
-
export declare function PointCloudDot(opts?: PMobjectOptions & {
|
|
129
|
-
center?: Point;
|
|
130
|
-
radius?: number;
|
|
131
|
-
density?: number;
|
|
132
|
-
}): PointCloudDotMobject;
|
|
133
|
-
/** A cloud of one point (Manim `Point`). */
|
|
134
|
-
export declare class PointMobject extends PMobjectMobject {
|
|
135
|
-
location: Point;
|
|
136
|
-
copy(): PointMobject;
|
|
137
|
-
/** Makes the point again (Manim `init_points`). */
|
|
138
|
-
initPoints(): this;
|
|
139
|
-
/** Adds the point at `location` (Manim `generate_points`). */
|
|
140
|
-
generatePoints(): this;
|
|
141
|
-
}
|
|
142
|
-
/** `Point(location, { color })` (Manim; defaults `ORIGIN` and `BLACK`). */
|
|
143
|
-
export declare function Point(location?: Point, opts?: PMobjectOptions): PointMobject;
|
|
144
|
-
export {};
|
package/dist/pointcloud.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
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. The frame draws
|
|
3
|
-
// it as Manim's camera draws a point: a block of whole pixels (the engine's `point-squares`).
|
|
4
|
-
// The points of one colour run are the subpaths of one node, so a cloud of thousands of
|
|
5
|
-
// points is a few nodes. The points and their colours are read back from
|
|
6
|
-
// the nodes, so every Mobject method and animation keeps them right.
|
|
7
|
-
import { BLACK, FRAME_WIDTH, ORIGIN, PIXEL_WIDTH, PURE_YELLOW, TAU, WHITE, Mobject, add, mul, norm, raw, sub, wrong, wrap, } from "./engine.js";
|
|
8
|
-
import { colorGradient, colorToRgba, rgbaToColor } from "./colors.js";
|
|
9
|
-
import { engine } from "./load.js";
|
|
10
|
-
/** Frame units of one pixel of the frame. */
|
|
11
|
-
const PIXEL = FRAME_WIDTH / PIXEL_WIDTH;
|
|
12
|
-
/** The points of a node of squares (the centres of its square subpaths), and their side. */
|
|
13
|
-
function squareCentres(node) {
|
|
14
|
-
const p = node.getPoints();
|
|
15
|
-
const points = [];
|
|
16
|
-
let side = 0;
|
|
17
|
-
for (let i = 0; i + 15 < p.length; i += 16) {
|
|
18
|
-
const a = p[i] ?? ORIGIN;
|
|
19
|
-
const c = p[i + 8] ?? ORIGIN;
|
|
20
|
-
points.push([(a[0] + c[0]) / 2, (a[1] + c[1]) / 2]);
|
|
21
|
-
side = norm(sub(p[i + 4] ?? a, a));
|
|
22
|
-
}
|
|
23
|
-
return { points, side };
|
|
24
|
-
}
|
|
25
|
-
function sameRgba(a, b) {
|
|
26
|
-
return a.every((v, i) => Math.abs(v - (b[i] ?? 0)) < 1e-9);
|
|
27
|
-
}
|
|
28
|
-
function lerpRgba(a, b, t) {
|
|
29
|
-
const at = (i) => a[i] + (b[i] - a[i]) * t;
|
|
30
|
-
return [at(0), at(1), at(2), at(3)];
|
|
31
|
-
}
|
|
32
|
-
/** NumPy's `arange(start, stop, step)`. */
|
|
33
|
-
function arange(start, stop, step) {
|
|
34
|
-
const n = Math.max(0, Math.ceil((stop - start) / step));
|
|
35
|
-
return Array.from({ length: n }, (_, i) => start + i * step);
|
|
36
|
-
}
|
|
37
|
-
/** A cloud of points: Manim's `PMobject`. Its submobjects are the colour runs of its own
|
|
38
|
-
* points (the nodes of the squares), then the clouds that `add` gives it. */
|
|
39
|
-
export class PMobjectMobject extends Mobject {
|
|
40
|
-
#strokeWidth = 4;
|
|
41
|
-
/** The colour of new points (Manim `color`). */
|
|
42
|
-
color = WHITE;
|
|
43
|
-
copy() {
|
|
44
|
-
return this.copyCloud(new PMobjectMobject(raw(this).copy()));
|
|
45
|
-
}
|
|
46
|
-
/** Gives `to`, a copy of the node, the settings of this cloud. */
|
|
47
|
-
copyCloud(to) {
|
|
48
|
-
to.#strokeWidth = this.#strokeWidth;
|
|
49
|
-
to.color = this.color;
|
|
50
|
-
return to;
|
|
51
|
-
}
|
|
52
|
-
/** The own points, in order. */
|
|
53
|
-
#points() {
|
|
54
|
-
return this.#runs().flatMap((r) => squareCentres(r).points);
|
|
55
|
-
}
|
|
56
|
-
/** The own colour of each own point. */
|
|
57
|
-
#rgbas() {
|
|
58
|
-
return this.#runs().flatMap((r) => {
|
|
59
|
-
const rgba = colorToRgba(r.getFillColor(), r.getFillOpacity());
|
|
60
|
-
return squareCentres(r).points.map(() => rgba);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/** The nodes of the own points: the submobjects with points and no submobjects. */
|
|
64
|
-
#runs() {
|
|
65
|
-
return this.submobjects.filter((s) => s.submobjects.length === 0 && s.hasPoints());
|
|
66
|
-
}
|
|
67
|
-
/** Draws the own points again: one node for each run of one colour, before the sub-clouds. */
|
|
68
|
-
#draw(points, rgbas) {
|
|
69
|
-
const others = this.submobjects.filter((s) => !this.#runs().includes(s));
|
|
70
|
-
this.remove(...this.submobjects);
|
|
71
|
-
const side = this.#strokeWidth * PIXEL;
|
|
72
|
-
let start = 0;
|
|
73
|
-
for (let i = 1; i <= points.length; i++) {
|
|
74
|
-
const a = rgbas[start] ?? [1, 1, 1, 1];
|
|
75
|
-
if (i < points.length && sameRgba(a, rgbas[i] ?? a))
|
|
76
|
-
continue;
|
|
77
|
-
const run = wrap(engine.pointSquares(points.slice(start, i), side));
|
|
78
|
-
run.setFill(rgbaToColor(a), { opacity: a[3] }).setStroke({ width: 0 });
|
|
79
|
-
this.add(run);
|
|
80
|
-
start = i;
|
|
81
|
-
}
|
|
82
|
-
return this.add(...others);
|
|
83
|
-
}
|
|
84
|
-
/** Removes the own points (Manim `reset_points`). */
|
|
85
|
-
resetPoints() {
|
|
86
|
-
return this.#draw([], []);
|
|
87
|
-
}
|
|
88
|
-
/** The names of the arrays of a point cloud (Manim `get_array_attrs`). */
|
|
89
|
-
getArrayAttrs() {
|
|
90
|
-
return ["points", "rgbas"];
|
|
91
|
-
}
|
|
92
|
-
/** Adds points, in `color` with opacity `alpha`, or one `[r, g, b, a]` each (Manim `add_points`). */
|
|
93
|
-
addPoints(points, opts = {}) {
|
|
94
|
-
const { rgbas, color, alpha = 1 } = opts;
|
|
95
|
-
if (rgbas !== undefined && rgbas.length !== points.length) {
|
|
96
|
-
wrong("addPoints", "points and rgbas must have the same length");
|
|
97
|
-
}
|
|
98
|
-
const rgba = colorToRgba(color ?? this.color, alpha);
|
|
99
|
-
const added = rgbas === undefined
|
|
100
|
-
? points.map(() => rgba)
|
|
101
|
-
: rgbas.map((c) => [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0, c[3] ?? 1]);
|
|
102
|
-
return this.#draw([...this.#points(), ...points], [...this.#rgbas(), ...added]);
|
|
103
|
-
}
|
|
104
|
-
/** Gives every point `color` (Manim `set_color`); with `family` (true) also the sub-clouds. */
|
|
105
|
-
setColor(color = PURE_YELLOW, opts = {}) {
|
|
106
|
-
const { alpha = 1, family = true } = opts;
|
|
107
|
-
const rgba = colorToRgba(color, alpha);
|
|
108
|
-
for (const cloud of family ? clouds(this) : [this]) {
|
|
109
|
-
cloud.#draw(cloud.#points(), cloud.#points().map(() => rgba));
|
|
110
|
-
cloud.color = rgbaToColor(rgba);
|
|
111
|
-
}
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
/** The size of a point, in pixels of the 854×480 frame. */
|
|
115
|
-
getStrokeWidth() {
|
|
116
|
-
return this.#strokeWidth;
|
|
117
|
-
}
|
|
118
|
-
/** Sets the size of the points (Manim `set_stroke_width`); with `family` (true) also of the
|
|
119
|
-
* sub-clouds. */
|
|
120
|
-
setStrokeWidth(width, family = true) {
|
|
121
|
-
for (const cloud of family ? clouds(this) : [this]) {
|
|
122
|
-
cloud.#strokeWidth = width;
|
|
123
|
-
cloud.#draw(cloud.#points(), cloud.#rgbas());
|
|
124
|
-
}
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
/** Spreads `colors` over the points in order (Manim `set_color_by_gradient`). */
|
|
128
|
-
setColorByGradient(...colors) {
|
|
129
|
-
const points = this.#points();
|
|
130
|
-
return this.#draw(points, colorGradient(colors, points.length).map((c) => colorToRgba(c)));
|
|
131
|
-
}
|
|
132
|
-
/** Colours the points from `innerColor` at `center` to `outerColor` at `radius` (Manim
|
|
133
|
-
* `set_colors_by_radial_gradient`). */
|
|
134
|
-
setColorsByRadialGradient(opts = {}) {
|
|
135
|
-
const { center = this.getCenter(), radius = 1, innerColor = WHITE, outerColor = BLACK } = opts;
|
|
136
|
-
const [a, b] = [colorToRgba(innerColor), colorToRgba(outerColor)];
|
|
137
|
-
for (const cloud of clouds(this)) {
|
|
138
|
-
const points = cloud.#points();
|
|
139
|
-
cloud.#draw(points, points.map((p) => lerpRgba(a, b, norm(sub(p, center)) / radius)));
|
|
140
|
-
}
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
/** Takes the colours of the points of `mobject`, in order (Manim `match_colors`). */
|
|
144
|
-
matchColors(mobject) {
|
|
145
|
-
const other = mobject instanceof PMobjectMobject ? mobject.#rgbas() : [];
|
|
146
|
-
const points = this.#points();
|
|
147
|
-
return this.#draw(points, points.map((_, i) => other[Math.min(i, other.length - 1)] ?? colorToRgba(this.color)));
|
|
148
|
-
}
|
|
149
|
-
/** Removes the points where `condition` is true (Manim `filter_out`). */
|
|
150
|
-
filterOut(condition) {
|
|
151
|
-
for (const cloud of clouds(this)) {
|
|
152
|
-
const [points, rgbas] = [cloud.#points(), cloud.#rgbas()];
|
|
153
|
-
const keep = points.map((p) => !condition(p));
|
|
154
|
-
cloud.#draw(points.filter((_, i) => keep[i]), rgbas.filter((_, i) => keep[i]));
|
|
155
|
-
}
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
/** Keeps every `factor`-th point (Manim `thin_out`). */
|
|
159
|
-
thinOut(factor = 5) {
|
|
160
|
-
for (const cloud of clouds(this)) {
|
|
161
|
-
const [points, rgbas] = [cloud.#points(), cloud.#rgbas()];
|
|
162
|
-
cloud.#draw(points.filter((_, i) => i % factor === 0), rgbas.filter((_, i) => i % factor === 0));
|
|
163
|
-
}
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
/** Orders the points by `f` (Manim `sort_points`; by x by default). */
|
|
167
|
-
sortPoints(f = (p) => p[0]) {
|
|
168
|
-
for (const cloud of clouds(this)) {
|
|
169
|
-
const [points, rgbas] = [cloud.#points(), cloud.#rgbas()];
|
|
170
|
-
const order = points.map((p, i) => [f(p), i]).toSorted((a, b) => a[0] - b[0]);
|
|
171
|
-
cloud.#draw(order.map(([, i]) => points[i] ?? ORIGIN), order.map(([, i]) => rgbas[i] ?? [1, 1, 1, 1]));
|
|
172
|
-
}
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
/** Moves the colours `alpha` of the way to `color` (Manim `fade_to`). */
|
|
176
|
-
fadeTo(color, alpha, opts = {}) {
|
|
177
|
-
const target = colorToRgba(color);
|
|
178
|
-
this.#draw(this.#points(), this.#rgbas().map((c) => lerpRgba(c, target, alpha)));
|
|
179
|
-
for (const child of this.submobjects)
|
|
180
|
-
if (child instanceof PMobjectMobject)
|
|
181
|
-
child.fadeTo(color, alpha, opts);
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
/** The colours of the points of the cloud and its sub-clouds (Manim `get_all_rgbas`). */
|
|
185
|
-
getAllRgbas() {
|
|
186
|
-
return clouds(this).flatMap((c) => c.#rgbas());
|
|
187
|
-
}
|
|
188
|
-
/** Takes the points of the sub-clouds as its own, and removes the sub-clouds (Manim
|
|
189
|
-
* `ingest_submobjects`). */
|
|
190
|
-
ingestSubmobjects() {
|
|
191
|
-
const all = clouds(this);
|
|
192
|
-
const points = all.flatMap((c) => c.#points());
|
|
193
|
-
const rgbas = all.flatMap((c) => c.#rgbas());
|
|
194
|
-
this.remove(...this.submobjects);
|
|
195
|
-
return this.#draw(points, rgbas);
|
|
196
|
-
}
|
|
197
|
-
/** The colour of the first point (Manim `get_color`). */
|
|
198
|
-
getColor() {
|
|
199
|
-
const first = this.getAllRgbas()[0];
|
|
200
|
-
return first === undefined ? this.color : rgbaToColor(first);
|
|
201
|
-
}
|
|
202
|
-
/** The point at `alpha` of the list of points (Manim `point_from_proportion`). */
|
|
203
|
-
pointFromProportion(alpha) {
|
|
204
|
-
const points = clouds(this).flatMap((c) => c.#points());
|
|
205
|
-
return points[Math.floor(alpha * (points.length - 1))] ?? this.getCenter();
|
|
206
|
-
}
|
|
207
|
-
/** `m.PMobject` (Manim `get_mobject_type_class`). */
|
|
208
|
-
getMobjectTypeClass() {
|
|
209
|
-
return PMobject;
|
|
210
|
-
}
|
|
211
|
-
/** Repeats points until the cloud has as many as `largerMobject` (Manim
|
|
212
|
-
* `align_points_with_larger`). */
|
|
213
|
-
alignPointsWithLarger(largerMobject) {
|
|
214
|
-
const n = largerMobject instanceof PMobjectMobject ? largerMobject.#points().length : 0;
|
|
215
|
-
const [points, rgbas] = [this.#points(), this.#rgbas()];
|
|
216
|
-
if (points.length === 0 || n <= points.length)
|
|
217
|
-
return this;
|
|
218
|
-
const at = (i) => Math.floor((i * points.length) / n);
|
|
219
|
-
return this.#draw(Array.from({ length: n }, (_, i) => points[at(i)] ?? ORIGIN), Array.from({ length: n }, (_, i) => rgbas[at(i)] ?? [1, 1, 1, 1]));
|
|
220
|
-
}
|
|
221
|
-
/** A one-point cloud at `center` (Manim `get_point_mobject`). */
|
|
222
|
-
getPointMobject(center) {
|
|
223
|
-
return Point(center ?? this.getCenter());
|
|
224
|
-
}
|
|
225
|
-
/** Takes colours and point size `alpha` of the way from `mobject1` to `mobject2` (Manim
|
|
226
|
-
* `interpolate_color`). */
|
|
227
|
-
interpolateColor(mobject1, mobject2, alpha) {
|
|
228
|
-
const a = mobject1 instanceof PMobjectMobject ? mobject1.#rgbas() : [];
|
|
229
|
-
const b = mobject2 instanceof PMobjectMobject ? mobject2.#rgbas() : [];
|
|
230
|
-
const points = this.#points();
|
|
231
|
-
const white = [1, 1, 1, 1];
|
|
232
|
-
const rgbas = points.map((_, i) => lerpRgba(a[i] ?? white, b[i] ?? white, alpha));
|
|
233
|
-
const w1 = mobject1 instanceof PMobjectMobject ? mobject1.#strokeWidth : this.#strokeWidth;
|
|
234
|
-
const w2 = mobject2 instanceof PMobjectMobject ? mobject2.#strokeWidth : this.#strokeWidth;
|
|
235
|
-
this.#strokeWidth = w1 + (w2 - w1) * alpha;
|
|
236
|
-
return this.#draw(points, rgbas);
|
|
237
|
-
}
|
|
238
|
-
/** Becomes the points of `mobject` from proportion `a` to `b` (Manim
|
|
239
|
-
* `pointwise_become_partial`). */
|
|
240
|
-
pointwiseBecomePartial(mobject, a, b) {
|
|
241
|
-
if (!(mobject instanceof PMobjectMobject))
|
|
242
|
-
return this;
|
|
243
|
-
const [points, rgbas] = [mobject.#points(), mobject.#rgbas()];
|
|
244
|
-
const [lo, hi] = [Math.floor(a * points.length), Math.floor(b * points.length)];
|
|
245
|
-
return this.#draw(points.slice(lo, hi), rgbas.slice(lo, hi));
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/** The cloud and every cloud inside it. */
|
|
249
|
-
function clouds(m) {
|
|
250
|
-
return m.getFamily().filter((x) => x instanceof PMobjectMobject);
|
|
251
|
-
}
|
|
252
|
-
function makeCloud(make, opts, width) {
|
|
253
|
-
const c = make(engine.vGroup([]));
|
|
254
|
-
c.color = opts.color === undefined ? WHITE : rgbaToColor(colorToRgba(opts.color));
|
|
255
|
-
return c.setStrokeWidth(opts.strokeWidth ?? width, false);
|
|
256
|
-
}
|
|
257
|
-
/** An empty point cloud (Manim `PMobject`): add points with `addPoints`. */
|
|
258
|
-
export function PMobject(opts = {}) {
|
|
259
|
-
return makeCloud((h) => new PMobjectMobject(h), opts, 4);
|
|
260
|
-
}
|
|
261
|
-
/** A point cloud of lines (Manim `Mobject1D`): `addLine` puts `density` points on each unit. */
|
|
262
|
-
export class Mobject1DMobject extends PMobjectMobject {
|
|
263
|
-
density = 10;
|
|
264
|
-
get epsilon() {
|
|
265
|
-
return 1 / this.density;
|
|
266
|
-
}
|
|
267
|
-
copy() {
|
|
268
|
-
const d = this.copyCloud(new Mobject1DMobject(raw(this).copy()));
|
|
269
|
-
d.density = this.density;
|
|
270
|
-
return d;
|
|
271
|
-
}
|
|
272
|
-
/** Adds the points of the line from `start` to `end`, `density` on each unit (Manim `add_line`). */
|
|
273
|
-
addLine(start, end, color) {
|
|
274
|
-
const length = norm(sub(end, start));
|
|
275
|
-
const points = length === 0
|
|
276
|
-
? [start]
|
|
277
|
-
: arange(0, 1, this.epsilon / length).map((t) => add(start, mul(sub(end, start), t)));
|
|
278
|
-
return this.addPoints(points, color === undefined ? {} : { color });
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/** `Mobject1D({ density })` (Manim; default density 10). */
|
|
282
|
-
export function Mobject1D(opts = {}) {
|
|
283
|
-
const { density = 10, ...rest } = opts;
|
|
284
|
-
const c = makeCloud((h) => new Mobject1DMobject(h), rest, 4);
|
|
285
|
-
c.density = density;
|
|
286
|
-
return c;
|
|
287
|
-
}
|
|
288
|
-
/** A point cloud of areas (Manim `Mobject2D`). */
|
|
289
|
-
export class Mobject2DMobject extends PMobjectMobject {
|
|
290
|
-
density = 25;
|
|
291
|
-
copy() {
|
|
292
|
-
const d = this.copyCloud(new Mobject2DMobject(raw(this).copy()));
|
|
293
|
-
d.density = this.density;
|
|
294
|
-
return d;
|
|
295
|
-
}
|
|
296
|
-
get epsilon() {
|
|
297
|
-
return 1 / this.density;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
/** `Mobject2D({ density })` (Manim; default density 25). */
|
|
301
|
-
export function Mobject2D(opts = {}) {
|
|
302
|
-
const { density = 25, ...rest } = opts;
|
|
303
|
-
const c = makeCloud((h) => new Mobject2DMobject(h), rest, 4);
|
|
304
|
-
c.density = density;
|
|
305
|
-
return c;
|
|
306
|
-
}
|
|
307
|
-
/** Point clouds as one (Manim `PGroup`): `PGroup(cloud1, cloud2, opts)`. */
|
|
308
|
-
export function PGroup(...args) {
|
|
309
|
-
const pmobs = args.filter((a) => a instanceof Mobject);
|
|
310
|
-
const opts = args.find((a) => !(a instanceof Mobject)) ?? {};
|
|
311
|
-
for (const p of pmobs) {
|
|
312
|
-
if (!(p instanceof PMobjectMobject))
|
|
313
|
-
wrong("PGroup", "all submobjects must be point clouds (PMobject)");
|
|
314
|
-
}
|
|
315
|
-
return makeCloud((h) => new PMobjectMobject(h), opts, 4).add(...pmobs);
|
|
316
|
-
}
|
|
317
|
-
/** A disc of points (Manim `PointCloudDot`): rings every `1 / density` up to `radius`. */
|
|
318
|
-
export class PointCloudDotMobject extends Mobject1DMobject {
|
|
319
|
-
radius = 2;
|
|
320
|
-
#center = ORIGIN;
|
|
321
|
-
copy() {
|
|
322
|
-
const d = this.copyCloud(new PointCloudDotMobject(raw(this).copy()));
|
|
323
|
-
d.density = this.density;
|
|
324
|
-
d.radius = this.radius;
|
|
325
|
-
d.#center = this.#center;
|
|
326
|
-
return d;
|
|
327
|
-
}
|
|
328
|
-
/** Makes the points again (Manim `init_points`). */
|
|
329
|
-
initPoints() {
|
|
330
|
-
this.resetPoints();
|
|
331
|
-
return this.generatePoints();
|
|
332
|
-
}
|
|
333
|
-
/** Adds the rings of points about the centre (Manim `generate_points`). */
|
|
334
|
-
generatePoints() {
|
|
335
|
-
const e = this.epsilon;
|
|
336
|
-
const points = arange(e, this.radius, e).flatMap((r) => {
|
|
337
|
-
const n = Math.floor((TAU * (r + e)) / e);
|
|
338
|
-
return Array.from({ length: n }, (_, k) => {
|
|
339
|
-
const theta = n === 1 ? 0 : (TAU * k) / (n - 1);
|
|
340
|
-
return add(this.#center, [r * Math.cos(theta), r * Math.sin(theta)]);
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
return this.addPoints(points);
|
|
344
|
-
}
|
|
345
|
-
/** The centre for `generatePoints`. */
|
|
346
|
-
setGenerationCenter(center) {
|
|
347
|
-
this.#center = center;
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
/** `PointCloudDot({ center, radius, strokeWidth, density, color })` (Manim; defaults
|
|
352
|
-
* `ORIGIN`, 2, 2, 10 and `PURE_YELLOW`). */
|
|
353
|
-
export function PointCloudDot(opts = {}) {
|
|
354
|
-
const { center = ORIGIN, radius = 2, density = 10, color = PURE_YELLOW, strokeWidth = 2 } = opts;
|
|
355
|
-
const c = makeCloud((h) => new PointCloudDotMobject(h), { color, strokeWidth }, 2);
|
|
356
|
-
c.density = density;
|
|
357
|
-
c.radius = radius;
|
|
358
|
-
return c.initPoints().shift(center);
|
|
359
|
-
}
|
|
360
|
-
/** A cloud of one point (Manim `Point`). */
|
|
361
|
-
export class PointMobject extends PMobjectMobject {
|
|
362
|
-
location = ORIGIN;
|
|
363
|
-
copy() {
|
|
364
|
-
const d = this.copyCloud(new PointMobject(raw(this).copy()));
|
|
365
|
-
d.location = this.location;
|
|
366
|
-
return d;
|
|
367
|
-
}
|
|
368
|
-
/** Makes the point again (Manim `init_points`). */
|
|
369
|
-
initPoints() {
|
|
370
|
-
this.resetPoints();
|
|
371
|
-
return this.generatePoints();
|
|
372
|
-
}
|
|
373
|
-
/** Adds the point at `location` (Manim `generate_points`). */
|
|
374
|
-
generatePoints() {
|
|
375
|
-
return this.addPoints([this.location]);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
/** `Point(location, { color })` (Manim; defaults `ORIGIN` and `BLACK`). */
|
|
379
|
-
export function Point(location = ORIGIN, opts = {}) {
|
|
380
|
-
const { color = BLACK, ...rest } = opts;
|
|
381
|
-
const p = makeCloud((h) => new PointMobject(h), { color, ...rest }, 4);
|
|
382
|
-
p.location = location;
|
|
383
|
-
return p.initPoints();
|
|
384
|
-
}
|
package/dist/rates.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
}
|