Skip to content

Commit f860b98

Browse files
committed
Added layered CA
1 parent 1714f01 commit f860b98

5 files changed

Lines changed: 2101 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ vite.config.ts.timestamp-*
143143
.vite/
144144

145145
*.iml
146+
.idea

experiments/layered_ca/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Binary Coded Layered Autonoma
2+
3+
An interactive cellular automaton that combines **Langton's Ant**, **multi-color substrates**, and **Conway's Game of
4+
Life** into a single layered system. Multiple ants traverse a colored grid, encoding their movement rules in binary,
5+
while a selectively-activated life simulation evolves on top of the substrate they create.
6+
7+
Open `layered_automata.html` in a browser to run the simulation — no build step or dependencies required.
8+
9+
## Concept
10+
11+
The system layers three interacting subsystems:
12+
13+
1. **Multi-Color Substrate (2–8 colors)** — a grid of colored cells that ants modify as they move.
14+
2. **Binary-Coded Ants** — Langton-style ants whose turn behavior (Left/Right) is encoded as a binary string indexed by
15+
the substrate color underneath them.
16+
3. **Selective Conway's Life** — a Game-of-Life layer that only evolves on cells whose substrate color is enabled by an
17+
*activation mask*, with positive/negative modes that create or inhibit life.
18+
19+
The interplay between these layers produces highway structures, fractal boundaries, and emergent life colonies tuned to
20+
specific color patterns.
21+
22+
## How It Works
23+
24+
### Ant Movement
25+
26+
Each ant reads the substrate color at its current cell and consults its binary **Ant Rule**:
27+
28+
- Bit `0` → turn Left
29+
- Bit `1` → turn Right
30+
31+
The ant then increments the cell's color (mod `numColors`), marks the cell, and steps forward. With `numColors = 4` and
32+
rule `0101`, this generalizes Langton's classic `LRLR` ant.
33+
34+
### Life Activation Mask
35+
36+
A second binary string — the **Activation Mask** — determines which substrate colors are eligible to host life. Each
37+
color also has an **Activation Mode**:
38+
39+
- **Positive (+)**: ant presence spawns life and clears inhibition
40+
- **Negative (−)**: ant presence kills life and creates an *inhibition zone* that suppresses spawning (decays at ~
41+
10%/generation)
42+
43+
### Conway's Life Layer
44+
45+
Life evolves only on **marked** cells whose substrate color is mask-enabled and not inhibited. The rules are extended:
46+
47+
- **Search radius** (1–5) — neighborhood size for counting live neighbors
48+
- **Birth** — exact neighbor count required to spawn life
49+
- **Survival min/max** — neighbor range that keeps a live cell alive
50+
- **Mutual inhibition** — neighbors only count if they share the same activation mode (+ or −) as the cell being
51+
evaluated
52+
53+
Negative-mode cells use slightly relaxed survival/birth thresholds, making them more fragile.
54+
55+
### Multi-Ant System
56+
57+
Up to 8 ants can run simultaneously with configurable:
58+
59+
- **Spawn modes**: `center`, `corners`, `edges`, `random`, `grid`
60+
- **Synchronization**:
61+
- `synchronized` — all ants share the same rule and mask
62+
- `independent` — each ant gets a randomized rule/mask
63+
- `offset` — each ant uses a rotated version of the base rule
64+
65+
## Controls
66+
67+
| Control | Description |
68+
|-----------------------------------------|---------------------------------------------------|
69+
| **Simulation Speed** | Delay between generations (1–2000 ms) |
70+
| **Number of Substrate Colors** | 2–8 colors (sets rule/mask length) |
71+
| **Number of Ants** | 1–8 simultaneous ants |
72+
| **Ant Spawn Mode** | How ants are initially placed |
73+
| **Ant Synchronization** | How rules are shared across ants |
74+
| **Ant Rule** | Per-color L/R turn instruction (clickable bits) |
75+
| **Life Activation Mask** | Per-color flag for life eligibility |
76+
| **Activation Mode** | Per-color +/− toggle (spawn vs. inhibit) |
77+
| **Life Search Radius** | Neighborhood radius for life rules |
78+
| **Birth / Survival Min / Survival Max** | Generalized Conway thresholds |
79+
| **Ant Activation Radius** | Radius around ants where life is seeded/inhibited |
80+
| **Activation Probability** | Per-cell chance of activation within radius |
81+
| **Grid Size** | 50×50 up to 500×500 |
82+
83+
### Buttons
84+
85+
- **Start / Stop** — toggle continuous simulation
86+
- **Step** — advance a single generation
87+
- **Reset** — clear grids and respawn ants
88+
- **Randomize All** — randomize rule, mask, and parameters
89+
- **Random Rule** — randomize only the ant rule
90+
- **Random Mask** — randomize only the activation mask & modes
91+
92+
## Stats Panel
93+
94+
- **Generation** — total simulation steps
95+
- **Ant Steps** — combined steps across all ants
96+
- **Marked Cells** — cells visited at least once by an ant
97+
- **Live Cells** — currently alive Conway cells
98+
- **Inhibited Cells** — cells suppressed by negative activation
99+
- **Active Ants** — number of ants currently running
100+
- **Current Mask** — the active life-activation bitstring
101+
102+
## Visualization
103+
104+
- **Substrate** is rendered using the configurable color palette (only marked cells are drawn).
105+
- **Live cells** appear as bright green squares.
106+
- **Inhibited cells** are tinted red.
107+
- **Ants** are shown as colored squares with a yellow direction indicator and an ID label (when multiple ants are
108+
present).
109+
- **Click the canvas** to enter fullscreen zoom mode; press **Esc** or click again to exit.
110+
111+
## Tips for Interesting Patterns
112+
113+
- Start with `numColors = 4`, rule `0101` (classic Langton's ant) to observe the famous ~10,000-step highway emergence.
114+
- Try rule `1100` or `0011` with 4 colors for symmetric expanding patterns.
115+
- Mix positive and negative activation modes to create competing life regions with shifting boundaries.
116+
- Use multiple ants with the `offset` synchronization to generate kaleidoscopic interference patterns.
117+
- Larger life search radii (3–5) combined with higher birth thresholds produce slow, organic-looking growth.
118+
- Use **Randomize All** repeatedly to discover novel rule combinations.
119+
120+
## Files
121+
122+
- `layered_automata.html` — self-contained simulation (HTML + CSS + JS)
123+
- `README.md` — this document
124+
125+
## Implementation Notes
126+
127+
- Rendering uses a single `ImageData` buffer for substrate and life cells (fast bulk pixel writes), with ants drawn via
128+
standard canvas calls for glow effects.
129+
- Grid wraps toroidally on all edges.
130+
- Inhibition decays stochastically (10% chance per generation) so negative regions slowly heal.
131+
- Neighbor counting respects activation-mode matching, producing emergent segregation between positive and negative life
132+
populations.

0 commit comments

Comments
 (0)