about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-07-06 09:00:24 -0400
committerelioat <elioat@tilde.institute>2024-07-06 09:00:24 -0400
commitc8dab2d52ec65d636e23894f7bab66264d1bc9d7 (patch)
tree5e4ed8045f6b51968430029ca9b51c8c0d526e74
parent92dfaae864e3538319d5f8fbe10585d32f502f2c (diff)
downloadtour-c8dab2d52ec65d636e23894f7bab66264d1bc9d7.tar.gz
*
-rw-r--r--html/life.html30
1 files changed, 28 insertions, 2 deletions
diff --git a/html/life.html b/html/life.html
index 9d2ecf3..7d93a0b 100644
--- a/html/life.html
+++ b/html/life.html
@@ -390,11 +390,37 @@
         let lastRenderTime = 0;
         let isPlaying = false;
 
-        function drawGrid() {
+        canvas.addEventListener('mousemove', handleMouseMove);
+        canvas.addEventListener('mouseout', handleMouseOut);
+
+        let hoveredCell = null; // stores what cell is hovered over
+
+        // Find the cell being hovered hover and and redraw the grid
+        function handleMouseMove(event) {
+            const rect = canvas.getBoundingClientRect();
+            const x = event.clientX - rect.left;
+            const y = event.clientY - rect.top;
+            const gridX = Math.floor(x / cellSize);
+            const gridY = Math.floor(y / cellSize);
+            hoveredCell = { x: gridX, y: gridY };
+            drawGrid(hoveredCell); // Redraw grid with highlighted cell
+        }
+
+        // remove highlight when mouse leaves the cell
+        function handleMouseOut() {
+            hoveredCell = null;
+            drawGrid(); 
+        }
+
+        function drawGrid(hoveredCell = null) {
             ctx.clearRect(0, 0, canvas.width, canvas.height);
             for (let x = 0; x < game.rows; x++) {
                 for (let y = 0; y < game.cols; y++) {
-                    ctx.fillStyle = game.grid[x][y] ? '#2d2d2d' : 'beige';
+                    if (hoveredCell && hoveredCell.x === y && hoveredCell.y === x) {
+                        ctx.fillStyle = '#74FFEF';
+                    } else {
+                        ctx.fillStyle = game.grid[x][y] ? '#2d2d2d' : 'beige';
+                    }
                     ctx.fillRect(y * cellSize, x * cellSize, cellSize, cellSize);
                     ctx.strokeStyle = 'lightgrey';
                     ctx.strokeRect(y * cellSize, x * cellSize, cellSize, cellSize);
een_test.mu?h=hlt&id=aa0888459fc2ca41b0ad6bef5bfa72223ca33945'>^
6f65d591 ^

fb942da8 ^
6f65d591 ^
fb942da8 ^
1fd41772 ^
fb942da8 ^
1fd41772 ^






e80fd05f ^














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