generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex copy.html
448 lines (395 loc) · 13.8 KB
/
index copy.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Le jeu de la vie de John Horton Conway</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
#gridContainer {
max-width: 100%;
margin: auto;
overflow: visible; /* Allow content to be visible outside the container */
transform-origin: center;
transition: transform 0.3s ease-in-out;
display: inline-block; /* Container size based on content */
}
.grid-cell {
width: 30px;
height: 30px;
border: 0.5px solid #333;
}
.grid-cell.alive {
background-color: #10B981;
}
@keyframes preloader {
0% {
top: 0%;
opacity: 1;
}
100% {
border-radius: 60%;
/* opacity: 0; */
top: -100%;
}
}
#gameCanvas {
}
.pre-loader {
position: fixed;
top: 0%;
width: 100%;
height: 100%;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
animation: preloader 1s ease-in forwards;
animation-delay: 3s;
}
.pre-loader-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: "Cormorant", serif;
}
.header {
text-align: center;
transform: scaleY(1.2);
}
.pre-loader-header h1 {
font-size: 5rem;
display: inline;
color: transparent;
-webkit-text-stroke: 1px #fff;
text-transform: uppercase;
line-height: 7rem;
letter-spacing: -9px;
}
.animate {
position: relative;
}
.animate::before {
content: attr(data-text);
position: absolute;
left: 0;
width: 0%;
color: rgb(100, 177, 27);
height: 100%;
transition: 1s;
animation: fill 2s forwards ease-in-out;
animation-delay: 0.5s;
overflow: hidden;
}
@keyframes fill {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
.pre-loader-btn {
color: white;
margin-top: 2rem;
font-family: "Petrona", serif;
font-size: 1.2rem;
text-transform: capitalize;
}
</style>
</head>
<body class="bg-black text-white font-sans">
<div class="pre-loader">
<div class="pre-loader-container">
<div class="pre-loader-header">
<div class="header">
<h1>Le Jeu de la vie</h1>
<div class="header-wrapper"></div>
</div>
<div class="header">
<h1 class="animate" data-text="est un">est un </h1>
<h1>automate</h1>
<div class="header-wrapper"></div>
</div>
<div class="header">
<h1>cellulaire</h1>
<div class="header-wrapper"></div>
</div>
<div class="header">
<h1>imaginé par </h1>
<div class="header-wrapper"></div>
</div>
<div class="header">
<h1>John Horton Conway</h1>
<h1 class="animate" data-text="en 1970"> en 1970</h1>
<div class="header-wrapper"></div>
</div>
</div>
</div>
</div>
<div class="container mx-auto p-4">
<div class="flex flex-col items-center">
<h1 class="text-4xl mb-8">Le jeu de la vie de John Horton Conway</h1>
<div class="flex justify-center space-x-4 mb-8">
<!-- ... (other buttons) -->
<h5>30% chance for each cell to be alive</h5>
<button id="generateRandom" class="bg-gray-700 px-4 py-2 rounded">Generate Random Setup</button>
<h5>50% chance for each cell to be alive </h5>
<button id="generateRandom5" class="bg-gray-700 px-4 py-2 rounded">Generate Random Setup</button>
</div>
<div id="gridContainer" class="mb-8">
<canvas id="gameCanvas" width="300" height="300" class="bg-dark"></canvas>
</div>
<!-- Placer a gauche -->
<div class="flex justify-start space-x-4 mb-5">
<div></div>
<button id="startGame" class="bg-gray-700 px-4 py-2 rounded">Start Game</button>
<button id="pauseGame" class="bg-gray-700 px-4 py-2 rounded">Pause Game</button>
<button id="reset" class="bg-gray-700 px-4 py-2 rounded">Reset</button>
<button id="zoomIn" class="bg-gray-700 px-4 py-2 rounded">Zoom In</button>
<button id="zoomOut" class="bg-gray-700 px-4 py-2 rounded">Zoom Out</button>
<button id="speedUp" class="bg-gray-700 px-4 py-2 rounded">Speed Up</button>
<button id="speedDown" class="bg-gray-700 px-4 py-2 rounded">Speed Down</button>
</div>
<!-- Placer a droite -->
<div class="flex justify-between w-1/2 mb-8">
<div>
<h2 class="text-lg mb-2">Adjust Grid Size:</h2>
<div class="flex space-x-2 mb-2">
<input type="number" id="rows" placeholder="Rows" class="px-2 py-1 rounded bg-gray-700" value="10" max="25">
<input type="number" id="columns" placeholder="Columns" class="px-2 py-1 rounded bg-gray-700" value="10" max="25">
<button id="updateSize" class="bg-gray-700 px-4 py-2 rounded">Update Grid Size</button>
</div>
</div>
<div id="cellStats" class="text-right">
<h2 class="text-lg mb-2">Nombre de cellules:</h2>
<p>en vie: <span id="aliveCount">0</span></p>
<p>mortes: <span id="deadCount">0</span></p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script>
<script>
// Votre code JavaScript pour le préchargeur
gsap.from(" .header > h1", 2, {
opacity: 0.1,
ease: "power3.inOut",
delay: 0,
});
// Reste du script...
</script>
<script>
let grid = document.getElementById('grid');
const aliveCount = document.getElementById('aliveCount');
const deadCount = document.getElementById('deadCount');
const startGameButton = document.getElementById('startGame');
const pauseGameButton = document.getElementById('pauseGame');
const resetButton = document.getElementById('reset');
const updateSizeButton = document.getElementById('updateSize');
const rowsInput = document.getElementById('rows');
const columnsInput = document.getElementById('columns');
let rows = 25;
let columns = 25;
let intervalId;
let cells = [];
let zoomLevel = 1;
const zoomStep = 0.1; // Step size for each zoom in/out action
const baseCellSize = 30; // Base size of cells in pixels
function calculateCellSize() {
const cellSizeX = canvas.width / columns;
const cellSizeY = canvas.width / rows;
return Math.min(cellSizeX, cellSizeY);
}
const gridContainer = document.getElementById('gridContainer');
const zoomInButton = document.getElementById('zoomIn');
const zoomOutButton = document.getElementById('zoomOut');
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const cellSize = 30; // Taille d'une cellule en pixels
canvas.width = columns * cellSize;
canvas.height = rows * cellSize;
function drawGrid() {
const cellSize = calculateCellSize();
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
ctx.strokeStyle = '#333';
ctx.strokeRect(j * cellSize, i * cellSize, cellSize, cellSize);
}
}
}
let zoomFactor = 1;
function zoomIn() {
zoomFactor = Math.min(zoomFactor + 0.1, 2); // Ajustez les limites selon vos besoins
}
function zoomOut() {
zoomFactor = Math.max(zoomFactor - 0.1, 0.5); // Ajustez les limites selon vos besoins
}
function calculateCellSize() {
const baseCellSize = Math.min(canvas.width / columns, canvas.height / rows);
return baseCellSize * zoomFactor;
}
function updateCanvasSize() {
canvas.width = columns * cellSize;
canvas.height = rows * cellSize;
}
function updateCellSize() {
const newSize = baseCellSize * zoomLevel;
document.querySelectorAll('.grid-cell').forEach(cell => {
cell.style.width = `${newSize}px`;
cell.style.height = `${newSize}px`;
});
}
zoomInButton.addEventListener('click', zoomIn);
zoomOutButton.addEventListener('click', zoomOut);
function createGrid() {
cells = new Array(rows * columns).fill(false);
}
createGrid();
updateGrid();
let speed = 500; // Initial speed in milliseconds
const generateRandomButton = document.getElementById('generateRandom');
const generateRandomButton5 = document.getElementById('generateRandom5');
function generateRandomSetup() {
for (let i = 0; i < cells.length; i++) {
cells[i] = Math.random() < 0.3; // 30% chance for each cell to be alive
}
updateGrid();
}
function generateRandomSetup5() {
for (let i = 0; i < cells.length; i++) {
cells[i] = Math.random() < 0.5; // 50% chance for each cell to be alive
}
updateGrid();
}
generateRandomButton.addEventListener('click', generateRandomSetup);
function updateInterval() {
if (intervalId) {
clearInterval(intervalId);
intervalId = setInterval(nextGeneration, speed);
}
}
generateRandomButton5.addEventListener('click', generateRandomSetup5);
function updateInterval() {
if (intervalId) {
clearInterval(intervalId);
intervalId = setInterval(nextGeneration, speed);
}
}
function updateCellCount() {
const aliveCount = cells.filter(alive => alive).length;
const deadCount = cells.filter(alive => !alive).length;
document.getElementById('aliveCount').textContent = aliveCount;
document.getElementById('deadCount').textContent = deadCount;
}
function speedUp() {
if (speed > 100) {
speed -= 100;
updateInterval();
}
}
function speedDown() {
if (speed < 2000) {
speed += 100;
updateInterval();
}
}
const speedUpButton = document.getElementById('speedUp');
const speedDownButton = document.getElementById('speedDown');
speedUpButton.addEventListener('click', speedUp);
speedDownButton.addEventListener('click', speedDown);
function toggleCellState(index) {
cells[index] = !cells[index];
updateGrid();
updateCellCount();
}
canvas.addEventListener('click', function(event) {
const rect = canvas.getBoundingClientRect();
const cellSize = calculateCellSize();
const x = (event.clientX - rect.left) / (rect.width / canvas.width);
const y = (event.clientY - rect.top) / (rect.height / canvas.height);
const gridX = Math.floor(x / cellSize);
const gridY = Math.floor(y / cellSize);
const index = gridY * columns + gridX;
if (gridX < columns && gridY < rows) {
toggleCellState(index);
updateGrid();
}
});
const internalWidth = 300;
const internalHeight = 300;
canvas.width = internalWidth;
canvas.height = internalHeight;
function updateGrid() {
drawGrid();
const cellSize = calculateCellSize();
cells.forEach((alive, index) => {
if (alive) {
const x = index % columns;
const y = Math.floor(index / columns);
ctx.fillStyle = '#10B981'; // Couleur pour les cellules vivantes
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
}
});
}
function nextGeneration() {
const newCells = cells.slice();
for (let i = 0; i < cells.length; i++) {
const x = i % columns;
const y = Math.floor(i / columns);
const neighbors = getAliveNeighbors(x, y);
const alive = cells[i];
if (alive && (neighbors < 2 || neighbors > 3)) {
newCells[i] = false;
} else if (!alive && neighbors === 3) {
newCells[i] = true;
}
}
cells = newCells;
updateGrid();
}
function getAliveNeighbors(x, y) {
let count = 0;
for (let dx = -1; dx <= 1; dx++) {
for (let dy = -1; dy <= 1; dy++) {
if (dx === 0 && dy === 0) continue;
const nx = x + dx;
const ny = y + dy;
if (nx >= 0 && nx < columns && ny >= 0 && ny < rows) {
count += cells[nx + ny * columns] ? 1 : 0;
}
}
}
return count;
}
function startGame() {
if (intervalId) {
clearInterval(intervalId);
}
intervalId = setInterval(nextGeneration, 500);
}
function resetGame() {
clearInterval(intervalId);
cells = cells.map(() => false);
updateGrid();
}
pauseGameButton.addEventListener('click', () => {
clearInterval(intervalId);
});
updateSizeButton.addEventListener('click', () => {
rows = parseInt(rowsInput.value) || 10;
columns = parseInt(columnsInput.value) || 10;
updateCanvasSize();
createGrid();
updateGrid();
});
startGameButton.addEventListener('click', startGame);
resetButton.addEventListener('click', resetGame);
createGrid();
updateGrid();
</script>
</body>
</html>