-
Notifications
You must be signed in to change notification settings - Fork 0
/
CellPhone.html
167 lines (153 loc) · 5.57 KB
/
CellPhone.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
https://claude.site/artifacts/3b09f7bb-e62b-4887-a11a-cda8675ba2ea
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Photonic Cellular Automaton</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #000;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
#grid {
display: grid;
grid-template-columns: repeat(20, 20px);
gap: 1px;
background-color: #333;
padding: 1px;
margin-bottom: 20px;
}
.cell {
width: 20px;
height: 20px;
background-color: #000;
transition: all 0.3s;
}
.controls {
margin-bottom: 20px;
}
button {
margin: 0 10px;
padding: 5px 10px;
}
#explanation {
max-width: 600px;
text-align: justify;
}
</style>
</head>
<body>
<h1>Photonic Cellular Automaton</h1>
<div id="grid"></div>
<div class="controls">
<button id="start">Start</button>
<button id="stop">Stop</button>
<button id="reset">Reset</button>
</div>
<div id="explanation">
<h2>Axioms and Their Effects:</h2>
<p>☼/☾ (Day/Night Cycle): Cells alternate between active and dormant states.</p>
<p>■~□ (Solid/Empty): Determines the presence or absence of energy in a cell.</p>
<p>↑↓→ (Movement): Influences the direction of energy transfer between cells.</p>
<p>◊/◊ (Interaction): Governs how neighboring cells affect each other.</p>
</div>
<script>
const gridSize = 20;
const grid = document.getElementById('grid');
let cells = [];
let intervalId = null;
// Initialize the grid
function initializeGrid() {
grid.innerHTML = '';
cells = [];
for (let i = 0; i < gridSize * gridSize; i++) {
const cell = document.createElement('div');
cell.className = 'cell';
grid.appendChild(cell);
cells.push({
element: cell,
state: Math.random() > 0.5 ? 1 : 0,
axiom: Math.floor(Math.random() * 4)
});
}
updateGrid();
}
// Update the visual representation of the grid
function updateGrid() {
cells.forEach(cell => {
const hue = cell.state * 60; // 0 for black, 60 for yellow
const lightness = 50 + cell.state * 50; // 50% for dim, 100% for bright
cell.element.style.backgroundColor = `hsl(${hue}, 100%, ${lightness}%)`;
cell.element.textContent = ['☼/☾', '■~□', '↑↓→', '◊/◊'][cell.axiom];
});
}
// Apply cellular automaton rules based on axioms
function applyRules() {
const newStates = cells.map((cell, index) => {
const neighbors = getNeighbors(index);
const activeNeighbors = neighbors.filter(n => n.state === 1).length;
switch (cell.axiom) {
case 0: // ☼/☾ Day/Night Cycle
return activeNeighbors === 2 || activeNeighbors === 3 ? 1 : 0;
case 1: // ■~□ Solid/Empty
return activeNeighbors > 4 ? 1 : 0;
case 2: // ↑↓→ Movement
return (cell.state + activeNeighbors) % 2;
case 3: // ◊/◊ Interaction
return activeNeighbors === 3 ? 1 : 0;
default:
return cell.state;
}
});
cells.forEach((cell, index) => {
cell.state = newStates[index];
});
}
// Get the neighboring cells for a given index
function getNeighbors(index) {
const neighbors = [];
const row = Math.floor(index / gridSize);
const col = index % gridSize;
for (let i = -1; i <= 1; i++) {
for (let j = -1; j <= 1; j++) {
if (i === 0 && j === 0) continue;
const newRow = row + i;
const newCol = col + j;
if (newRow >= 0 && newRow < gridSize && newCol >= 0 && newCol < gridSize) {
neighbors.push(cells[newRow * gridSize + newCol]);
}
}
}
return neighbors;
}
// Start the simulation
function startSimulation() {
if (!intervalId) {
intervalId = setInterval(() => {
applyRules();
updateGrid();
}, 500);
}
}
// Stop the simulation
function stopSimulation() {
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
}
// Event listeners for controls
document.getElementById('start').addEventListener('click', startSimulation);
document.getElementById('stop').addEventListener('click', stopSimulation);
document.getElementById('reset').addEventListener('click', initializeGrid);
// Initialize the grid on page load
initializeGrid();
</script>
</body>
</html>