Spaces:
Sleeping
Sleeping
Commit
·
b04fe02
1
Parent(s):
6701385
Add effect on win
Browse files- index.html +30 -6
index.html
CHANGED
|
@@ -57,6 +57,8 @@
|
|
| 57 |
let timer = null;
|
| 58 |
let animationId = null;
|
| 59 |
let winnerDecided = false;
|
|
|
|
|
|
|
| 60 |
|
| 61 |
// Set canvas dimensions to full window size
|
| 62 |
function resizeCanvas() {
|
|
@@ -67,7 +69,7 @@
|
|
| 67 |
|
| 68 |
function resetTimer(touches) {
|
| 69 |
clearTimeout(timer);
|
| 70 |
-
if (touches >=1){
|
| 71 |
timer = setTimeout(decideWinner, 4000);
|
| 72 |
}
|
| 73 |
}
|
|
@@ -96,6 +98,24 @@
|
|
| 96 |
ctx.fillStyle = circle.color || '#fff';
|
| 97 |
ctx.fill();
|
| 98 |
ctx.closePath();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
});
|
| 100 |
|
| 101 |
animationId = requestAnimationFrame(draw);
|
|
@@ -118,6 +138,7 @@
|
|
| 118 |
circles = circles.filter(c => c.id !== id);
|
| 119 |
if (circles.length === 0 && winnerDecided) {
|
| 120 |
winnerDecided = false;
|
|
|
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
|
@@ -128,8 +149,8 @@
|
|
| 128 |
}
|
| 129 |
const touches = event.touches;
|
| 130 |
updateCircles(touches);
|
| 131 |
-
|
| 132 |
-
resetTimer(touches);
|
| 133 |
});
|
| 134 |
|
| 135 |
canvas.addEventListener('touchmove', (event) => {
|
|
@@ -143,20 +164,23 @@
|
|
| 143 |
|
| 144 |
canvas.addEventListener('touchend', (event) => {
|
| 145 |
const touches = event.touches;
|
| 146 |
-
if (touches.length == 0) {
|
|
|
|
|
|
|
|
|
|
| 147 |
if (winnerDecided) {
|
| 148 |
event.preventDefault();
|
| 149 |
return;
|
| 150 |
}
|
| 151 |
updateCircles(touches);
|
| 152 |
-
resetTimer(touches);
|
| 153 |
});
|
| 154 |
|
| 155 |
window.addEventListener('resize', resizeCanvas);
|
| 156 |
|
| 157 |
setTimeout(() => {
|
| 158 |
resizeCanvas();
|
| 159 |
-
},
|
| 160 |
});
|
| 161 |
</script>
|
| 162 |
</body>
|
|
|
|
| 57 |
let timer = null;
|
| 58 |
let animationId = null;
|
| 59 |
let winnerDecided = false;
|
| 60 |
+
let pulseScale = 1.0;
|
| 61 |
+
let pulseDirection = 0.05;
|
| 62 |
|
| 63 |
// Set canvas dimensions to full window size
|
| 64 |
function resizeCanvas() {
|
|
|
|
| 69 |
|
| 70 |
function resetTimer(touches) {
|
| 71 |
clearTimeout(timer);
|
| 72 |
+
if (touches >= 1) {
|
| 73 |
timer = setTimeout(decideWinner, 4000);
|
| 74 |
}
|
| 75 |
}
|
|
|
|
| 98 |
ctx.fillStyle = circle.color || '#fff';
|
| 99 |
ctx.fill();
|
| 100 |
ctx.closePath();
|
| 101 |
+
|
| 102 |
+
// Draw pulsing glow effect around the winning circle
|
| 103 |
+
if (winnerDecided && circle.color === '#228B22') {
|
| 104 |
+
ctx.beginPath();
|
| 105 |
+
ctx.arc(circle.x, circle.y, 60 * pulseScale, 0, Math.PI * 2);
|
| 106 |
+
const gradient = ctx.createRadialGradient(circle.x, circle.y, 60, circle.x, circle.y, 60 * pulseScale);
|
| 107 |
+
gradient.addColorStop(0, 'rgba(34, 139, 34, 0.5)');
|
| 108 |
+
gradient.addColorStop(1, 'rgba(34, 139, 34, 0)');
|
| 109 |
+
ctx.fillStyle = gradient;
|
| 110 |
+
ctx.fill();
|
| 111 |
+
ctx.closePath();
|
| 112 |
+
|
| 113 |
+
// Update pulse scale for animation
|
| 114 |
+
pulseScale += pulseDirection;
|
| 115 |
+
if (pulseScale > 1.5 || pulseScale < 1.0) {
|
| 116 |
+
pulseDirection *= -1;
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
});
|
| 120 |
|
| 121 |
animationId = requestAnimationFrame(draw);
|
|
|
|
| 138 |
circles = circles.filter(c => c.id !== id);
|
| 139 |
if (circles.length === 0 && winnerDecided) {
|
| 140 |
winnerDecided = false;
|
| 141 |
+
pulseScale = 1.0; // Reset pulse scale
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
|
|
|
| 149 |
}
|
| 150 |
const touches = event.touches;
|
| 151 |
updateCircles(touches);
|
| 152 |
+
|
| 153 |
+
resetTimer(touches.length);
|
| 154 |
});
|
| 155 |
|
| 156 |
canvas.addEventListener('touchmove', (event) => {
|
|
|
|
| 164 |
|
| 165 |
canvas.addEventListener('touchend', (event) => {
|
| 166 |
const touches = event.touches;
|
| 167 |
+
if (touches.length == 0) {
|
| 168 |
+
winnerDecided = false;
|
| 169 |
+
pulseScale = 1.0; // Reset pulse scale
|
| 170 |
+
}
|
| 171 |
if (winnerDecided) {
|
| 172 |
event.preventDefault();
|
| 173 |
return;
|
| 174 |
}
|
| 175 |
updateCircles(touches);
|
| 176 |
+
resetTimer(touches.length);
|
| 177 |
});
|
| 178 |
|
| 179 |
window.addEventListener('resize', resizeCanvas);
|
| 180 |
|
| 181 |
setTimeout(() => {
|
| 182 |
resizeCanvas();
|
| 183 |
+
}, 100);
|
| 184 |
});
|
| 185 |
</script>
|
| 186 |
</body>
|