-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlostandfound.html
More file actions
300 lines (259 loc) · 7.4 KB
/
lostandfound.html
File metadata and controls
300 lines (259 loc) · 7.4 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spinning Wheel</title>
<style>
:root {
--bg: #f6f7fb;
--card: #ffffff;
--text: #1f2937;
--muted: #6b7280;
--accent: #111827;
--border: #e5e7eb;
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: Arial, Helvetica, sans-serif;
background: radial-gradient(circle at top, #ffffff 0%, var(--bg) 70%);
color: var(--text);
}
.container {
width: min(92vw, 760px);
background: var(--card);
border: 1px solid var(--border);
border-radius: 24px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
padding: 28px;
text-align: center;
}
h1 {
margin: 0 0 8px;
font-size: clamp(1.8rem, 3vw, 2.4rem);
}
p {
margin: 0 0 22px;
color: var(--muted);
font-size: 1rem;
}
.wheel-wrap {
position: relative;
width: min(78vw, 520px);
height: min(78vw, 520px);
margin: 0 auto 20px;
}
.pointer {
position: absolute;
left: 100%;
top: 50%;
transform: translateX(-50%) rotate(-90deg);
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 0;
border-bottom: 38px solid var(--accent);
z-index: 5;
filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15));
}
canvas {
width: 100%;
height: 100%;
display: block;
cursor: pointer;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.result {
min-height: 32px;
font-size: 1.1rem;
font-weight: 700;
margin-top: 6px;
}
.hint {
color: var(--muted);
font-size: 0.95rem;
margin-top: 8px;
}
.legend {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 10px;
margin-top: 20px;
text-align: left;
}
.legend-item {
border: 1px solid var(--border);
border-radius: 12px;
padding: 10px 12px;
background: #fafafa;
font-size: 0.95rem;
}
</style>
</head>
<body>
<main class="container">
<h1>Spin and Win!</h1>
<p>Click the wheel to claim something from Lost and Found.</p>
<div class="wheel-wrap">
<div class="pointer" aria-hidden="true"></div>
<canvas id="wheel" width="520" height="520" aria-label="Spinning wheel"></canvas>
</div>
<div class="result" id="result">Click the wheel to begin.</div>
<div class="hint">Wait, is this how lost and found works?</div>
</main>
<script>
const labels = [
"Keys",
"Headphones",
"Book",
"ENIGMA User Manual",
"Smartphone",
"Newspaper",
"Coffee Cup",
"Wallet"
];
const colors = [
"#ef4444",
"#f59e0b",
"#10b981",
"#06b6d4",
"#3b82f6",
"#8b5cf6",
"#ec4899",
"#84cc16"
];
const canvas = document.getElementById("wheel");
const ctx = canvas.getContext("2d");
const result = document.getElementById("result");
const size = canvas.width;
const center = size / 2;
const radius = center - 12;
const segmentAngle = (Math.PI * 2) / labels.length;
let rotation = 0;
let isSpinning = false;
function drawWheel() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Outer shadow circle
ctx.beginPath();
ctx.arc(center, center, radius, 0, Math.PI * 2);
ctx.fillStyle = "#ffffff";
ctx.shadowColor = "rgba(0,0,0,0.12)";
ctx.shadowBlur = 16;
ctx.fill();
ctx.shadowBlur = 0;
// Segments
for (let i = 0; i < labels.length; i++) {
const start = rotation + i * segmentAngle - Math.PI / 2;
const end = start + segmentAngle;
ctx.beginPath();
ctx.moveTo(center, center);
ctx.arc(center, center, radius, start, end);
ctx.closePath();
ctx.fillStyle = colors[i];
ctx.fill();
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 3;
ctx.stroke();
// Label text
ctx.save();
ctx.translate(center, center);
ctx.rotate(start + segmentAngle / 2);
ctx.textAlign = "right";
ctx.fillStyle = "#ffffff";
ctx.font = labels[i].length > 13 ? "bold 16px Arial" : "bold 18px Arial";
ctx.shadowColor = "rgba(0,0,0,0.25)";
ctx.shadowBlur = 2;
wrapText(labels[i], radius - 22);
ctx.restore();
}
// Center hub
ctx.beginPath();
ctx.arc(center, center, 42, 0, Math.PI * 2);
ctx.fillStyle = "#111827";
ctx.fill();
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 6;
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.font = "bold 14px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("SPIN", center, center);
}
function wrapText(text, x) {
const words = text.split(" ");
const lines = [];
let line = "";
const maxWidth = 150;
for (const word of words) {
const testLine = line ? line + " " + word : word;
if (ctx.measureText(testLine).width > maxWidth && line) {
lines.push(line);
line = word;
} else {
line = testLine;
}
}
if (line) lines.push(line);
const lineHeight = 18;
const startY = -((lines.length - 1) * lineHeight) / 2;
lines.forEach((ln, idx) => {
ctx.fillText(ln, x, startY + idx * lineHeight);
});
}
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function spinWheel() {
if (isSpinning) return;
isSpinning = true;
result.textContent = "Spinning...";
const winningIndex = labels.indexOf("Coffee Cup");
const targetCenter = winningIndex * segmentAngle + segmentAngle / 2;
const topPointerAngle = Math.PI / 2;
const currentNormalized = ((rotation % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2);
let finalRotation = topPointerAngle - targetCenter;
while (finalRotation <= currentNormalized) {
finalRotation += Math.PI * 2;
}
finalRotation += Math.PI * 2 * (5 + Math.floor(Math.random() * 3));
const startRotation = rotation;
const delta = finalRotation - startRotation;
const duration = 4200;
const startTime = performance.now();
function animate(now) {
const elapsed = now - startTime;
const t = Math.min(elapsed / duration, 1);
rotation = startRotation + delta * easeOutCubic(t);
drawWheel();
if (t < 1) {
requestAnimationFrame(animate);
} else {
isSpinning = false;
result.innerHTML = `
<div>You got: <strong>${labels[winningIndex]}</strong></div>
<div style="font-size: 0.9rem; color: gray;">
Spin again? We have a LOT of coffee cups in the lost and found.
</div>`;;
}
}
requestAnimationFrame(animate);
}
canvas.addEventListener("click", spinWheel);
canvas.addEventListener("keydown", (e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
spinWheel();
}
});
canvas.tabIndex = 0;
drawWheel();
</script>
</body>
</html>