summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authoralex <[email protected]>2026-11-10 20:54:44 +0100
committeralex <[email protected]>2026-11-10 20:54:44 +0100
commit5bdac896f505b850142682a12e3f5961f775efb7 (patch)
tree766ded4a9dd6b1e84339432cfcaa3862c13c4984 /public
downloadwheel-of-names-clone.git-5bdac896f505b850142682a12e3f5961f775efb7.tar.xz
wheel-of-names-clone.git-5bdac896f505b850142682a12e3f5961f775efb7.zip
init
Diffstat (limited to 'public')
-rw-r--r--public/app.js172
-rw-r--r--public/index.html47
-rw-r--r--public/styles.css212
3 files changed, 431 insertions, 0 deletions
diff --git a/public/app.js b/public/app.js
new file mode 100644
index 0000000..a757086
--- /dev/null
+++ b/public/app.js
@@ -0,0 +1,172 @@
+const socket = io();
+
+const wheelEl = document.getElementById("wheel");
+const winnerChip = document.getElementById("winnerChip");
+const exampleCommandsEl = document.getElementById("exampleCommands");
+
+const ctx = wheelEl.getContext("2d");
+const radius = wheelEl.width / 2;
+const center = { x: radius, y: radius };
+
+const palette = ["#d95d39", "#f2a541", "#4f6d7a", "#90be6d", "#f28482", "#8d5a97", "#2f3e46", "#577590"];
+
+const appState = {
+ entries: [],
+ selectedWinner: null,
+ angle: 0,
+ spinning: false,
+};
+
+const drawWheel = () => {
+ const entries = appState.entries;
+ const count = entries.length;
+
+ ctx.clearRect(0, 0, wheelEl.width, wheelEl.height);
+ ctx.save();
+ ctx.translate(center.x, center.y);
+ ctx.rotate(appState.angle);
+
+ if (count === 0) {
+ ctx.beginPath();
+ ctx.arc(0, 0, radius - 16, 0, Math.PI * 2);
+ ctx.fillStyle = "#ddd";
+ ctx.fill();
+ ctx.restore();
+ return;
+ }
+
+ const slice = (Math.PI * 2) / count;
+
+ for (let i = 0; i < count; i += 1) {
+ const start = i * slice;
+ const end = start + slice;
+
+ ctx.beginPath();
+ ctx.moveTo(0, 0);
+ ctx.arc(0, 0, radius - 16, start, end);
+ ctx.closePath();
+ ctx.fillStyle = palette[i % palette.length];
+ ctx.fill();
+
+ ctx.save();
+ ctx.rotate(start + slice / 2);
+ ctx.textAlign = "right";
+ ctx.fillStyle = "#fffdf8";
+ ctx.font = "700 26px 'Alegreya Sans', sans-serif";
+ ctx.fillText(entries[i], radius - 36, 10);
+ ctx.restore();
+ }
+
+ ctx.beginPath();
+ ctx.arc(0, 0, 40, 0, Math.PI * 2);
+ ctx.fillStyle = "#fef6ea";
+ ctx.fill();
+ ctx.lineWidth = 7;
+ ctx.strokeStyle = "#1f1b18";
+ ctx.stroke();
+
+ ctx.restore();
+};
+
+const normalizeAngle = (angle) => {
+ const full = Math.PI * 2;
+ return ((angle % full) + full) % full;
+};
+
+const indexAtPointer = () => {
+ const count = appState.entries.length;
+ if (!count) {
+ return -1;
+ }
+
+ const slice = (Math.PI * 2) / count;
+ const pointerAngle = -Math.PI / 2;
+ const relative = normalizeAngle(pointerAngle - appState.angle);
+ return Math.floor(relative / slice) % count;
+};
+
+const targetAngleForWinner = (winner) => {
+ const entries = appState.entries;
+ const winnerIndex = entries.indexOf(winner);
+ if (winnerIndex === -1) {
+ return appState.angle;
+ }
+
+ const count = entries.length;
+ const slice = (Math.PI * 2) / count;
+ const centerOfSlice = winnerIndex * slice + slice / 2;
+ const pointerAngle = -Math.PI / 2;
+
+ return pointerAngle - centerOfSlice;
+};
+
+const easeOutCubic = (t) => 1 - (1 - t) ** 3;
+
+const animateSpin = (winner) => {
+ if (appState.spinning) {
+ return;
+ }
+
+ appState.spinning = true;
+
+ const start = appState.angle;
+ const baseTarget = targetAngleForWinner(winner);
+ const spins = 6 + Math.floor(Math.random() * 3);
+ const final = baseTarget + spins * Math.PI * 2;
+ const duration = 5200;
+ const startTs = performance.now();
+
+ const frame = (now) => {
+ const progress = Math.min(1, (now - startTs) / duration);
+ const eased = easeOutCubic(progress);
+ appState.angle = start + (final - start) * eased;
+ drawWheel();
+
+ if (progress < 1) {
+ requestAnimationFrame(frame);
+ return;
+ }
+
+ appState.angle = final;
+ drawWheel();
+ appState.spinning = false;
+
+ const idx = indexAtPointer();
+ const landed = idx >= 0 ? appState.entries[idx] : winner;
+ winnerChip.textContent = `Winner: ${landed}`;
+ winnerChip.classList.remove("pulse");
+ void winnerChip.offsetWidth;
+ winnerChip.classList.add("pulse");
+ };
+
+ requestAnimationFrame(frame);
+};
+
+const setState = (next) => {
+ appState.entries = Array.isArray(next.entries) ? next.entries : [];
+ appState.selectedWinner = next.selectedWinner || null;
+ drawWheel();
+
+ if (!appState.selectedWinner) {
+ winnerChip.textContent = "Waiting for spin...";
+ }
+
+ const commands = [
+ `curl -X POST http://localhost:3000/api/entries \\\n+ -H 'Content-Type: application/json' \\\n+ -d '{"entries":["Alice","Bob","Charlie","Diana"]}'`,
+ `curl -X POST http://localhost:3000/api/spin \\\n+ -H 'Content-Type: application/json' \\\n+ -d '{"winner":"Charlie"}'`,
+ ];
+
+ exampleCommandsEl.textContent = commands.join("\n\n");
+};
+
+socket.on("state", setState);
+
+socket.on("spin", (spin) => {
+ if (!spin || !spin.winner) {
+ return;
+ }
+
+ animateSpin(spin.winner);
+});
+
+drawWheel();
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..f27fc20
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,47 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Wheel of Names Clone</title>
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
+ <link
+ href="https://fonts.googleapis.com/css2?family=Alegreya+Sans:wght@400;500;700;800&family=Fraunces:opsz,[email protected],600;9..144,700&display=swap"
+ rel="stylesheet"
+ />
+ <link rel="stylesheet" href="styles.css" />
+ </head>
+ <body>
+ <div class="background-shape shape-one"></div>
+ <div class="background-shape shape-two"></div>
+ <main class="app-shell">
+ <header class="hero">
+ <p class="label">Show Mode Wheel</p>
+ <h1>Pick the winner from your terminal</h1>
+ <p class="subtitle">
+ This wheel is controlled by API calls. The spin animation is visual-only,
+ while you choose the winner in advance.
+ </p>
+ </header>
+
+ <section class="wheel-area">
+ <canvas id="wheel" width="640" height="640" aria-label="Wheel"></canvas>
+ <div class="pointer" aria-hidden="true"></div>
+ <div class="winner-chip" id="winnerChip">Waiting for spin...</div>
+ </section>
+
+ <section class="controls">
+ <h2>How to control it</h2>
+ <ol>
+ <li>Set names via <code>POST /api/entries</code></li>
+ <li>Trigger winner via <code>POST /api/spin</code></li>
+ </ol>
+ <pre><code id="exampleCommands"></code></pre>
+ </section>
+ </main>
+
+ <script src="/socket.io/socket.io.js"></script>
+ <script src="app.js"></script>
+ </body>
+</html>
diff --git a/public/styles.css b/public/styles.css
new file mode 100644
index 0000000..a35ab47
--- /dev/null
+++ b/public/styles.css
@@ -0,0 +1,212 @@
+:root {
+ --bg: #f6efe6;
+ --ink: #1f1b18;
+ --muted: #5c5249;
+ --panel: #fff8f0;
+ --accent-a: #d95d39;
+ --accent-b: #f2a541;
+ --accent-c: #4f6d7a;
+ --accent-d: #90be6d;
+ --accent-e: #f28482;
+ --accent-f: #8d5a97;
+ --shadow: 0 24px 48px rgba(31, 27, 24, 0.16);
+}
+
+* {
+ box-sizing: border-box;
+}
+
+body {
+ margin: 0;
+ min-height: 100vh;
+ font-family: "Alegreya Sans", sans-serif;
+ color: var(--ink);
+ background: radial-gradient(circle at 10% 10%, #fff7ec 0%, #f6efe6 50%, #efe4d6 100%);
+ overflow-x: hidden;
+}
+
+.background-shape {
+ position: fixed;
+ border-radius: 999px;
+ opacity: 0.5;
+ filter: blur(2px);
+ pointer-events: none;
+ z-index: 0;
+}
+
+.shape-one {
+ width: 360px;
+ height: 360px;
+ top: -100px;
+ left: -120px;
+ background: linear-gradient(140deg, #f2a541, #d95d39);
+}
+
+.shape-two {
+ width: 340px;
+ height: 340px;
+ right: -100px;
+ bottom: -110px;
+ background: linear-gradient(160deg, #90be6d, #4f6d7a);
+}
+
+.app-shell {
+ position: relative;
+ z-index: 1;
+ display: grid;
+ grid-template-columns: minmax(280px, 720px);
+ justify-content: center;
+ gap: 1.5rem;
+ padding: 2rem 1rem 2.5rem;
+}
+
+.hero {
+ background: color-mix(in oklab, var(--panel), white 35%);
+ border: 1px solid rgba(31, 27, 24, 0.1);
+ border-radius: 20px;
+ padding: 1rem 1.2rem;
+ box-shadow: var(--shadow);
+ animation: riseIn 500ms ease-out both;
+}
+
+.label {
+ margin: 0;
+ color: var(--muted);
+ font-size: 0.95rem;
+ letter-spacing: 0.06em;
+ text-transform: uppercase;
+ font-weight: 700;
+}
+
+h1 {
+ margin: 0.2rem 0 0;
+ font-family: "Fraunces", serif;
+ font-size: clamp(1.8rem, 4vw, 2.6rem);
+ line-height: 1.1;
+}
+
+.subtitle {
+ margin: 0.7rem 0 0;
+ color: var(--muted);
+ font-size: 1.08rem;
+}
+
+.wheel-area {
+ position: relative;
+ display: grid;
+ justify-items: center;
+ gap: 0.8rem;
+ padding: 1rem;
+ background: color-mix(in oklab, var(--panel), white 30%);
+ border: 1px solid rgba(31, 27, 24, 0.09);
+ border-radius: 20px;
+ box-shadow: var(--shadow);
+ animation: riseIn 650ms ease-out both;
+}
+
+#wheel {
+ width: min(88vw, 560px);
+ height: auto;
+ border-radius: 50%;
+ box-shadow: inset 0 0 0 10px #fdf6ea, 0 10px 24px rgba(31, 27, 24, 0.2);
+ transform: rotate(0deg);
+}
+
+.pointer {
+ position: absolute;
+ top: 12px;
+ width: 0;
+ height: 0;
+ border-left: 16px solid transparent;
+ border-right: 16px solid transparent;
+ border-top: 30px solid #2f3e46;
+ filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.2));
+}
+
+.winner-chip {
+ min-height: 40px;
+ display: grid;
+ place-items: center;
+ border-radius: 999px;
+ padding: 0.5rem 1rem;
+ background: #fff;
+ border: 1px solid rgba(31, 27, 24, 0.15);
+ font-weight: 700;
+}
+
+.winner-chip.pulse {
+ animation: pulse 480ms ease;
+}
+
+.controls {
+ background: color-mix(in oklab, var(--panel), white 25%);
+ border-radius: 20px;
+ border: 1px solid rgba(31, 27, 24, 0.09);
+ box-shadow: var(--shadow);
+ padding: 1rem 1.2rem;
+ animation: riseIn 800ms ease-out both;
+}
+
+h2 {
+ margin: 0;
+ font-family: "Fraunces", serif;
+}
+
+ol {
+ margin: 0.5rem 0 0;
+ padding-left: 1.2rem;
+}
+
+li {
+ margin: 0.4rem 0;
+}
+
+pre {
+ margin: 0.8rem 0 0;
+ background: #1f1b18;
+ color: #f7efe5;
+ border-radius: 12px;
+ padding: 0.9rem;
+ overflow-x: auto;
+}
+
+code {
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
+}
+
+@keyframes riseIn {
+ from {
+ transform: translateY(12px);
+ opacity: 0;
+ }
+ to {
+ transform: translateY(0);
+ opacity: 1;
+ }
+}
+
+@keyframes pulse {
+ 0% {
+ transform: scale(1);
+ }
+ 45% {
+ transform: scale(1.07);
+ }
+ 100% {
+ transform: scale(1);
+ }
+}
+
+@media (max-width: 640px) {
+ .app-shell {
+ padding-top: 1rem;
+ }
+
+ .pointer {
+ top: 8px;
+ }
+
+ .subtitle {
+ font-size: 1rem;
+ }
+}