@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 CHANGED
@@ -1,4 +1,8 @@
1
- # Vivarium
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.
@@ -9,6 +9,7 @@ export type Kind = {
9
9
  export type Color = string;
10
10
  export type Automaton = {
11
11
  neighborhood: Neighborhood;
12
+ wrapping: boolean;
12
13
  elements: Element[];
13
14
  kinds: Kind[];
14
15
  rules: Rule[];
@@ -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-DGODv9IV.js";
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-D4GX9YB2.js";
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-DGODv9IV.js";
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-D4GX9YB2.js";
4
+ import "../constants-BT-9-x_4.js";
5
5
  export {
6
6
  o as RuleBlueprint,
7
7
  l as RuleBlueprintWithAccept
@@ -1,4 +1,4 @@
1
- import { n as t } from "../constants-D4GX9YB2.js";
1
+ import { n as t } from "../constants-BT-9-x_4.js";
2
2
  const s = (o) => typeof o == "string" ? t[o] : o.id;
3
3
  export {
4
4
  s as toRefIdOrPoint
@@ -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-DGODv9IV.js";
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 d, S as p } from "../constants-D4GX9YB2.js";
6
- class b extends a {
7
- constructor(t) {
8
- super(), this.neighborhoodName = t, this.helpers = new h(this.neighborhoodName), this.neighbor = this.neighborhoodName === "cross" ? d : p, this.automaton = {
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
- b as VivariumBlueprint
79
+ C as VivariumBlueprint
79
80
  };
@@ -62,3 +62,4 @@ export declare const GpuCondition: d.WgslStruct<{
62
62
  chance: d.F32;
63
63
  }>;
64
64
  export declare const WORKGROUP_SIZE: [number, number];
65
+ export declare const MIN_GRID_SIZE: number;
@@ -1,14 +1,15 @@
1
- import { A as o, C as e, b as p, G as c, a as n, O as t, S as r, T as u, cj as G, c as i, n as O } from "../constants-D4GX9YB2.js";
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
- p as GpuCondition,
6
- c as GpuElement,
5
+ c as GpuCondition,
6
+ p as GpuElement,
7
7
  n as GpuRule,
8
- t as Opcode,
8
+ t as MIN_GRID_SIZE,
9
+ G as Opcode,
9
10
  r as Square,
10
11
  u as To,
11
- G as WORKGROUP_SIZE,
12
- i as acceptMap,
12
+ i as WORKGROUP_SIZE,
13
+ I as acceptMap,
13
14
  O as neighborhoodPoints
14
15
  };
@@ -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, c, n) => a + a + c + c + n + n
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("Bad color");
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
  };