@wonderyard/vivarium 1.4.1 → 2.0.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 -3
- package/dist/automaton/types.d.ts +1 -0
- package/dist/blueprint/base-blueprint.js +1 -3
- package/dist/blueprint/ref-blueprint.js +2 -2
- package/dist/blueprint/rule-blueprint.js +2 -2
- package/dist/blueprint/utils.js +1 -1
- package/dist/blueprint/vivarium-blueprint.d.ts +3 -1
- package/dist/blueprint/vivarium-blueprint.js +7 -6
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +7 -6
- package/dist/common/utils.js +2 -2
- package/dist/constants-BT-9-x_4.js +3289 -0
- package/dist/main.d.ts +2 -2
- package/dist/main.js +1 -1
- package/dist/{rule-blueprint-DGODv9IV.js → rule-blueprint-C9qa6iP-.js} +1 -1
- package/dist/vivarium/vivarium.d.ts +4 -1
- package/dist/vivarium/vivarium.js +4 -4
- package/dist/webgpu/compiler.d.ts +2 -1
- package/dist/webgpu/compiler.js +37 -50
- package/dist/webgpu/setup.d.ts +5 -2
- package/dist/webgpu/setup.js +8452 -4915
- package/package.json +21 -20
- package/dist/constants-D4GX9YB2.js +0 -2301
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="128" height="128" src="docs/src/assets/glider.png" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Vivarium</h1>
|
|
2
6
|
|
|
3
7
|
<p align="center">
|
|
4
8
|
<img src="docs/banner.png" />
|
|
@@ -69,7 +73,7 @@ const life = vi.create();
|
|
|
69
73
|
const canvas = document.createElement(canvas);
|
|
70
74
|
document.body.appendChild(canvas);
|
|
71
75
|
|
|
72
|
-
// Set the canvas size. This will be the automaton size as well.
|
|
76
|
+
// Set the canvas size (must be a power of 2). This will be the automaton size as well.
|
|
73
77
|
const size = 256;
|
|
74
78
|
canvas.width = size;
|
|
75
79
|
canvas.height = size;
|
|
@@ -81,7 +85,7 @@ const { evolve } = setup({ canvas, automaton: life });
|
|
|
81
85
|
const loop = async () => {
|
|
82
86
|
await evolve();
|
|
83
87
|
requestAnimationFrame(loop);
|
|
84
|
-
}
|
|
88
|
+
};
|
|
85
89
|
requestAnimationFrame(loop);
|
|
86
90
|
```
|
|
87
91
|
|
|
@@ -92,4 +96,5 @@ requestAnimationFrame(loop);
|
|
|
92
96
|
Vivarium runs its simulation entirely on the GPU thanks to the WebGPU API and its compute shaders. WebGPU is a relatively new technology. It is available since Chrome 113, Safari 26. See implementation status in other browsers [here](https://github.com/gpuweb/gpuweb/wiki/Implementation-Status). Vivarium has been tested on Chrome 139 for macOS and Safari 26.0 for macOS, showing better performances on Chrome overall.
|
|
93
97
|
|
|
94
98
|
## Contributing
|
|
99
|
+
|
|
95
100
|
Although I've been researching and experimenting with cellular automata for years, this is my first WebGPU-based project, so it might be rough around the edges. With WebGPU I've been able to achieve something it wouldn't be possible in a browser otherwise: to build something simple, customizable, and accessible for the end user, without compromising on performance. The intent is to offer this library as a learning tool and something other people can build on top of. If you share the vision and you would like to improve this software, PRs are welcome.
|
|
@@ -19,9 +19,7 @@ class o {
|
|
|
19
19
|
}
|
|
20
20
|
assertNotEmpty() {
|
|
21
21
|
if (!this.automaton.elements.length)
|
|
22
|
-
throw new Error(
|
|
23
|
-
"No elements found in automaton, at least one element is required"
|
|
24
|
-
);
|
|
22
|
+
throw new Error("No elements found in automaton, at least one element is required");
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseBlueprint as n } from "./base-blueprint.js";
|
|
2
|
-
import { R as p } from "../rule-blueprint-
|
|
2
|
+
import { R as p } from "../rule-blueprint-C9qa6iP-.js";
|
|
3
3
|
import { toRefIdOrPoint as d } from "./utils.js";
|
|
4
|
-
import { A as u } from "../constants-
|
|
4
|
+
import { A as u } from "../constants-BT-9-x_4.js";
|
|
5
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as o, a as l } from "../rule-blueprint-
|
|
1
|
+
import { R as o, a as l } from "../rule-blueprint-C9qa6iP-.js";
|
|
2
2
|
import "./base-blueprint.js";
|
|
3
3
|
import "./utils.js";
|
|
4
|
-
import "../constants-
|
|
4
|
+
import "../constants-BT-9-x_4.js";
|
|
5
5
|
export {
|
|
6
6
|
o as RuleBlueprint,
|
|
7
7
|
l as RuleBlueprintWithAccept
|
package/dist/blueprint/utils.js
CHANGED
|
@@ -27,7 +27,9 @@ export declare class VivariumBlueprint<N extends Neighborhood = "square"> extend
|
|
|
27
27
|
* Includes {@link Helpers.not | not}, {@link Helpers.between | between}, {@link Helpers.even | even}, and {@link Helpers.odd | odd}.
|
|
28
28
|
*/
|
|
29
29
|
helpers: Helpers;
|
|
30
|
-
constructor(neighborhoodName?: N | undefined
|
|
30
|
+
constructor(neighborhoodName?: N | undefined, options?: {
|
|
31
|
+
wrapping?: boolean;
|
|
32
|
+
});
|
|
31
33
|
/**
|
|
32
34
|
* Defines a new element in the vivarium.
|
|
33
35
|
*
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { n as o } from "../rule-blueprint-
|
|
1
|
+
import { n as o } from "../rule-blueprint-C9qa6iP-.js";
|
|
2
2
|
import { BaseBlueprint as a } from "./base-blueprint.js";
|
|
3
3
|
import { Helpers as h } from "./helpers.js";
|
|
4
4
|
import { ElementBlueprint as m, KindBlueprint as u } from "./ref-blueprint.js";
|
|
5
|
-
import { C as
|
|
6
|
-
class
|
|
7
|
-
constructor(t) {
|
|
8
|
-
super(), this.neighborhoodName = t, this.helpers = new h(this.neighborhoodName), this.neighbor = this.neighborhoodName === "cross" ?
|
|
5
|
+
import { C as p, S as d } from "../constants-BT-9-x_4.js";
|
|
6
|
+
class C extends a {
|
|
7
|
+
constructor(t, e) {
|
|
8
|
+
super(), this.neighborhoodName = t, this.helpers = new h(this.neighborhoodName), this.neighbor = this.neighborhoodName === "cross" ? p : d, this.automaton = {
|
|
9
9
|
neighborhood: t ?? "square",
|
|
10
|
+
wrapping: e?.wrapping ?? !1,
|
|
10
11
|
elements: [],
|
|
11
12
|
kinds: [],
|
|
12
13
|
rules: []
|
|
@@ -75,5 +76,5 @@ class b extends a {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
export {
|
|
78
|
-
|
|
79
|
+
C as VivariumBlueprint
|
|
79
80
|
};
|
package/dist/common/constants.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { A as o, C as e, b as
|
|
1
|
+
import { A as o, C as e, b as c, G as p, a as n, c4 as t, O as G, S as r, T as u, c3 as i, c as I, n as O } from "../constants-BT-9-x_4.js";
|
|
2
2
|
export {
|
|
3
3
|
o as Accept,
|
|
4
4
|
e as Cross,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
c as GpuCondition,
|
|
6
|
+
p as GpuElement,
|
|
7
7
|
n as GpuRule,
|
|
8
|
-
t as
|
|
8
|
+
t as MIN_GRID_SIZE,
|
|
9
|
+
G as Opcode,
|
|
9
10
|
r as Square,
|
|
10
11
|
u as To,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
i as WORKGROUP_SIZE,
|
|
13
|
+
I as acceptMap,
|
|
13
14
|
O as neighborhoodPoints
|
|
14
15
|
};
|
package/dist/common/utils.js
CHANGED
|
@@ -295,11 +295,11 @@ const f = (e) => {
|
|
|
295
295
|
const t = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
296
296
|
e = e.replace(
|
|
297
297
|
t,
|
|
298
|
-
(l, a,
|
|
298
|
+
(l, a, n, c) => a + a + n + n + c + c
|
|
299
299
|
);
|
|
300
300
|
const r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
|
|
301
301
|
if (!r)
|
|
302
|
-
throw new Error(
|
|
302
|
+
throw new Error(`Bad color: ${e}`);
|
|
303
303
|
const s = parseInt(r[1], 16), u = parseInt(r[2], 16);
|
|
304
304
|
return 4278190080 | parseInt(r[3], 16) << 16 | u << 8 | s;
|
|
305
305
|
};
|