vikhyatk commited on
Commit
77b0c52
·
verified ·
1 Parent(s): 2bfc98e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -118
app.py CHANGED
@@ -248,125 +248,127 @@ def point(img, object):
248
  )
249
 
250
 
251
- js = """
252
- function createBgAnimation() {
253
- var canvas = document.createElement('canvas');
254
- canvas.id = 'life-canvas';
255
- document.body.appendChild(canvas);
256
-
257
- var canvas = document.getElementById('life-canvas');
258
- var ctx = canvas.getContext('2d');
259
 
260
- function resizeCanvas() {
261
- canvas.width = window.innerWidth;
262
- canvas.height = window.innerHeight;
263
- }
264
- resizeCanvas();
265
- window.addEventListener('resize', resizeCanvas);
266
-
267
- var cellSize = 8;
268
- var cols = Math.ceil(canvas.width / cellSize);
269
- var rows = Math.ceil(canvas.height / cellSize);
270
-
271
- // Track cell age for color variation
272
- var grid = new Array(cols).fill(null)
273
- .map(() => new Array(rows).fill(null)
274
- .map(() => Math.random() > 0.8 ? 1 : 0)); // If alive, start with age 1
275
-
276
- function countNeighbors(grid, x, y) {
277
- var sum = 0;
278
- for (var i = -1; i < 2; i++) {
279
- for (var j = -1; j < 2; j++) {
280
- var col = (x + i + cols) % cols;
281
- var row = (y + j + rows) % rows;
282
- sum += grid[col][row] ? 1 : 0;
283
- }
284
- }
285
- sum -= grid[x][y] ? 1 : 0;
286
- return sum;
287
- }
288
-
289
- function computeNextGeneration() {
290
- var next = grid.map(arr => [...arr]);
291
 
292
- for (var i = 0; i < cols; i++) {
293
- for (var j = 0; j < rows; j++) {
294
- var neighbors = countNeighbors(grid, i, j);
295
- var state = grid[i][j];
296
-
297
- if (state) {
298
- if (neighbors < 2 || neighbors > 3) {
299
- next[i][j] = 0; // Cell dies
300
- } else {
301
- next[i][j] = Math.min(state + 1, 5); // Age the cell, max age of 5
302
- }
303
- } else if (neighbors === 3) {
304
- next[i][j] = 1; // New cell born
305
- }
306
- }
307
- }
308
 
309
- grid = next;
310
- }
311
-
312
- function getColor(age, isDarkMode) {
313
- // Light mode colors
314
- var lightColors = {
315
- 1: '#dae1f5', // Light blue-grey
316
- 2: '#d3e0f4',
317
- 3: '#ccdff3',
318
- 4: '#c5def2',
319
- 5: '#beddf1' // Slightly deeper blue-grey
320
- };
321
-
322
- // Dark mode colors
323
- var darkColors = {
324
- /*
325
- 1: '#4a5788', // Deep blue-grey
326
- 2: '#4c5a8d',
327
- 3: '#4e5d92',
328
- 4: '#506097',
329
- 5: '#52639c' // Brighter blue-grey
330
- */
331
- 1: 'rgb(16, 20, 32)',
332
- 2: 'rgb(21, 25, 39)',
333
- 3: 'rgb(26, 30, 46)',
334
- 4: 'rgb(31, 35, 53)',
335
- 5: 'rgb(36, 40, 60)'
336
- };
337
-
338
- return isDarkMode ? darkColors[age] : lightColors[age];
339
- }
340
-
341
- function draw() {
342
- var isDarkMode = document.body.classList.contains('dark');
343
- ctx.fillStyle = isDarkMode ? '#0b0f19' : '#f0f0f0';
344
- ctx.fillRect(0, 0, canvas.width, canvas.height);
345
- for (var i = 0; i < cols; i++) {
346
- for (var j = 0; j < rows; j++) {
347
- if (grid[i][j]) {
348
- ctx.fillStyle = getColor(grid[i][j], isDarkMode);
349
- ctx.fillRect(i * cellSize, j * cellSize, cellSize - 1, cellSize - 1);
350
- }
351
- }
352
- }
353
- }
354
-
355
- var lastFrame = 0;
356
- var frameInterval = 300;
357
-
358
- function animate(timestamp) {
359
- if (timestamp - lastFrame >= frameInterval) {
360
- draw();
361
- computeNextGeneration();
362
- lastFrame = timestamp;
363
- }
364
- requestAnimationFrame(animate);
365
- }
366
-
367
- animate(0);
368
- }
369
- """
 
 
370
 
371
  css = """
372
  .output-text span p {
@@ -384,13 +386,13 @@ css = """
384
  }
385
 
386
  #life-canvas {
387
- position: fixed;
388
  top: 0;
389
  left: 0;
390
  width: 100%;
391
  height: 100%;
392
  z-index: -1;
393
- opacity: 0.3;
394
  }
395
 
396
  """
 
248
  )
249
 
250
 
251
+ # js = """
252
+ # function createBgAnimation() {
253
+ # var canvas = document.createElement('canvas');
254
+ # canvas.id = 'life-canvas';
255
+ # document.body.appendChild(canvas);
256
+
257
+ # var canvas = document.getElementById('life-canvas');
258
+ # var ctx = canvas.getContext('2d');
259
 
260
+ # function resizeCanvas() {
261
+ # canvas.width = window.innerWidth;
262
+ # canvas.height = window.innerHeight;
263
+ # }
264
+ # resizeCanvas();
265
+ # window.addEventListener('resize', resizeCanvas);
266
+
267
+ # var cellSize = 8;
268
+ # var cols = Math.ceil(canvas.width / cellSize);
269
+ # var rows = Math.ceil(canvas.height / cellSize);
270
+
271
+ # // Track cell age for color variation
272
+ # var grid = new Array(cols).fill(null)
273
+ # .map(() => new Array(rows).fill(null)
274
+ # .map(() => Math.random() > 0.8 ? 1 : 0)); // If alive, start with age 1
275
+
276
+ # function countNeighbors(grid, x, y) {
277
+ # var sum = 0;
278
+ # for (var i = -1; i < 2; i++) {
279
+ # for (var j = -1; j < 2; j++) {
280
+ # var col = (x + i + cols) % cols;
281
+ # var row = (y + j + rows) % rows;
282
+ # sum += grid[col][row] ? 1 : 0;
283
+ # }
284
+ # }
285
+ # sum -= grid[x][y] ? 1 : 0;
286
+ # return sum;
287
+ # }
288
+
289
+ # function computeNextGeneration() {
290
+ # var next = grid.map(arr => [...arr]);
291
 
292
+ # for (var i = 0; i < cols; i++) {
293
+ # for (var j = 0; j < rows; j++) {
294
+ # var neighbors = countNeighbors(grid, i, j);
295
+ # var state = grid[i][j];
296
+
297
+ # if (state) {
298
+ # if (neighbors < 2 || neighbors > 3) {
299
+ # next[i][j] = 0; // Cell dies
300
+ # } else {
301
+ # next[i][j] = Math.min(state + 1, 5); // Age the cell, max age of 5
302
+ # }
303
+ # } else if (neighbors === 3) {
304
+ # next[i][j] = 1; // New cell born
305
+ # }
306
+ # }
307
+ # }
308
 
309
+ # grid = next;
310
+ # }
311
+
312
+ # function getColor(age, isDarkMode) {
313
+ # // Light mode colors
314
+ # var lightColors = {
315
+ # 1: '#dae1f5', // Light blue-grey
316
+ # 2: '#d3e0f4',
317
+ # 3: '#ccdff3',
318
+ # 4: '#c5def2',
319
+ # 5: '#beddf1' // Slightly deeper blue-grey
320
+ # };
321
+
322
+ # // Dark mode colors
323
+ # var darkColors = {
324
+ # /*
325
+ # 1: '#4a5788', // Deep blue-grey
326
+ # 2: '#4c5a8d',
327
+ # 3: '#4e5d92',
328
+ # 4: '#506097',
329
+ # 5: '#52639c' // Brighter blue-grey
330
+ # */
331
+ # 1: 'rgb(16, 20, 32)',
332
+ # 2: 'rgb(21, 25, 39)',
333
+ # 3: 'rgb(26, 30, 46)',
334
+ # 4: 'rgb(31, 35, 53)',
335
+ # 5: 'rgb(36, 40, 60)'
336
+ # };
337
+
338
+ # return isDarkMode ? darkColors[age] : lightColors[age];
339
+ # }
340
+
341
+ # function draw() {
342
+ # var isDarkMode = document.body.classList.contains('dark');
343
+ # ctx.fillStyle = isDarkMode ? '#0b0f19' : '#f0f0f0';
344
+ # ctx.fillRect(0, 0, canvas.width, canvas.height);
345
+ # for (var i = 0; i < cols; i++) {
346
+ # for (var j = 0; j < rows; j++) {
347
+ # if (grid[i][j]) {
348
+ # ctx.fillStyle = getColor(grid[i][j], isDarkMode);
349
+ # ctx.fillRect(i * cellSize, j * cellSize, cellSize - 1, cellSize - 1);
350
+ # }
351
+ # }
352
+ # }
353
+ # }
354
+
355
+ # var lastFrame = 0;
356
+ # var frameInterval = 300;
357
+
358
+ # function animate(timestamp) {
359
+ # if (timestamp - lastFrame >= frameInterval) {
360
+ # draw();
361
+ # computeNextGeneration();
362
+ # lastFrame = timestamp;
363
+ # }
364
+ # requestAnimationFrame(animate);
365
+ # }
366
+
367
+ # animate(0);
368
+ # }
369
+ # """
370
+
371
+ js = ""
372
 
373
  css = """
374
  .output-text span p {
 
386
  }
387
 
388
  #life-canvas {
389
+ /*position: fixed;
390
  top: 0;
391
  left: 0;
392
  width: 100%;
393
  height: 100%;
394
  z-index: -1;
395
+ opacity: 0.3;*/
396
  }
397
 
398
  """