02Flick to angular velocity — turning pointer travel into spin
Each pointermove measures the angle from center with Math.atan2; the delta over elapsed time yields angular velocity in rad/s. The value at release becomes the initial spin, so the disc turns exactly as hard as you flicked it.
Best forInteractive draws, playful screens
pointermovepointerdownMath.atan2

<main class="stage">
<div class="fw" id="fw">
<p class="fw__hint">Each pointermove measures the center angle with atan2; delta over time yields rad/s</p>
<div class="fw__row">
<div class="fw__field" id="field" role="application" aria-label="Flick velocity lab" tabindex="0">
<canvas class="fw__cv" id="cv"></canvas>
</div>
<div class="fw__side">
<b class="fw__vel" id="vel">0.0</b>
<span class="fw__unit">rad/s — the value at release becomes the initial spin</span>
<div class="fw__bar" id="bar" aria-hidden="true"></div>
<p class="fw__meta">Flick strength <b class="fw__count" id="pow">0</b><span class="fw__metaUnit">levels</span></p>
<p class="fw__meta">Drag near the rim and let go</p>
</div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 튕김 각속도(02) — 움직임은 전부 캔버스 rAF 루프다. CSS @keyframes 를 두지 않는다.
// 무대는 노랑 무대의 파스텔 변형 — 무대 노랑 토큰(채도 1.0) 대신 같은 색상의 연한
// 버터 톤(채도 .48 · 명도 .80)을 쓴다(BD26). 칸 다섯 색도 채도 .40 이하 파스텔.
$duration: $dur-loop;
$easing: $ease-out;
$color: $subject-blue;
@include stage(#f2e4bd);
.fw {
--w1: #b3bfd4; // 파랑빛 파스텔 — 1번 칸
--w2: #d8a3b4; // 로즈 파스텔 — 2번 칸
--w3: #a9c4b0; // 세이지 파스텔 — 3번 칸
--w4: #d9c48f; // 골드 파스텔 — 4번 칸
--w5: #c2a8d1; // 플럼 파스텔 — 5번 칸
--ink: #{$subject-ink};
--cream: #{$subject-cream};
display: flex; flex-direction: column; gap: $sp-2;
width: 100%; max-width: 420px;
}
.fw__hint {
margin: 0; font-weight: 700; font-size: clamp(10px, 2.8vw, 12px); line-height: 1.35;
color: $subject-ink;
}
.fw__row { display: flex; gap: $sp-2; align-items: stretch; }
.fw__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;
}
.fw__field:active { cursor: grabbing; }
.fw__field:focus-visible { outline: 2px solid $color; outline-offset: 2px; }
.fw__cv { display: block; width: 100%; height: 100%; }
.fw__side {
flex: 1; min-width: 0;
display: flex; flex-direction: column; gap: $sp-1;
padding-top: $sp-1;
}
.fw__vel {
font-weight: 800; font-size: clamp(20px, 6vw, 30px); line-height: 1;
color: $subject-blue-deep; font-variant-numeric: tabular-nums;
}
.fw__unit { font-weight: 600; font-size: clamp(9px, 2.4vw, 11px); line-height: 1.4; color: rgba($subject-ink, .82); }
.fw__bar { display: flex; gap: $sp-1; margin-top: $sp-1; }
.fw__seg {
width: clamp(12px, 3.4vw, 20px); height: 12px;
border-radius: $r-xs;
background: rgba($subject-ink, .14);
}
.fw__seg.is-on { background: $subject-blue-deep; }
.fw__meta { margin: $sp-1 0 0; font-size: clamp(9px, 2.4vw, 11px); line-height: 1.5; color: rgba($subject-ink, .82); }
.fw__meta b { font-weight: 700; color: $subject-blue-deep; font-variant-numeric: tabular-nums; margin-right: $sp-1; }
.fw__metaUnit { color: rgba($subject-ink, .72); }
@media (max-width: 340px) {
.fw__hint { font-size: 8px; line-height: 1.3; }
.fw { gap: $sp-1; }
.fw__field { width: 150px; height: 150px; }
.fw__vel { font-size: 16px; }
.fw__meta { margin-top: 0; font-size: 8px; }
.fw__seg { width: 10px; height: 8px; }
}
// reduce — 루프가 안 돈다. 자취 표시가 남은 정지 한 장이 남는다.
@media (prefers-reduced-motion: reduce) {
.fw.is-still .fw__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: #f2e4bd;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.fw {
--w1: #b3bfd4;
--w2: #d8a3b4;
--w3: #a9c4b0;
--w4: #d9c48f;
--w5: #c2a8d1;
--ink: #17141a;
--cream: #fff7e6;
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
max-width: 420px;
}
.fw__hint {
margin: 0;
font-weight: 700;
font-size: clamp(10px, 2.8vw, 12px);
line-height: 1.35;
color: #17141a;
}
.fw__row {
display: flex;
gap: 8px;
align-items: stretch;
}
.fw__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;
}
.fw__field:active {
cursor: grabbing;
}
.fw__field:focus-visible {
outline: 2px solid #2f6df6;
outline-offset: 2px;
}
.fw__cv {
display: block;
width: 100%;
height: 100%;
}
.fw__side {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
padding-top: 4px;
}
.fw__vel {
font-weight: 800;
font-size: clamp(20px, 6vw, 30px);
line-height: 1;
color: #0a4fe8;
font-variant-numeric: tabular-nums;
}
.fw__unit {
font-weight: 600;
font-size: clamp(9px, 2.4vw, 11px);
line-height: 1.4;
color: rgba(23, 20, 26, 0.82);
}
.fw__bar {
display: flex;
gap: 4px;
margin-top: 4px;
}
.fw__seg {
width: clamp(12px, 3.4vw, 20px);
height: 12px;
border-radius: 4px;
background: rgba(23, 20, 26, 0.14);
}
.fw__seg.is-on {
background: #0a4fe8;
}
.fw__meta {
margin: 4px 0 0;
font-size: clamp(9px, 2.4vw, 11px);
line-height: 1.5;
color: rgba(23, 20, 26, 0.82);
}
.fw__meta b {
font-weight: 700;
color: #0a4fe8;
font-variant-numeric: tabular-nums;
margin-right: 4px;
}
.fw__metaUnit {
color: rgba(23, 20, 26, 0.72);
}
@media (max-width: 340px) {
.fw__hint {
font-size: 8px;
line-height: 1.3;
}
.fw {
gap: 4px;
}
.fw__field {
width: 150px;
height: 150px;
}
.fw__vel {
font-size: 16px;
}
.fw__meta {
margin-top: 0;
font-size: 8px;
}
.fw__seg {
width: 10px;
height: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
.fw.is-still .fw__field {
cursor: default !important;
}
}// 튕김 각속도(02) — 포인터 이동을 회전 속도로 바꾼다. pointermove 마다 중심에서의 각도를
// Math.atan2 로 재고 이전 각도와의 차에 경과 시간을 나누면 rad/s 각속도가 나온다.
// 손을 뗀 순간의 값이 초기 회전 속도가 되어 튕긴 세기 그대로 판이 돈다.
(function () {
var root = document.getElementById('fw');
var field = document.getElementById('field');
var cv = document.getElementById('cv');
var velEl = document.getElementById('vel');
var barEl = document.getElementById('bar');
var powEl = document.getElementById('pow');
if (!root || !field || !cv || !velEl || !barEl || !powEl) return;
var ctx = cv.getContext('2d');
var css = getComputedStyle(root);
var PAL = [];
for (var i = 1; i <= 5; 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 N = 5, SEG = TAU / N;
var ang = -1.1, vel = 0;
var FRICTION = 0.26, STOP = 0.5;
var FLICKS = [10.2, -15.8, 6.8]; // 자동 시연 튕김 — 고정값이라 항상 같은 시연이 반복된다
var fi = 1, markAng = -1.1, markOp = 0, idle = 0, dpr = 1;
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 draw(peak) {
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 - 10;
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();
ctx.fillStyle = PAL[k]; ctx.fill();
ctx.strokeStyle = 'rgba(23,20,26,.20)'; ctx.lineWidth = 1; ctx.stroke();
ctx.save();
ctx.rotate(a0 + SEG / 2);
ctx.fillStyle = INK;
ctx.font = '700 13px sans-serif';
ctx.textAlign = 'right'; ctx.textBaseline = 'middle';
ctx.fillText(String(k + 1), R - 14, 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();
ctx.restore();
// 12시 고정 포인터
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();
// 손 뗀 순간의 각도 자취 — 튕김의 시작점을 허브에서 표시한다
if (markOp > 0) {
ctx.beginPath();
ctx.arc(cx, cy, 20, markAng - 0.5, markAng + 0.5);
ctx.strokeStyle = 'rgba(23,20,26,' + markOp * 0.7 + ')';
ctx.lineWidth = 4; ctx.stroke();
}
}
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;
velEl.textContent = (drag.v).toFixed(1);
idle = 1.2;
});
function endDrag() {
if (!drag.on) return;
drag.on = false;
vel = Math.max(-24, Math.min(24, drag.v));
markAng = ang; markOp = 1;
powEl.textContent = String(Math.min(5, Math.max(1, Math.ceil(Math.abs(vel) / 4.8))));
}
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];
markAng = ang; markOp = 1; idle = 0;
powEl.textContent = String(Math.min(5, Math.max(1, Math.ceil(Math.abs(vel) / 4.8))));
}
});
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);
velEl.textContent = vel.toFixed(1);
if (Math.abs(vel) < STOP) { vel = 0; velEl.textContent = '0.0'; }
} else if (idle > 0) { idle -= dt; }
else {
vel = FLICKS[fi++ % FLICKS.length];
markAng = ang; markOp = 1;
powEl.textContent = String(Math.min(5, Math.max(1, Math.ceil(Math.abs(vel) / 4.8))));
}
}
if (markOp > 0) markOp = Math.max(0, markOp - dt * 0.9);
draw(markOp);
// 속도 바 — 5단계로 채운다 (레이아웃이 아니라 transform 이다)
var lv = Math.min(5, Math.ceil(Math.abs(drag.on ? drag.v : vel) / 4.8));
for (var q = 0; q < barEl.children.length; q++) {
barEl.children[q].className = q < lv ? 'fw__seg is-on' : 'fw__seg';
}
requestAnimationFrame(step);
}
fit();
for (var s = 0; s < 5; s++) {
var seg = document.createElement('span');
seg.className = 'fw__seg';
barEl.appendChild(seg);
}
window.addEventListener('resize', fit);
if (reduce) {
// 정지 한 장 — 자취 표시가 진행 중인 상태로 고정하고 루프는 돌지 않는다
markOp = 0.5;
draw(0.5);
for (var z = 0; z < barEl.children.length; z++) barEl.children[z].className = z < 2 ? 'fw__seg is-on' : 'fw__seg';
root.classList.add('is-still');
} else {
vel = FLICKS[0]; markAng = ang; markOp = 1;
powEl.textContent = '2';
requestAnimationFrame(step);
}
})();// SpinWheelFlickVelocity — vanilla 판(run/332/demo/02-spin-wheel-flick-velocity/index.html) 의 React 포트.
// pointermove 마다 중심에서의 각도를 Math.atan2 로 재고 이전 각도와의 차에 경과 시간을 나누면
// rad/s 각속도가 나온다. 손을 뗀 순간의 값이 초기 회전 속도가 되어 튕긴 세기 그대로 판이 돈다.
// 자동 시연 튕김(FLICKS)은 시드 없는 고정값 — 항상 같은 계열이 반복된다. 값·수치는 vanilla 와 같다.
// 움직임은 전부 캔버스 rAF 루프가 그리므로 CSS 애니메이션이 없다.
// reduce 에서는 루프를 돌리지 않고 자취 표시가 남은 정지 한 장만 남긴다(.isStill).
import { useEffect, useRef, useState } from "react";
import type { CSSProperties, PointerEvent } from "react";
import styles from "./SpinWheelFlickVelocity.module.scss";
// demo.py 의 ambient react 스텁은 KeyboardEvent 를 export 하지 않는다 — 최소 자체 타입으로 대체
type KeyEvt = { key: string; preventDefault(): void };
export type SpinWheelFlickVelocityProps = {
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 = 5, SEG = TAU / N;
const FRICTION = 0.26, STOP = 0.5;
const FLICKS = [10.2, -15.8, 6.8]; // 자동 시연 튕김 — 고정값이라 항상 같은 시연이 반복된다
const PAL = ["#b3bfd4", "#d8a3b4", "#a9c4b0", "#d9c48f", "#c2a8d1"];
const INK = "#17141a";
const CREAM = "#fff7e6";
const HINT = "pointermove 마다 atan2 로 중심각을 재고 이전 각도·시간과의 차로 rad/s 를 만듭니다";
const ARIA_FIELD = "튕김 각속도 실험판";
const UNIT = "rad/s 손을 뗀 순간의 값이 초기 속도";
const POW_LABEL = "튕김 세기 ";
const POW_UNIT = "단계";
const META_DRAG = "가장자리를 드래그해 돌리고 놓아 보세요";
export default function SpinWheelFlickVelocity({
duration = "2s",
easing = "ease-out",
color = "#2f6df6"
}: SpinWheelFlickVelocityProps) {
const fieldRef = useRef<HTMLDivElement | null>(null);
const cvRef = useRef<HTMLCanvasElement | null>(null);
const velRef = useRef<HTMLSpanElement | null>(null);
const powRef = useRef<HTMLSpanElement | null>(null);
const barRef = useRef<HTMLDivElement | null>(null);
const ctxRef = useRef<CanvasRenderingContext2D | null>(null);
const stRef = useRef({
ang: -1.1, vel: 0, fi: 1, markAng: -1.1, markOp: 0, idle: 0, dpr: 1,
drag: { on: false, lastA: 0, lastT: 0, v: 0 }
}) as Box<{
ang: number; vel: number; fi: number; markAng: number; markOp: number; idle: number; dpr: 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 powLevel(v: number): number {
return Math.min(5, Math.max(1, Math.ceil(Math.abs(v) / 4.8)));
}
function draw(peak: number): 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;
ctx.save();
ctx.translate(cx, cy);
ctx.rotate(st.ang);
for (let k = 0; k < N; k++) {
const a0 = k * SEG;
ctx.beginPath(); ctx.moveTo(0, 0);
ctx.arc(0, 0, R, a0, a0 + SEG); ctx.closePath();
ctx.fillStyle = PAL[k]; ctx.fill();
ctx.strokeStyle = "rgba(23,20,26,.20)"; ctx.lineWidth = 1; ctx.stroke();
ctx.save();
ctx.rotate(a0 + SEG / 2);
ctx.fillStyle = INK;
ctx.font = "700 13px sans-serif";
ctx.textAlign = "right"; ctx.textBaseline = "middle";
ctx.fillText(String(k + 1), R - 14, 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();
ctx.restore();
// 12시 고정 포인터
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();
// 손 뗀 순간의 각도 자취 — 튕김의 시작점을 허브에서 표시한다
if (peak > 0) {
ctx.beginPath();
ctx.arc(cx, cy, 20, st.markAng - 0.5, st.markAng + 0.5);
ctx.strokeStyle = "rgba(23,20,26," + peak * 0.7 + ")";
ctx.lineWidth = 4; ctx.stroke();
}
}
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;
const vel = velRef.current;
if (vel) vel.textContent = st.drag.v.toFixed(1);
st.idle = 1.2;
}
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));
st.markAng = st.ang; st.markOp = 1;
const pow = powRef.current;
if (pow) pow.textContent = String(powLevel(st.vel));
}
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.markAng = st.ang; st.markOp = 1; st.idle = 0;
const pow = powRef.current;
if (pow) pow.textContent = String(powLevel(st.vel));
}
}
function step(now: number): void {
const st = stRef.current;
const dt = Math.min(64, now - lastRef.current) / 1000; lastRef.current = now;
const vel = velRef.current, pow = powRef.current;
if (!st.drag.on) {
if (st.vel !== 0) {
st.ang += st.vel * dt;
st.vel *= Math.pow(FRICTION, dt);
if (vel) vel.textContent = st.vel.toFixed(1);
if (Math.abs(st.vel) < STOP) { st.vel = 0; if (vel) vel.textContent = "0.0"; }
} else if (st.idle > 0) { st.idle -= dt; }
else {
st.vel = FLICKS[st.fi++ % FLICKS.length];
st.markAng = st.ang; st.markOp = 1;
if (pow) pow.textContent = String(powLevel(st.vel));
}
}
if (st.markOp > 0) st.markOp = Math.max(0, st.markOp - dt * 0.9);
draw(st.markOp);
// 속도 바 — 5단계로 채운다 (레이아웃이 아니라 transform 이다)
const lv = Math.min(5, Math.ceil(Math.abs(st.drag.on ? st.drag.v : st.vel) / 4.8));
const bar = barRef.current;
if (bar) {
for (let q = 0; q < bar.children.length; q++) {
(bar.children[q] as HTMLElement).className = q < lv ? styles.seg + " " + styles.isOn : styles.seg;
}
}
rafRef.current = requestAnimationFrame(step);
}
useEffect(() => {
fit();
function onResize(): void { fit(); }
window.addEventListener("resize", onResize);
if (reduced()) {
// 정지 한 장 — 자취 표시가 진행 중인 상태로 고정하고 루프는 돌지 않는다
const st = stRef.current;
st.markOp = 0.5;
draw(0.5);
const bar = barRef.current;
if (bar) {
for (let z = 0; z < bar.children.length; z++) {
(bar.children[z] as HTMLElement).className = z < 2 ? styles.seg + " " + styles.isOn : styles.seg;
}
}
setStill(true);
} else {
const st = stRef.current;
st.vel = FLICKS[0]; st.markAng = st.ang; st.markOp = 1;
const pow = powRef.current;
if (pow) pow.textContent = "2";
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.fw + " " + styles.isStill : styles.fw;
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.vel} ref={velRef}>0.0</b>
<span className={styles.unit}>{UNIT}</span>
<div className={styles.bar} ref={barRef} aria-hidden="true">
{Array.from({ length: 5 }, (_, i) => <span key={i} className={styles.seg}></span>)}
</div>
<p className={styles.meta}>{POW_LABEL}<b className={styles.count} ref={powRef}>0</b><span className={styles.metaUnit}>{POW_UNIT}</span></p>
<p className={styles.meta}>{META_DRAG}</p>
</div>
</div>
</div>
</main>
);
}02 Flick to angular velocity — turning pointer travel into spin — Measured area 23.217% · 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
game03 Whack-a-mole9 CSS Game Demos — Mini Games in HTML & CSS
game01 Basic Spinning Top Whose Angular Speed Decays by FrictionSpinning Top Animation: 9 Canvas Physics Scenes
game02 A Solid Board That Tilts in Perspective With the Pointer and Casts a Longer, Softer Shadow While a Mark Falls Into PlaceCSS Tic Tac Toe: 9 Boards That Count Ahead