06Winner judging — converting the resting angle into a sector index
The pointer sits fixed at 12 o'clock, so normalize the resting angle against −π/2 and divide by sector angle — the winning index falls out. Announce it through aria-live and chain judge, display and re-spin into one flow for endless rounds.
Best forDraw tools, classroom picks
Math.atan2aria-livefillText

<main class="stage">
<div class="jd" id="jd">
<p class="jd__hint">Normalize the resting angle against −π/2 and divide by the sector angle — the winning index falls out</p>
<div class="jd__row">
<div class="jd__field" id="field" role="application" aria-label="Winner judging lab" tabindex="0">
<canvas class="jd__cv" id="cv"></canvas>
</div>
<div class="jd__side">
<b class="jd__win" id="win">-</b>
<span class="jd__unit" id="winName">Spin the wheel and the result lands here</span>
<p class="jd__meta">Resting angle <b class="jd__count" id="rest">0</b><span class="jd__metaUnit">°</span></p>
<p class="jd__meta">Rounds <b class="jd__count" id="round">0</b><span class="jd__metaUnit">rounds in a row</span></p>
<p class="jd__sr" id="live" aria-live="polite"></p>
</div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 당첨 판정(06) — 움직임은 전부 캔버스 rAF 루프다. CSS @keyframes 를 두지 않는다.
// 무대는 노랑 무대의 파스텔 변형 — 무대 노랑 토큰 대신 연한 버터 톤(채도 .49 · 명도 .78).
// 칸 여섯 색도 파스텔 — 당첨 칸은 스트로크 강조로 알린다(색이 아니라 선).
$duration: $dur-loop;
$easing: $ease-out;
$color: $subject-blue;
@include stage(#f0e2ba);
.jd {
--w1: #b3bfd4; // 파랑빛 파스텔 — 1번 칸
--w2: #d8a3b4; // 로즈 파스텔 — 2번 칸
--w3: #a9c4b0; // 세이지 파스텔 — 3번 칸
--w4: #d9c48f; // 골드 파스텔 — 4번 칸
--w5: #c2a8d1; // 플럼 파스텔 — 5번 칸
--w6: #9fc6c2; // 틸 파스텔 — 6번 칸
--ink: #{$subject-ink};
--cream: #{$subject-cream};
display: flex; flex-direction: column; gap: $sp-2;
width: 100%; max-width: 420px;
}
.jd__hint {
margin: 0; font-weight: 700; font-size: clamp(10px, 2.8vw, 12px); line-height: 1.35;
color: $subject-ink;
}
.jd__row { display: flex; gap: $sp-2; align-items: stretch; }
.jd__field {
position: relative; overflow: hidden;
flex: 0 0 auto;
width: clamp(176px, 46vw, 232px);
height: clamp(176px, 46vw, 232px);
border-radius: $r-card;
background: rgba($subject-ink, .05);
box-shadow: inset 0 0 0 1px rgba($subject-ink, .16);
cursor: grab; touch-action: none;
}
.jd__field:active { cursor: grabbing; }
.jd__field:focus-visible { outline: 2px solid $color; outline-offset: 2px; }
.jd__cv { display: block; width: 100%; height: 100%; }
.jd__side {
flex: 1; min-width: 0;
display: flex; flex-direction: column; gap: $sp-1;
padding-top: $sp-1;
}
.jd__win {
font-weight: 800; font-size: clamp(20px, 6vw, 30px); line-height: 1;
color: $subject-blue-deep; font-variant-numeric: tabular-nums;
}
.jd__unit { font-weight: 600; font-size: clamp(9px, 2.4vw, 11px); line-height: 1.4; color: rgba($subject-ink, .82); }
.jd__meta { margin: $sp-1 0 0; font-size: clamp(9px, 2.4vw, 11px); line-height: 1.5; color: rgba($subject-ink, .82); }
.jd__meta b { font-weight: 700; color: $subject-blue-deep; font-variant-numeric: tabular-nums; margin-right: $sp-1; }
.jd__metaUnit { color: rgba($subject-ink, .72); }
.jd__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); margin: -1px; }
@media (max-width: 340px) {
.jd__hint { font-size: 8px; line-height: 1.3; }
.jd { gap: $sp-1; }
.jd__field { width: 150px; height: 150px; }
.jd__win { font-size: 16px; }
.jd__meta { margin-top: 0; font-size: 8px; }
}
// reduce — 루프가 안 돈다. 판정까지 끝난 정지 한 장이 남는다.
@media (prefers-reduced-motion: reduce) {
.jd.is-still .jd__field { cursor: default !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #f0e2ba;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.jd {
--w1: #b3bfd4;
--w2: #d8a3b4;
--w3: #a9c4b0;
--w4: #d9c48f;
--w5: #c2a8d1;
--w6: #9fc6c2;
--ink: #17141a;
--cream: #fff7e6;
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
max-width: 420px;
}
.jd__hint {
margin: 0;
font-weight: 700;
font-size: clamp(10px, 2.8vw, 12px);
line-height: 1.35;
color: #17141a;
}
.jd__row {
display: flex;
gap: 8px;
align-items: stretch;
}
.jd__field {
position: relative;
overflow: hidden;
flex: 0 0 auto;
width: clamp(176px, 46vw, 232px);
height: clamp(176px, 46vw, 232px);
border-radius: 16px;
background: rgba(23, 20, 26, 0.05);
box-shadow: inset 0 0 0 1px rgba(23, 20, 26, 0.16);
cursor: grab;
touch-action: none;
}
.jd__field:active {
cursor: grabbing;
}
.jd__field:focus-visible {
outline: 2px solid #2f6df6;
outline-offset: 2px;
}
.jd__cv {
display: block;
width: 100%;
height: 100%;
}
.jd__side {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
padding-top: 4px;
}
.jd__win {
font-weight: 800;
font-size: clamp(20px, 6vw, 30px);
line-height: 1;
color: #0a4fe8;
font-variant-numeric: tabular-nums;
}
.jd__unit {
font-weight: 600;
font-size: clamp(9px, 2.4vw, 11px);
line-height: 1.4;
color: rgba(23, 20, 26, 0.82);
}
.jd__meta {
margin: 4px 0 0;
font-size: clamp(9px, 2.4vw, 11px);
line-height: 1.5;
color: rgba(23, 20, 26, 0.82);
}
.jd__meta b {
font-weight: 700;
color: #0a4fe8;
font-variant-numeric: tabular-nums;
margin-right: 4px;
}
.jd__metaUnit {
color: rgba(23, 20, 26, 0.72);
}
.jd__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
margin: -1px;
}
@media (max-width: 340px) {
.jd__hint {
font-size: 8px;
line-height: 1.3;
}
.jd {
gap: 4px;
}
.jd__field {
width: 150px;
height: 150px;
}
.jd__win {
font-size: 16px;
}
.jd__meta {
margin-top: 0;
font-size: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
.jd.is-still .jd__field {
cursor: default !important;
}
}// Winner 판정(06) — 포인터는 12시 방향 고정이므로 정지 각도를 −π/2 기준으로 정규화한
// 뒤 sectors 각도로 나누면 Winner 인덱스가 나온다. 결과는 aria-live 로 읽어주고, 판정·표시·
// 재도전을 한 흐름으로 묶어 화면을 켠 채로 몇 번이든 돌린다.
(function () {
var root = document.getElementById('jd');
var field = document.getElementById('field');
var cv = document.getElementById('cv');
var winEl = document.getElementById('win');
var nameEl = document.getElementById('winName');
var restEl = document.getElementById('rest');
var roundEl = document.getElementById('round');
var liveEl = document.getElementById('live');
if (!root || !field || !cv || !winEl || !nameEl || !restEl || !roundEl || !liveEl) return;
var ctx = cv.getContext('2d');
var css = getComputedStyle(root);
var PAL = [];
for (var i = 1; i <= 6; i++) PAL.push(css.getPropertyValue('--w' + i).trim());
var INK = css.getPropertyValue('--ink').trim();
var CREAM = css.getPropertyValue('--cream').trim();
var TAU = Math.PI * 2;
var NAMES = ['Coffee gift card', 'Zilch, next round', 'Triangle kimbap', 'Cookie', 'Americano', 'Penalty hit'];
var N = 6, SEG = TAU / N;
var ang = -0.7, vel = 0, round = 0, lastWin = -1;
var FRICTION = 0.28, STOP = 0.5;
var settle = -1, pulse = -1, dpr = 1, announced = false;
var flicks = [10.5, -12.5, 9];
var fi = 1, idle = 0;
function fit() {
var w = field.clientWidth, h = field.clientHeight;
dpr = Math.min(2, window.devicePixelRatio || 1);
cv.width = Math.round(w * dpr); cv.height = Math.round(h * dpr);
}
function norm(a) { a %= TAU; return a < 0 ? a + TAU : a; }
function idxAt(a) { return Math.floor(norm(-Math.PI / 2 - a) / SEG) % N; }
function draw() {
var w = cv.width / dpr, h = cv.height / dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, w, h);
var cx = w / 2, cy = h / 2, R = Math.min(w, h) / 2 - 12;
ctx.save(); ctx.translate(cx, cy); ctx.rotate(ang);
for (var k = 0; k < N; k++) {
var a0 = k * SEG;
ctx.beginPath(); ctx.moveTo(0, 0);
ctx.arc(0, 0, R, a0, a0 + SEG); ctx.closePath();
// Winner 칸은 한 levels 진하게 — settle 중일때만
var isWin = settle >= 0 && k === lastWin;
ctx.fillStyle = isWin ? PAL[k] : PAL[k];
ctx.fill();
if (isWin) {
ctx.strokeStyle = INK; ctx.lineWidth = 2.5; ctx.stroke();
} else {
ctx.strokeStyle = 'rgba(23,20,26,.20)'; ctx.lineWidth = 1; ctx.stroke();
}
// Name — sectors 가운데 각도에 세로로 눕혀 적는다
ctx.save(); ctx.rotate(a0 + SEG / 2);
ctx.fillStyle = INK;
ctx.font = '700 11px sans-serif';
ctx.textAlign = 'right'; ctx.textBaseline = 'middle';
ctx.fillText(NAMES[k], R - 12, 0);
ctx.restore();
}
ctx.beginPath(); ctx.arc(0, 0, 13, 0, TAU);
ctx.fillStyle = CREAM; ctx.fill(); ctx.strokeStyle = 'rgba(23,20,26,.35)'; ctx.stroke();
if (pulse >= 0) {
ctx.beginPath(); ctx.arc(0, 0, 13 + pulse * 24, 0, TAU);
ctx.strokeStyle = 'rgba(23,20,26,' + (1 - pulse) * 0.55 + ')';
ctx.lineWidth = 2; ctx.stroke();
}
ctx.restore();
ctx.beginPath();
ctx.moveTo(cx - 7, cy - R - 9); ctx.lineTo(cx + 7, cy - R - 9); ctx.lineTo(cx, cy - R + 8);
ctx.closePath(); ctx.fillStyle = INK; ctx.fill();
}
var drag = { on: false, lastA: 0, lastT: 0, v: 0 };
function angleAt(e) {
var b = field.getBoundingClientRect();
return Math.atan2(e.clientY - (b.top + b.height / 2), e.clientX - (b.left + b.width / 2));
}
field.addEventListener('pointerdown', function (e) {
drag.on = true; drag.lastA = angleAt(e); drag.lastT = performance.now(); drag.v = 0;
if (field.setPointerCapture) { try { field.setPointerCapture(e.pointerId); } catch (err) { /* 캡처 실패는 회전에 영향 없다 */ } }
});
field.addEventListener('pointermove', function (e) {
if (!drag.on) return;
var a = angleAt(e), now = performance.now();
var dA = a - drag.lastA;
if (dA > Math.PI) dA -= TAU;
if (dA < -Math.PI) dA += TAU;
ang += dA;
var dt = Math.max(1, now - drag.lastT) / 1000;
drag.v = 0.65 * drag.v + 0.35 * (dA / dt);
drag.lastA = a; drag.lastT = now;
idle = 0;
});
function endDrag() {
if (!drag.on) return;
drag.on = false;
vel = Math.max(-24, Math.min(24, drag.v));
if (Math.abs(vel) < 1.5) vel = flicks[0];
settle = -1; pulse = -1; announced = false;
round++; roundEl.textContent = String(round);
}
field.addEventListener('pointerup', endDrag);
field.addEventListener('pointercancel', endDrag);
field.addEventListener('keydown', function (e) {
if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
vel = flicks[fi++ % flicks.length];
settle = -1; pulse = -1; announced = false;
round++; roundEl.textContent = String(round);
}
});
function judge() {
var deg = Math.round(norm(ang) * 180 / Math.PI);
restEl.textContent = String(deg);
var idx = idxAt(ang);
lastWin = idx;
winEl.textContent = String(idx + 1) + 'No.';
nameEl.textContent = NAMES[idx];
liveEl.textContent = idx + 1 + 'No. ' + NAMES[idx];
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var last = performance.now();
function step(now) {
var dt = Math.min(64, now - last) / 1000; last = now;
if (!drag.on) {
if (vel !== 0) {
ang += vel * dt;
vel *= Math.pow(FRICTION, dt);
if (Math.abs(vel) < STOP) { vel = 0; settle = 0; pulse = 0; judge(); }
} else if (idle > 0) { idle -= dt; }
else if (settle >= 0) {
settle += dt; pulse = Math.min(1, settle / 0.3);
if (settle > 0.85) {
vel = flicks[fi++ % flicks.length];
settle = -1; pulse = -1; announced = false;
round++; roundEl.textContent = String(round);
}
}
}
draw();
requestAnimationFrame(step);
}
fit();
window.addEventListener('resize', fit);
if (reduce) {
// 정지 한 장 — 판정까지 끝난 상태로 고정하고 루프는 돌지 않는다
ang = -Math.PI / 2 - 2.1 * SEG;
lastWin = idxAt(ang);
pulse = 0.4; settle = 0;
draw();
judge();
roundEl.textContent = '1'; round = 1;
root.classList.add('is-still');
} else {
vel = flicks[0];
round = 1; roundEl.textContent = '1';
requestAnimationFrame(step);
}
})();// SpinWheelResultSnap — vanilla 판(run/332/demo/06-spin-wheel-result-snap/index.html) 의 React 포트.
// judge() 가 정지 각도를 -90도 기준으로 정규화해 당첨 칸 인덱스를 정하고, 그 칸만 굵은 잉크
// 테두리로 강조한다. 결과는 시각 강조와 함께 aria-live 영역에도 텍스트로 알린다(스크린리더 대응).
// 정지 뒤 0.85초 대기 후 자동 재시작 — 다른 항목보다 결과를 오래 보여준다.
// 움직임은 전부 캔버스 rAF 루프가 그리므로 CSS 애니메이션이 없다.
import { useEffect, useRef, useState } from "react";
import type { CSSProperties, PointerEvent } from "react";
import styles from "./SpinWheelResultSnap.module.scss";
// demo.py 의 ambient react 스텁은 KeyboardEvent 를 export 하지 않는다 — 최소 자체 타입으로 대체
type KeyEvt = { key: string; preventDefault(): void };
export type SpinWheelResultSnapProps = {
duration?: string;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
type Box<T> = { current: T };
const TAU = Math.PI * 2;
const N = 6, SEG = TAU / N;
const NAMES = ["커피 기프티콘", "꽝 다음 판", "삼각김밥", "쿠키", "아메리카노", "벌칙 당첨"];
const FRICTION = 0.28, STOP = 0.5;
const FLICKS = [10.5, -12.5, 9];
const PAL = ["#b3bfd4", "#d9c48f", "#a9c4b0", "#c2a8d1", "#d8a3b4", "#9fc6c2"];
const INK = "#17141a";
const CREAM = "#fff7e6";
const HINT = "정지 각도를 -90도 기준으로 정규화해 당첨 칸 인덱스를 구합니다";
const ARIA_FIELD = "결과 판정 실험판";
const UNIT = "번 칸이 당첨입니다";
const META_ROUND = "회차 ";
const META_ROUND_UNIT = "번째 판정";
const SETTLE_WAIT = 0.85; // 다른 항목보다 결과를 오래 보여준다
export default function SpinWheelResultSnap({
duration = "2s",
easing = "ease-out",
color = "#2f6df6"
}: SpinWheelResultSnapProps) {
const fieldRef = useRef<HTMLDivElement | null>(null);
const cvRef = useRef<HTMLCanvasElement | null>(null);
const winRef = useRef<HTMLSpanElement | null>(null);
const nameRef = useRef<HTMLSpanElement | null>(null);
const roundRef = useRef<HTMLSpanElement | null>(null);
const liveRef = useRef<HTMLDivElement | null>(null);
const ctxRef = useRef<CanvasRenderingContext2D | null>(null);
const stRef = useRef({
ang: -0.6, vel: 0, round: 0, settle: -1, lastWin: -1, dpr: 1, fi: 1, idle: 0,
drag: { on: false, lastA: 0, lastT: 0, v: 0 }
}) as Box<{
ang: number; vel: number; round: number; settle: number; lastWin: number; dpr: number; fi: number; idle: number;
drag: { on: boolean; lastA: number; lastT: number; v: number };
}>;
const lastRef = useRef(0) as Box<number>;
const rafRef = useRef(0) as Box<number>;
const [still, setStill] = useState(false);
function reduced(): boolean {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function fit(): void {
const st = stRef.current;
const field = fieldRef.current, cv = cvRef.current;
if (!field || !cv) return;
const ctx = cv.getContext("2d");
if (!ctx) return;
st.dpr = Math.min(2, window.devicePixelRatio || 1);
cv.width = Math.round(field.clientWidth * st.dpr);
cv.height = Math.round(field.clientHeight * st.dpr);
ctxRef.current = ctx;
}
function norm(a: number): number {
const r = a % TAU;
return r < 0 ? r + TAU : r;
}
function judge(): void {
const st = stRef.current;
const u = norm(-Math.PI / 2 - st.ang);
const idx = Math.min(N - 1, Math.floor(u / SEG));
st.lastWin = idx;
const win = winRef.current, name = nameRef.current, live = liveRef.current;
if (win) win.textContent = String(idx + 1) + "번";
if (name) name.textContent = NAMES[idx];
if (live) live.textContent = String(idx + 1) + "번 " + NAMES[idx] + " 당첨";
}
function bumpRound(): void {
const st = stRef.current;
st.round++;
const rd = roundRef.current;
if (rd) rd.textContent = String(st.round);
}
function draw(): void {
const st = stRef.current;
const ctx = ctxRef.current;
if (!ctx) return;
const w = cvRef.current!.width / st.dpr, h = cvRef.current!.height / st.dpr;
ctx.setTransform(st.dpr, 0, 0, st.dpr, 0, 0);
ctx.clearRect(0, 0, w, h);
const cx = w / 2, cy = h / 2, R = Math.min(w, h) / 2 - 10;
const isSettled = st.settle >= 0;
ctx.save(); ctx.translate(cx, cy); ctx.rotate(st.ang);
for (let k = 0; k < N; k++) {
const a0 = k * SEG;
const isWin = isSettled && k === st.lastWin;
ctx.beginPath(); ctx.moveTo(0, 0);
ctx.arc(0, 0, R, a0, a0 + SEG); ctx.closePath();
ctx.fillStyle = PAL[k]; ctx.fill();
ctx.strokeStyle = isWin ? INK : "rgba(23,20,26,.20)";
ctx.lineWidth = isWin ? 2.5 : 1;
ctx.stroke();
}
ctx.beginPath(); ctx.arc(0, 0, 12, 0, TAU);
ctx.fillStyle = CREAM; ctx.fill(); ctx.strokeStyle = "rgba(23,20,26,.35)"; ctx.stroke();
ctx.restore();
ctx.beginPath();
ctx.moveTo(cx - 7, cy - R - 8); ctx.lineTo(cx + 7, cy - R - 8); ctx.lineTo(cx, cy - R + 8);
ctx.closePath(); ctx.fillStyle = INK; ctx.fill();
}
function angleAt(e: PointerEvent<HTMLDivElement>): number {
const b = e.currentTarget.getBoundingClientRect();
return Math.atan2(e.clientY - (b.top + b.height / 2), e.clientX - (b.left + b.width / 2));
}
function onPointerDown(e: PointerEvent<HTMLDivElement>): void {
const st = stRef.current;
st.drag.on = true; st.drag.lastA = angleAt(e); st.drag.lastT = performance.now(); st.drag.v = 0;
try { e.currentTarget.setPointerCapture(e.pointerId); } catch { /* 캡처 실패는 회전에 영향 없다 */ }
}
function onPointerMove(e: PointerEvent<HTMLDivElement>): void {
const st = stRef.current;
if (!st.drag.on) return;
const a = angleAt(e), now = performance.now();
let dA = a - st.drag.lastA;
if (dA > Math.PI) dA -= TAU;
if (dA < -Math.PI) dA += TAU;
st.ang += dA;
const dt = Math.max(1, now - st.drag.lastT) / 1000;
st.drag.v = 0.65 * st.drag.v + 0.35 * (dA / dt);
st.drag.lastA = a; st.drag.lastT = now;
st.idle = 0;
}
function endDrag(): void {
const st = stRef.current;
if (!st.drag.on) return;
st.drag.on = false;
st.vel = Math.max(-24, Math.min(24, st.drag.v));
if (Math.abs(st.vel) < 1) st.vel = FLICKS[0];
st.settle = -1;
bumpRound();
}
function onKeyDown(e: KeyEvt): void {
const st = stRef.current;
if (e.key === " " || e.key === "Enter") {
e.preventDefault();
st.vel = FLICKS[st.fi++ % FLICKS.length];
st.settle = -1; st.idle = 0;
bumpRound();
}
}
function step(now: number): void {
const st = stRef.current;
const dt = Math.min(64, now - lastRef.current) / 1000; lastRef.current = now;
if (!st.drag.on) {
if (st.vel !== 0) {
st.ang += st.vel * dt;
st.vel *= Math.pow(FRICTION, dt);
if (Math.abs(st.vel) < STOP) { st.vel = 0; st.settle = 0; judge(); }
} else if (st.settle >= 0) {
st.settle += dt;
if (st.settle > SETTLE_WAIT) {
st.vel = FLICKS[st.fi++ % FLICKS.length]; st.settle = -1;
bumpRound();
}
} else if (st.idle > 0) { st.idle -= dt; }
else { st.vel = FLICKS[st.fi++ % FLICKS.length]; st.settle = -1; bumpRound(); }
}
draw();
rafRef.current = requestAnimationFrame(step);
}
useEffect(() => {
fit();
function onResize(): void { fit(); }
window.addEventListener("resize", onResize);
if (reduced()) {
// 정지 한 장 — 판정이 끝난 상태로 고정하고 루프는 돌지 않는다
const st = stRef.current;
st.settle = 0.5;
judge();
draw();
st.round = 1;
const rd = roundRef.current;
if (rd) rd.textContent = "1";
setStill(true);
} else {
stRef.current.vel = FLICKS[0];
stRef.current.round = 1;
const rd = roundRef.current;
if (rd) rd.textContent = "1";
lastRef.current = performance.now();
rafRef.current = requestAnimationFrame(step);
}
return () => {
window.removeEventListener("resize", onResize);
cancelAnimationFrame(rafRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const rootCls = still ? styles.jd + " " + styles.isStill : styles.jd;
return (
<main className={styles.stage}>
<div className={rootCls} style={{ "--duration": duration, "--easing": easing, "--color": color } as Vars}>
<p className={styles.hint}>{HINT}</p>
<div className={styles.row}>
<div
className={styles.field}
ref={fieldRef}
role="application"
aria-label={ARIA_FIELD}
tabIndex={0}
onKeyDown={onKeyDown}
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={endDrag}
onPointerCancel={endDrag}
>
<canvas className={styles.cv} ref={cvRef}></canvas>
</div>
<div className={styles.side}>
<b className={styles.num} ref={winRef}>0번</b>
<span className={styles.unit}>{UNIT}</span>
<p className={styles.name} ref={nameRef}></p>
<p className={styles.meta}>{META_ROUND}<b className={styles.count} ref={roundRef}>0</b><span className={styles.metaUnit}>{META_ROUND_UNIT}</span></p>
<div className={styles.sr} ref={liveRef} aria-live="polite"></div>
</div>
</div>
</div>
</main>
);
}06 Winner judging — converting the resting angle into a sector index — Measured area 22.293% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · Spin Wheel: 9 Canvas Roulettes, Flick to Stop
The post this demo lives in
Spin Wheel: 9 Canvas Roulettes, Flick to StopIt spins exactly as hard as you flick it. Angular velocity is integrated, friction decays it, and the sector under the p See all demos in this post
If you like this effect - similar demos
game01 Logo match puzzleHTML CSS JS mini games: 9 copy-paste mini apps
game04 Wandering Top Leaving a Friction Trace on the FloorSpinning Top Animation: 9 Canvas Physics Scenes
game08 A Snake Whose Food Bursts Into Gravity-Bound Particles While the Score Digits Bounce UpCSS Snake Game: 9 Boards That Find Their Own Path