@wonderyard/vivarium 1.0.0 → 1.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 +1 -1
- package/dist/blueprint/ref-blueprint.d.ts +2 -1
- package/dist/blueprint/ref-blueprint.js +15 -14
- package/dist/blueprint/vivarium-blueprint.js +12 -12
- package/dist/main.d.ts +4 -4
- package/dist/main.js +15 -15
- package/dist/webgpu/setup.d.ts +6 -2
- package/dist/webgpu/setup.js +1869 -1859
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,8 @@ export declare class ElementBlueprint extends RefBlueprint {
|
|
|
27
27
|
protected context: BlueprintContext;
|
|
28
28
|
type: "element";
|
|
29
29
|
id: string;
|
|
30
|
-
|
|
30
|
+
index: number;
|
|
31
|
+
constructor(context: BlueprintContext, automaton: Automaton, element: Element, index: number);
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Blueprint for a kind. Returned by {@link VivariumBlueprint.kind | vivarium().kind()}.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BaseBlueprint as
|
|
2
|
-
import { R as
|
|
3
|
-
import { toRefIdOrPoint as
|
|
1
|
+
import { BaseBlueprint as n } from "./base-blueprint.js";
|
|
2
|
+
import { R as p } from "../rule-blueprint-DGODv9IV.js";
|
|
3
|
+
import { toRefIdOrPoint as d } from "./utils.js";
|
|
4
4
|
import { A as u } from "../constants-D4GX9YB2.js";
|
|
5
|
-
class o extends
|
|
5
|
+
class o extends n {
|
|
6
6
|
constructor(e, t) {
|
|
7
7
|
super(), this.automaton = e, this.id = t.id, this.name = t.name, this.type = t.type;
|
|
8
8
|
}
|
|
@@ -20,29 +20,30 @@ class o extends r {
|
|
|
20
20
|
const t = {
|
|
21
21
|
fromId: this.id,
|
|
22
22
|
fromType: this.type,
|
|
23
|
-
to:
|
|
23
|
+
to: d(e),
|
|
24
24
|
when: [],
|
|
25
25
|
accept: u.ALL
|
|
26
26
|
};
|
|
27
|
-
return this.automaton.rules.push(t), new
|
|
27
|
+
return this.automaton.rules.push(t), new p(this.context, this.automaton, t);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
class
|
|
31
|
-
constructor(e, t,
|
|
32
|
-
super(t,
|
|
30
|
+
class l extends o {
|
|
31
|
+
constructor(e, t, i, r) {
|
|
32
|
+
super(t, i), this.context = e, this.id = i.id, this.index = r;
|
|
33
33
|
}
|
|
34
34
|
type = "element";
|
|
35
35
|
id;
|
|
36
|
+
index;
|
|
36
37
|
}
|
|
37
|
-
class
|
|
38
|
-
constructor(e, t,
|
|
39
|
-
super(t,
|
|
38
|
+
class x extends o {
|
|
39
|
+
constructor(e, t, i) {
|
|
40
|
+
super(t, i), this.context = e, this.id = i.id;
|
|
40
41
|
}
|
|
41
42
|
type = "kind";
|
|
42
43
|
id;
|
|
43
44
|
}
|
|
44
45
|
export {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
l as ElementBlueprint,
|
|
47
|
+
x as KindBlueprint,
|
|
47
48
|
o as RefBlueprint
|
|
48
49
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { n as o } from "../rule-blueprint-DGODv9IV.js";
|
|
2
|
-
import { BaseBlueprint as
|
|
3
|
-
import { Helpers as
|
|
4
|
-
import { ElementBlueprint as
|
|
5
|
-
import { C as
|
|
6
|
-
class
|
|
2
|
+
import { BaseBlueprint as a } from "./base-blueprint.js";
|
|
3
|
+
import { Helpers as h } from "./helpers.js";
|
|
4
|
+
import { ElementBlueprint as m, KindBlueprint as u } from "./ref-blueprint.js";
|
|
5
|
+
import { C as d, S as p } from "../constants-D4GX9YB2.js";
|
|
6
|
+
class b extends a {
|
|
7
7
|
constructor(t) {
|
|
8
|
-
super(), this.neighborhoodName = t, this.helpers = new
|
|
8
|
+
super(), this.neighborhoodName = t, this.helpers = new h(this.neighborhoodName), this.neighbor = this.neighborhoodName === "cross" ? d : p, this.automaton = {
|
|
9
9
|
neighborhood: t ?? "square",
|
|
10
10
|
elements: [],
|
|
11
11
|
kinds: [],
|
|
@@ -36,16 +36,16 @@ class C extends n {
|
|
|
36
36
|
* @param extensions - An optional array of kinds this element extends.
|
|
37
37
|
* @returns An {@link ElementBlueprint} that can be used to define rules.
|
|
38
38
|
*/
|
|
39
|
-
element(t, e,
|
|
39
|
+
element(t, e, i = []) {
|
|
40
40
|
this.assertNotCreated(), this.assertUniqueName(t), this.assertUniqueColor(e);
|
|
41
41
|
const s = {
|
|
42
42
|
type: "element",
|
|
43
43
|
id: o(),
|
|
44
44
|
name: t,
|
|
45
45
|
color: e,
|
|
46
|
-
extensions:
|
|
47
|
-
};
|
|
48
|
-
return
|
|
46
|
+
extensions: i.map((r) => r.id)
|
|
47
|
+
}, n = this.automaton.elements.push(s) - 1;
|
|
48
|
+
return new m(this.context, this.automaton, s, n);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Defines a new kind in the vivarium. A kind groups elements that share common behavior.
|
|
@@ -60,7 +60,7 @@ class C extends n {
|
|
|
60
60
|
id: o(),
|
|
61
61
|
name: t
|
|
62
62
|
};
|
|
63
|
-
return this.automaton.kinds.push(e), new
|
|
63
|
+
return this.automaton.kinds.push(e), new u(this.context, this.automaton, e);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Finalizes the vivarium and produces an {@link Automaton} object. After calling this method,
|
|
@@ -75,5 +75,5 @@ class C extends n {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
export {
|
|
78
|
-
|
|
78
|
+
b as VivariumBlueprint
|
|
79
79
|
};
|
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export { Helpers } from './blueprint/helpers';
|
|
2
|
+
export { ElementBlueprint, KindBlueprint, RefBlueprint, } from './blueprint/ref-blueprint';
|
|
3
|
+
export { RuleBlueprint, RuleBlueprintWithAccept, } from './blueprint/rule-blueprint';
|
|
4
|
+
export { VivariumBlueprint } from './blueprint/vivarium-blueprint';
|
|
1
5
|
export { vivarium } from './vivarium/vivarium';
|
|
2
6
|
export { setup } from './webgpu/setup';
|
|
3
|
-
export { VivariumBlueprint } from './blueprint/vivarium-blueprint';
|
|
4
|
-
export { RefBlueprint, ElementBlueprint, KindBlueprint, } from './blueprint/ref-blueprint';
|
|
5
|
-
export { RuleBlueprint, RuleBlueprintWithAccept, } from './blueprint/rule-blueprint';
|
|
6
|
-
export { Helpers } from './blueprint/helpers';
|
package/dist/main.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { Helpers as t } from "./blueprint/helpers.js";
|
|
2
|
+
import { ElementBlueprint as i, KindBlueprint as o, RefBlueprint as u } from "./blueprint/ref-blueprint.js";
|
|
3
|
+
import { R as m, a as n } from "./rule-blueprint-DGODv9IV.js";
|
|
4
|
+
import { VivariumBlueprint as x } from "./blueprint/vivarium-blueprint.js";
|
|
5
|
+
import { vivarium as a } from "./vivarium/vivarium.js";
|
|
6
|
+
import { setup as R } from "./webgpu/setup.js";
|
|
7
7
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
i as ElementBlueprint,
|
|
9
|
+
t as Helpers,
|
|
10
|
+
o as KindBlueprint,
|
|
11
|
+
u as RefBlueprint,
|
|
12
|
+
m as RuleBlueprint,
|
|
13
|
+
n as RuleBlueprintWithAccept,
|
|
14
|
+
x as VivariumBlueprint,
|
|
15
|
+
R as setup,
|
|
16
|
+
a as vivarium
|
|
17
17
|
};
|
package/dist/webgpu/setup.d.ts
CHANGED
|
@@ -63,16 +63,20 @@ export declare const mainCompute: import('typegpu').TgpuComputeFn<{
|
|
|
63
63
|
}>;
|
|
64
64
|
/**
|
|
65
65
|
* Initializes the WebGPU simulation for a given canvas and automaton. The grid is randomly initialized
|
|
66
|
-
* with the defined elements.
|
|
66
|
+
* with the defined elements unless an `initialGrid` is provided.
|
|
67
|
+
*
|
|
68
|
+
* Use `index` found in `ElementBlueprint` instances to reference elements when building the initialGrid.
|
|
67
69
|
*
|
|
68
70
|
* @param options - An object containing the `canvas` element and the compiled `automaton`.
|
|
69
71
|
* @param options.canvas - The HTML canvas element. Its `width` and `height` define the grid dimensions.
|
|
70
72
|
* @param options.automaton - The compiled automaton produced by {@link VivariumBlueprint.create | vivarium().create()}.
|
|
73
|
+
* @param options.initialGrid - An optional 2d array of element indices to use instead of random initialization. Alternatively, you can pass a flat (1d) array with one index per cell, row-major order.
|
|
71
74
|
* @returns An object with an `evolve` function that advances the simulation by one step, a `setAutomaton` function to update the automaton, and the underlying `tgpuRoot`.
|
|
72
75
|
*/
|
|
73
|
-
export declare const setup: ({ canvas, automaton, }: {
|
|
76
|
+
export declare const setup: ({ canvas, automaton, initialGrid, }: {
|
|
74
77
|
canvas: HTMLCanvasElement;
|
|
75
78
|
automaton: Automaton;
|
|
79
|
+
initialGrid?: number[] | number[][];
|
|
76
80
|
}) => {
|
|
77
81
|
evolve: () => Promise<void>;
|
|
78
82
|
setAutomaton: ({ automaton }: {
|