@automatajs/core 0.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/LICENSE +21 -0
- package/README.md +461 -0
- package/dist/engine.d.ts +103 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +255 -0
- package/dist/engine.js.map +1 -0
- package/dist/grid.d.ts +55 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +186 -0
- package/dist/grid.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction.d.ts +44 -0
- package/dist/interaction.d.ts.map +1 -0
- package/dist/interaction.js +145 -0
- package/dist/interaction.js.map +1 -0
- package/dist/presets.d.ts +62 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +158 -0
- package/dist/presets.js.map +1 -0
- package/dist/renderer.d.ts +51 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +150 -0
- package/dist/renderer.js.map +1 -0
- package/dist/types.d.ts +113 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +29 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export type NeighborhoodType = "moore" | "vonneumann";
|
|
2
|
+
export interface GridOptions {
|
|
3
|
+
/** Enable toroidal wrapping (default: true) */
|
|
4
|
+
wrap?: boolean;
|
|
5
|
+
/** Neighborhood type (default: "moore") */
|
|
6
|
+
neighborhood?: NeighborhoodType;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* RGBA color tuple: [red, green, blue, alpha], each 0–255.
|
|
10
|
+
*/
|
|
11
|
+
export type RGBA = [number, number, number, number];
|
|
12
|
+
/**
|
|
13
|
+
* Context object passed to each cell during a rule evaluation.
|
|
14
|
+
* Provides easy access to the cell's own state, its neighbors,
|
|
15
|
+
* and the ability to read any cell on the grid.
|
|
16
|
+
*/
|
|
17
|
+
export interface CellContext {
|
|
18
|
+
/** Current state of this cell (0 = dead, 1+ = alive / multi-state) */
|
|
19
|
+
self: number;
|
|
20
|
+
/** Column coordinate */
|
|
21
|
+
x: number;
|
|
22
|
+
/** Row coordinate */
|
|
23
|
+
y: number;
|
|
24
|
+
/** Number of alive neighbors (count of neighbors with state > 0) */
|
|
25
|
+
neighborCount: number;
|
|
26
|
+
/** Array of individual neighbor state values (Moore: 8, Von Neumann: 4) */
|
|
27
|
+
neighbors: number[];
|
|
28
|
+
/** Read any cell on the grid by coordinate */
|
|
29
|
+
get(x: number, y: number): number;
|
|
30
|
+
/** Grid width */
|
|
31
|
+
cols: number;
|
|
32
|
+
/** Grid height */
|
|
33
|
+
rows: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Style function signature.
|
|
37
|
+
* Determines the visual appearance of a cell based on its state and context.
|
|
38
|
+
* Return an RGBA color tuple, a CSS color string, or a boolean (true = alive color).
|
|
39
|
+
*
|
|
40
|
+
* @param state - Current state of the cell
|
|
41
|
+
* @param ctx - Cell context with position and grid access
|
|
42
|
+
* @returns RGBA tuple, CSS color string, or boolean
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // Fade based on neighbor density
|
|
47
|
+
* const heatmap: StyleFunction = (state, ctx) => {
|
|
48
|
+
* const intensity = Math.floor((ctx.neighborCount / 8) * 255);
|
|
49
|
+
* return [intensity, 50, 255 - intensity, 255];
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export type StyleFunction = (state: number, ctx: CellContext) => RGBA | string | boolean;
|
|
54
|
+
export interface AutomataOptions extends GridOptions {
|
|
55
|
+
/** Number of columns */
|
|
56
|
+
cols?: number;
|
|
57
|
+
/** Number of rows */
|
|
58
|
+
rows?: number;
|
|
59
|
+
/** Frames per second (default: 10) */
|
|
60
|
+
fps?: number;
|
|
61
|
+
/** Color for alive cells (default: "#22d3ee") */
|
|
62
|
+
aliveColor?: string;
|
|
63
|
+
/** Color for dead cells (default: "#0f172a") */
|
|
64
|
+
deadColor?: string;
|
|
65
|
+
/** Background color (default: "#020617") */
|
|
66
|
+
backgroundColor?: string;
|
|
67
|
+
/** Show grid lines (default: true) */
|
|
68
|
+
showGridLines?: boolean;
|
|
69
|
+
/** Grid line color (default: "#1e293b") */
|
|
70
|
+
gridLineColor?: string;
|
|
71
|
+
/** Cell size in pixels (auto-calculated if omitted) */
|
|
72
|
+
cellSize?: number;
|
|
73
|
+
/** Rule function — determines next state for each cell */
|
|
74
|
+
rule?: RuleFunction;
|
|
75
|
+
/** Style function — determines visual appearance per cell (optional) */
|
|
76
|
+
style?: StyleFunction;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Rule function signature.
|
|
80
|
+
*
|
|
81
|
+
* Receives a CellContext with everything you need: self state, neighbor
|
|
82
|
+
* values, neighbor count, coordinates, and a grid accessor.
|
|
83
|
+
*
|
|
84
|
+
* Also supports the legacy positional signature for backward compatibility:
|
|
85
|
+
* `(neighbors, currentState, x, y, grid) => number`
|
|
86
|
+
*
|
|
87
|
+
* @param ctx - Cell context object
|
|
88
|
+
* @returns New state for the cell (0 = dead, 1+ = alive)
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* // Game of Life using CellContext
|
|
93
|
+
* const gol: RuleFunction = (ctx) => {
|
|
94
|
+
* if (ctx.self === 1) {
|
|
95
|
+
* return ctx.neighborCount === 2 || ctx.neighborCount === 3 ? 1 : 0;
|
|
96
|
+
* }
|
|
97
|
+
* return ctx.neighborCount === 3 ? 1 : 0;
|
|
98
|
+
* };
|
|
99
|
+
*
|
|
100
|
+
* // Access individual neighbor values
|
|
101
|
+
* const custom: RuleFunction = (ctx) => {
|
|
102
|
+
* const aliveAbove = ctx.get(ctx.x, ctx.y - 1);
|
|
103
|
+
* return aliveAbove ? 1 : 0;
|
|
104
|
+
* };
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export type RuleFunction = ((ctx: CellContext) => number) | ((neighbors: number, currentState: number, x?: number, y?: number, grid?: Uint8Array) => number);
|
|
108
|
+
export type CellCallback = (x: number, y: number, state: number) => void;
|
|
109
|
+
export interface ExportOptions {
|
|
110
|
+
scale?: number;
|
|
111
|
+
format?: "png" | "jpeg";
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,YAAY,CAAC;AAEtD,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2CAA2C;IAC3C,YAAY,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,qBAAqB;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,oEAAoE;IACpE,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,8CAA8C;IAC9C,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,KAAK,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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,2CAA2C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@automatajs/core",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A focused cellular automata engine for the browser",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"author": "alex <alex@n3m3th.com>",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"readme": "cd ../.. && npm run readme",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.6.3"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT"
|
|
29
|
+
}
|