eaglelandsonce commited on
Commit
6c7dd6b
·
verified ·
1 Parent(s): 1a012c9

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +302 -18
index.html CHANGED
@@ -1,19 +1,303 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Conway's Game of Life</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ font-family: Arial, sans-serif;
11
+ background: #111827;
12
+ color: white;
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: center;
16
+ min-height: 100vh;
17
+ }
18
+
19
+ h1 {
20
+ margin: 20px 0 5px;
21
+ font-size: 2rem;
22
+ }
23
+
24
+ p {
25
+ margin: 0 0 15px;
26
+ color: #cbd5e1;
27
+ text-align: center;
28
+ max-width: 800px;
29
+ }
30
+
31
+ .stats {
32
+ display: flex;
33
+ gap: 20px;
34
+ margin-bottom: 12px;
35
+ font-size: 1rem;
36
+ color: #e5e7eb;
37
+ }
38
+
39
+ canvas {
40
+ background: #0f172a;
41
+ border: 2px solid #334155;
42
+ border-radius: 12px;
43
+ box-shadow: 0 10px 30px rgba(0,0,0,0.35);
44
+ cursor: pointer;
45
+ }
46
+
47
+ .controls {
48
+ margin: 18px 0;
49
+ display: flex;
50
+ flex-wrap: wrap;
51
+ justify-content: center;
52
+ gap: 10px;
53
+ max-width: 900px;
54
+ }
55
+
56
+ button, select, input {
57
+ border: none;
58
+ border-radius: 10px;
59
+ padding: 10px 14px;
60
+ font-size: 0.95rem;
61
+ }
62
+
63
+ button {
64
+ background: #2563eb;
65
+ color: white;
66
+ cursor: pointer;
67
+ transition: transform 0.15s, background 0.15s;
68
+ }
69
+
70
+ button:hover {
71
+ background: #1d4ed8;
72
+ transform: translateY(-1px);
73
+ }
74
+
75
+ select, input {
76
+ background: #e5e7eb;
77
+ color: #111827;
78
+ }
79
+
80
+ label {
81
+ display: flex;
82
+ align-items: center;
83
+ gap: 8px;
84
+ background: #1e293b;
85
+ padding: 6px 10px;
86
+ border-radius: 10px;
87
+ }
88
+ </style>
89
+ </head>
90
+ <body>
91
+ <h1>Conway's Game of Life</h1>
92
+ <p>Click cells to toggle life. Press Play and watch simple rules create complex patterns.</p>
93
+
94
+ <div class="stats">
95
+ <div>Generation: <span id="generation">0</span></div>
96
+ <div>Live Cells: <span id="liveCells">0</span></div>
97
+ </div>
98
+
99
+ <canvas id="gameCanvas" width="800" height="500"></canvas>
100
+
101
+ <div class="controls">
102
+ <button onclick="play()">Play</button>
103
+ <button onclick="pause()">Pause</button>
104
+ <button onclick="step()">Step</button>
105
+ <button onclick="resetGrid()">Reset</button>
106
+ <button onclick="randomizeGrid()">Randomize</button>
107
+
108
+ <select id="patternSelect" onchange="loadPattern(this.value)">
109
+ <option value="">Choose Pattern</option>
110
+ <option value="glider">Glider</option>
111
+ <option value="pulsar">Pulsar</option>
112
+ <option value="spaceship">Lightweight Spaceship</option>
113
+ <option value="gosper">Gosper Glider Gun</option>
114
+ </select>
115
+
116
+ <label>
117
+ Speed
118
+ <input id="speed" type="range" min="50" max="800" value="200" oninput="changeSpeed()" />
119
+ </label>
120
+ </div>
121
+
122
+ <script>
123
+ const canvas = document.getElementById('gameCanvas');
124
+ const ctx = canvas.getContext('2d');
125
+ const generationEl = document.getElementById('generation');
126
+ const liveCellsEl = document.getElementById('liveCells');
127
+ const speedInput = document.getElementById('speed');
128
+
129
+ const cellSize = 10;
130
+ const cols = Math.floor(canvas.width / cellSize);
131
+ const rows = Math.floor(canvas.height / cellSize);
132
+
133
+ let grid = createGrid();
134
+ let generation = 0;
135
+ let timer = null;
136
+ let speed = 200;
137
+
138
+ function createGrid() {
139
+ return Array.from({ length: rows }, () => Array(cols).fill(0));
140
+ }
141
+
142
+ function drawGrid() {
143
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
144
+
145
+ let liveCount = 0;
146
+
147
+ for (let r = 0; r < rows; r++) {
148
+ for (let c = 0; c < cols; c++) {
149
+ if (grid[r][c]) {
150
+ ctx.fillStyle = '#38bdf8';
151
+ ctx.fillRect(c * cellSize, r * cellSize, cellSize - 1, cellSize - 1);
152
+ liveCount++;
153
+ } else {
154
+ ctx.fillStyle = '#020617';
155
+ ctx.fillRect(c * cellSize, r * cellSize, cellSize - 1, cellSize - 1);
156
+ }
157
+ }
158
+ }
159
+
160
+ generationEl.textContent = generation;
161
+ liveCellsEl.textContent = liveCount;
162
+ }
163
+
164
+ function countNeighbors(row, col) {
165
+ let count = 0;
166
+
167
+ for (let dr = -1; dr <= 1; dr++) {
168
+ for (let dc = -1; dc <= 1; dc++) {
169
+ if (dr === 0 && dc === 0) continue;
170
+
171
+ const r = row + dr;
172
+ const c = col + dc;
173
+
174
+ if (r >= 0 && r < rows && c >= 0 && c < cols) {
175
+ count += grid[r][c];
176
+ }
177
+ }
178
+ }
179
+
180
+ return count;
181
+ }
182
+
183
+ function nextGeneration() {
184
+ const next = createGrid();
185
+
186
+ for (let r = 0; r < rows; r++) {
187
+ for (let c = 0; c < cols; c++) {
188
+ const neighbors = countNeighbors(r, c);
189
+ const alive = grid[r][c] === 1;
190
+
191
+ if (alive && (neighbors === 2 || neighbors === 3)) {
192
+ next[r][c] = 1;
193
+ } else if (!alive && neighbors === 3) {
194
+ next[r][c] = 1;
195
+ }
196
+ }
197
+ }
198
+
199
+ grid = next;
200
+ generation++;
201
+ drawGrid();
202
+ }
203
+
204
+ function play() {
205
+ if (!timer) {
206
+ timer = setInterval(nextGeneration, speed);
207
+ }
208
+ }
209
+
210
+ function pause() {
211
+ clearInterval(timer);
212
+ timer = null;
213
+ }
214
+
215
+ function step() {
216
+ pause();
217
+ nextGeneration();
218
+ }
219
+
220
+ function resetGrid() {
221
+ pause();
222
+ grid = createGrid();
223
+ generation = 0;
224
+ document.getElementById('patternSelect').value = '';
225
+ drawGrid();
226
+ }
227
+
228
+ function randomizeGrid() {
229
+ pause();
230
+ grid = createGrid().map(row => row.map(() => Math.random() > 0.75 ? 1 : 0));
231
+ generation = 0;
232
+ drawGrid();
233
+ }
234
+
235
+ function changeSpeed() {
236
+ speed = Number(speedInput.value);
237
+ if (timer) {
238
+ pause();
239
+ play();
240
+ }
241
+ }
242
+
243
+ canvas.addEventListener('click', event => {
244
+ const rect = canvas.getBoundingClientRect();
245
+ const col = Math.floor((event.clientX - rect.left) / cellSize);
246
+ const row = Math.floor((event.clientY - rect.top) / cellSize);
247
+
248
+ if (row >= 0 && row < rows && col >= 0 && col < cols) {
249
+ grid[row][col] = grid[row][col] ? 0 : 1;
250
+ drawGrid();
251
+ }
252
+ });
253
+
254
+ function placePattern(pattern, startRow, startCol) {
255
+ grid = createGrid();
256
+ generation = 0;
257
+
258
+ pattern.forEach(([r, c]) => {
259
+ const row = startRow + r;
260
+ const col = startCol + c;
261
+ if (row >= 0 && row < rows && col >= 0 && col < cols) {
262
+ grid[row][col] = 1;
263
+ }
264
+ });
265
+
266
+ drawGrid();
267
+ }
268
+
269
+ function loadPattern(name) {
270
+ pause();
271
+
272
+ const patterns = {
273
+ glider: [[0,1],[1,2],[2,0],[2,1],[2,2]],
274
+ spaceship: [[0,1],[0,4],[1,0],[2,0],[2,4],[3,0],[3,1],[3,2],[3,3]],
275
+ pulsar: [
276
+ [0,2],[0,3],[0,4],[0,8],[0,9],[0,10],
277
+ [2,0],[2,5],[2,7],[2,12],
278
+ [3,0],[3,5],[3,7],[3,12],
279
+ [4,0],[4,5],[4,7],[4,12],
280
+ [5,2],[5,3],[5,4],[5,8],[5,9],[5,10],
281
+ [7,2],[7,3],[7,4],[7,8],[7,9],[7,10],
282
+ [8,0],[8,5],[8,7],[8,12],
283
+ [9,0],[9,5],[9,7],[9,12],
284
+ [10,0],[10,5],[10,7],[10,12],
285
+ [12,2],[12,3],[12,4],[12,8],[12,9],[12,10]
286
+ ],
287
+ gosper: [
288
+ [5,1],[5,2],[6,1],[6,2],
289
+ [3,13],[3,14],[4,12],[4,16],[5,11],[5,17],[6,11],[6,15],[6,17],[6,18],[7,11],[7,17],[8,12],[8,16],[9,13],[9,14],
290
+ [1,25],[2,23],[2,25],[3,21],[3,22],[4,21],[4,22],[5,21],[5,22],[6,23],[6,25],[7,25],
291
+ [3,35],[3,36],[4,35],[4,36]
292
+ ]
293
+ };
294
+
295
+ if (patterns[name]) {
296
+ placePattern(patterns[name], 8, 12);
297
+ }
298
+ }
299
+
300
+ drawGrid();
301
+ </script>
302
+ </body>
303
  </html>