Spaces:
Sleeping
Sleeping
Commit
·
fc4d829
1
Parent(s):
cc49c95
bug fix
Browse files- index.html +9 -11
index.html
CHANGED
|
@@ -65,9 +65,6 @@
|
|
| 65 |
draw(); // Redraw the canvas after resizing
|
| 66 |
}
|
| 67 |
|
| 68 |
-
window.addEventListener('resize', resizeCanvas);
|
| 69 |
-
resizeCanvas();
|
| 70 |
-
|
| 71 |
function resetTimer() {
|
| 72 |
clearTimeout(timer);
|
| 73 |
timer = setTimeout(decideWinner, 4000);
|
|
@@ -93,7 +90,7 @@
|
|
| 93 |
// Draw all circles
|
| 94 |
circles.forEach(circle => {
|
| 95 |
ctx.beginPath();
|
| 96 |
-
ctx.arc(circle.x, circle.y,
|
| 97 |
ctx.fillStyle = circle.color || '#fff';
|
| 98 |
ctx.fill();
|
| 99 |
ctx.closePath();
|
|
@@ -113,8 +110,6 @@
|
|
| 113 |
const touch = touches[i];
|
| 114 |
circles.push({ id: touch.identifier, x: touch.clientX, y: touch.clientY, color: '#fff' });
|
| 115 |
}
|
| 116 |
-
|
| 117 |
-
resetTimer();
|
| 118 |
}
|
| 119 |
|
| 120 |
function removeCircle(id) {
|
|
@@ -132,6 +127,8 @@
|
|
| 132 |
}
|
| 133 |
const touches = event.touches;
|
| 134 |
updateCircles(touches);
|
|
|
|
|
|
|
| 135 |
});
|
| 136 |
|
| 137 |
canvas.addEventListener('touchmove', (event) => {
|
|
@@ -144,19 +141,20 @@
|
|
| 144 |
});
|
| 145 |
|
| 146 |
canvas.addEventListener('touchend', (event) => {
|
|
|
|
|
|
|
| 147 |
if (winnerDecided) {
|
| 148 |
event.preventDefault();
|
| 149 |
return;
|
| 150 |
}
|
| 151 |
-
|
| 152 |
-
for (let i = 0; i < touches.length; i++) {
|
| 153 |
-
const touch = touches[i];
|
| 154 |
-
removeCircle(touch.identifier);
|
| 155 |
-
}
|
| 156 |
});
|
| 157 |
|
| 158 |
// Start the drawing loop
|
| 159 |
draw();
|
|
|
|
|
|
|
|
|
|
| 160 |
});
|
| 161 |
</script>
|
| 162 |
</body>
|
|
|
|
| 65 |
draw(); // Redraw the canvas after resizing
|
| 66 |
}
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
function resetTimer() {
|
| 69 |
clearTimeout(timer);
|
| 70 |
timer = setTimeout(decideWinner, 4000);
|
|
|
|
| 90 |
// Draw all circles
|
| 91 |
circles.forEach(circle => {
|
| 92 |
ctx.beginPath();
|
| 93 |
+
ctx.arc(circle.x, circle.y, 60, 0, Math.PI * 2); // Radius of 60
|
| 94 |
ctx.fillStyle = circle.color || '#fff';
|
| 95 |
ctx.fill();
|
| 96 |
ctx.closePath();
|
|
|
|
| 110 |
const touch = touches[i];
|
| 111 |
circles.push({ id: touch.identifier, x: touch.clientX, y: touch.clientY, color: '#fff' });
|
| 112 |
}
|
|
|
|
|
|
|
| 113 |
}
|
| 114 |
|
| 115 |
function removeCircle(id) {
|
|
|
|
| 127 |
}
|
| 128 |
const touches = event.touches;
|
| 129 |
updateCircles(touches);
|
| 130 |
+
|
| 131 |
+
resetTimer();
|
| 132 |
});
|
| 133 |
|
| 134 |
canvas.addEventListener('touchmove', (event) => {
|
|
|
|
| 141 |
});
|
| 142 |
|
| 143 |
canvas.addEventListener('touchend', (event) => {
|
| 144 |
+
const touches = event.changedTouches;
|
| 145 |
+
if (touches.length == 0) { winnerDecided = false; }
|
| 146 |
if (winnerDecided) {
|
| 147 |
event.preventDefault();
|
| 148 |
return;
|
| 149 |
}
|
| 150 |
+
updateCircles(touches);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
});
|
| 152 |
|
| 153 |
// Start the drawing loop
|
| 154 |
draw();
|
| 155 |
+
|
| 156 |
+
window.addEventListener('resize', resizeCanvas);
|
| 157 |
+
resizeCanvas();
|
| 158 |
});
|
| 159 |
</script>
|
| 160 |
</body>
|