06Vortex decay
Seed a Rankine vortex — solid rotation at the core, inverse falloff outside — and let viscous decay act alone, and you can watch the vortex smear out over time. One decay constant decides how long the rotation survives.
Best forA slow whirl on a loading screen
Math.powFloat32Array

<main class="stage stage--ink">
<div class="fa" id="fa">
<p class="fa__hint">
<svg class="fa__ico" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M128 216a88 88 0 1 1 88-88 8 8 0 0 1-16 0 72 72 0 1 0-72 72 8 8 0 0 1 0 16Z" opacity=".2"/><path d="M128 24a104.2 104.2 0 0 0-73.5 30.5 8 8 0 0 0 11.3 11.3A88 88 0 1 1 40 128a8 8 0 0 0-16 0 104 104 0 1 0 104-104Zm0 40a64 64 0 1 0 64 64 8 8 0 0 0-16 0 48 48 0 1 1-48-48 8 8 0 0 0 0-16Z"/></g></svg>
<span>The core spins together like a rigid body while the outer rim slows with distance, and viscosity fades the whole thing out over time</span>
</p>
<div class="fa__field" id="field" role="application" aria-label="Vortex decay board" tabindex="0">
<canvas class="fa__cv" id="cv"></canvas>
<b class="fa__badge" aria-hidden="true">32<span class="fa__badgeUnit">grid</span></b>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 소용돌이 감쇠 — 움직임은 캔버스 rAF 루프 안에 있다. CSS 는 무대·판·배지만 맡는다. @keyframes 없음.
// 염료 팔레트는 항목01 과 같은 파스텔 3단(하늘색 → 라일락 → 산호)을 재사용한다 — 잉크 무대 위 대비 7.6~13.0.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-blue;
@include stage($stage-ink);
.fa {
--dye-0: #9ac2df;
--dye-1: #b19edb;
--dye-2: #e0a3b8;
display: flex; flex-direction: column; gap: $sp-2;
width: 100%; max-width: 424px;
}
.fa__hint {
display: flex; align-items: center; gap: $sp-1; margin: 0;
font-weight: 700; font-size: clamp(10px, 2.8vw, 12px); line-height: 1.35;
color: $subject-cream;
}
.fa__ico { width: 16px; height: 16px; flex: 0 0 auto; color: #9ac2df; }
.fa__field {
position: relative; height: 208px;
border-radius: $r-card; overflow: hidden;
background: $stage-ink;
box-shadow: inset 0 0 0 1px rgba($subject-cream, .14);
cursor: crosshair; touch-action: none;
}
.fa__field:focus-visible { outline: 2px solid #9ac2df; outline-offset: 2px; }
.fa__cv { display: block; width: 100%; height: 100%; }
.fa__badge {
position: absolute; right: $sp-2; top: $sp-2;
display: flex; align-items: baseline; gap: $sp-1;
padding: $sp-1 $sp-2; border-radius: $r-pill;
background: rgba($subject-ink, .78);
color: $subject-cream; font-weight: 700; font-size: 11px;
}
.fa__badgeUnit { font-weight: 700; }
@media (max-width: 340px) {
.fa { gap: $sp-1; }
.fa__field { height: 124px; }
.fa__badge { font-size: 10px; padding: 0 $sp-1; }
}
// reduce — 루프가 멈춘 한 장이 남으므로 커서 신호만 바꾼다.
@media (prefers-reduced-motion: reduce) {
.fa.is-still .fa__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: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.fa {
--dye-0: #9ac2df;
--dye-1: #b19edb;
--dye-2: #e0a3b8;
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
max-width: 424px;
}
.fa__hint {
display: flex;
align-items: center;
gap: 4px;
margin: 0;
font-weight: 700;
font-size: clamp(10px, 2.8vw, 12px);
line-height: 1.35;
color: #fff7e6;
}
.fa__ico {
width: 16px;
height: 16px;
flex: 0 0 auto;
color: #9ac2df;
}
.fa__field {
position: relative;
height: 208px;
border-radius: 16px;
overflow: hidden;
background: #17141a;
box-shadow: inset 0 0 0 1px rgba(255, 247, 230, 0.14);
cursor: crosshair;
touch-action: none;
}
.fa__field:focus-visible {
outline: 2px solid #9ac2df;
outline-offset: 2px;
}
.fa__cv {
display: block;
width: 100%;
height: 100%;
}
.fa__badge {
position: absolute;
right: 8px;
top: 8px;
display: flex;
align-items: baseline;
gap: 4px;
padding: 4px 8px;
border-radius: 999px;
background: rgba(23, 20, 26, 0.78);
color: #fff7e6;
font-weight: 700;
font-size: 11px;
}
.fa__badgeUnit {
font-weight: 700;
}
@media (max-width: 340px) {
.fa {
gap: 4px;
}
.fa__field {
height: 124px;
}
.fa__badge {
font-size: 10px;
padding: 0 4px;
}
}
@media (prefers-reduced-motion: reduce) {
.fa.is-still .fa__field {
cursor: default !important;
}
}// 소용돌이 감쇠 — 초기화 시점에 랭킨 소용돌이(Rankine vortex) 속도장을 딱 한 번 심는다.
// 중심 반경(r_core) 안쪽은 강체 회전(속도 ∝ 거리), 바깥쪽은 속도 ∝ 1/거리로 줄어든다.
// 이후엔 연속 주입 없이 약한 확산 + 매 프레임 곱셈 감쇠만 걸어 소용돌이가 스스로 흐려져 사라지게 둔다.
// 감쇠가 끝나면 자동으로 다시 심어 루프를 반복한다 — 클릭하면 그 자리에 즉시 새로 심어진다.
var root = document.getElementById('fa');
var field = document.getElementById('field');
var cv = document.getElementById('cv');
var ctx = cv.getContext('2d', { willReadFrequently: true });
var css = getComputedStyle(root);
var PAL0 = css.getPropertyValue('--dye-0').trim();
var PAL1 = css.getPropertyValue('--dye-1').trim();
var PAL2 = css.getPropertyValue('--dye-2').trim();
var N = 32;
var SIZE = (N + 2) * (N + 2);
var IX = function (x, y) { return x + (N + 2) * y; };
var u = new Float32Array(SIZE), v = new Float32Array(SIZE);
var u0 = new Float32Array(SIZE), v0 = new Float32Array(SIZE);
var d = new Float32Array(SIZE), d0 = new Float32Array(SIZE);
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var W = 0, H = 0, raf = 0;
var R_CORE = N * 0.17; // 강체 회전 반경 — 이 안쪽은 각속도가 일정하다
var OMEGA = 1.35; // 중심 각속도 — 값이 클수록 처음에 세게 돈다
var LIFE = 110; // 씨드 뒤 이 스텝(≈3.7초 @30fps) 이 지나면 자동으로 다시 심는다
var lifeStep = 0;
var cycle = 0;
function fit() {
var r = field.getBoundingClientRect();
W = r.width; H = r.height;
cv.width = Math.round(W); cv.height = Math.round(H);
}
// 01 과 동일한 후방 이류(semi-Lagrangian).
function advect(b, dt) {
var src = b === 'u' ? u0 : (b === 'v' ? v0 : d0);
var dst = b === 'u' ? u : (b === 'v' ? v : d);
for (var j = 1; j <= N; j++) {
for (var i = 1; i <= N; i++) {
var x = i - dt * N * u0[IX(i, j)];
var y = j - dt * N * v0[IX(i, j)];
if (x < 0.5) x = 0.5; else if (x > N + 0.5) x = N + 0.5;
var i0 = x | 0; var i1 = i0 + 1;
if (y < 0.5) y = 0.5; else if (y > N + 0.5) y = N + 0.5;
var j0 = y | 0; var j1 = j0 + 1;
var s1 = x - i0, s0 = 1 - s1, t1 = y - j0, t0 = 1 - t1;
dst[IX(i, j)] = s0 * (t0 * src[IX(i0, j0)] + t1 * src[IX(i0, j1)]) +
s1 * (t0 * src[IX(i1, j0)] + t1 * src[IX(i1, j1)]);
}
}
}
// 약한 점성 확산 — 회전 에너지를 이웃 칸으로 새어 나가게 해 소용돌이 팔이 무뎌지며 사라지게 한다.
function diffuse(b, k, dt) {
var src = b === 'u' ? u : (b === 'v' ? v : d);
var a = dt * k * N * N;
for (var iter = 0; iter < 2; iter++) {
for (var j = 1; j <= N; j++) {
for (var i = 1; i <= N; i++) {
var idx = IX(i, j);
src[idx] = (src[idx] + a * (src[IX(i - 1, j)] + src[IX(i + 1, j)] + src[IX(i, j - 1)] + src[IX(i, j + 1)])) / (1 + 4 * a);
}
}
}
}
function bounds() {
for (var i = 1; i <= N; i++) {
d[IX(i, 0)] = d[IX(i, 1)] * 0.5; d[IX(i, N + 1)] = d[IX(i, N)] * 0.5;
u[IX(i, 0)] = u[IX(i, 1)] * 0.4; u[IX(i, N + 1)] = u[IX(i, N)] * 0.4;
v[IX(i, 0)] = v[IX(i, 1)] * 0.4; v[IX(i, N + 1)] = v[IX(i, N)] * 0.4;
}
for (var j = 1; j <= N; j++) {
d[IX(0, j)] = d[IX(1, j)] * 0.5; d[IX(N + 1, j)] = d[IX(N, j)] * 0.5;
u[IX(0, j)] = u[IX(1, j)] * 0.4; u[IX(N + 1, j)] = u[IX(N, j)] * 0.4;
v[IX(0, j)] = v[IX(1, j)] * 0.4; v[IX(N + 1, j)] = v[IX(N, j)] * 0.4;
}
}
// 랭킨 소용돌이 심기 — 필드를 전부 비우고 새 소용돌이 하나만 남긴다(연속 주입이 아니라 일회성 초기화).
function seedVortex(cx, cy, dir) {
u.fill(0); v.fill(0); d.fill(0);
u0.fill(0); v0.fill(0); d0.fill(0);
for (var j = 1; j <= N; j++) {
for (var i = 1; i <= N; i++) {
var dx = i - cx, dy = j - cy;
var r = Math.sqrt(dx * dx + dy * dy) || 0.0001;
var vTheta = r <= R_CORE ? OMEGA * r : OMEGA * (R_CORE * R_CORE) / r;
var idx = IX(i, j);
// 접선 방향(반시계=dir 1, 시계=dir -1): (-dy/r, dx/r)
u[idx] = dir * (-dy / r) * vTheta;
v[idx] = dir * (dx / r) * vTheta;
// 밀도는 소용돌이 팔 모양을 보이려고 코어 주변 링 모양으로 심는다
var ring = Math.exp(-Math.pow((r - R_CORE * 1.15) / (R_CORE * 0.85), 2));
d[idx] = ring * 1.4;
}
}
lifeStep = 0;
}
function step(dt) {
u0.set(u); v0.set(v); d0.set(d);
advect('u', dt); u0.set(u);
advect('v', dt); v0.set(v);
advect('d', dt);
diffuse('u', 0.0016, dt);
diffuse('v', 0.0016, dt);
diffuse('d', 0.0016, dt);
bounds();
// 매 프레임 곱셈 감쇠 — 연속 주입 없이 이것만으로 소용돌이가 시간이 갈수록 흐려진다
var decay = 0.9905;
for (var k = 0; k < SIZE; k++) { u[k] *= decay; v[k] *= decay; d[k] *= 0.988; }
lifeStep++;
if (lifeStep >= LIFE) {
cycle++;
var dir = cycle % 2 === 0 ? 1 : -1;
var cx = N * 0.5 + (cycle % 3 - 1) * N * 0.05;
var cy = N * 0.5 + ((cycle + 1) % 3 - 1) * N * 0.05;
seedVortex(cx, cy, dir);
}
}
function render() {
var img = ctx.createImageData(cv.width, cv.height);
var px = img.data;
var cellW = cv.width / N, cellH = cv.height / N;
var pal = [PAL0, PAL1, PAL2];
for (var py = 0; py < cv.height; py++) {
var gy = Math.min(N - 1, (py / cellH) | 0);
for (var pxx = 0; pxx < cv.width; pxx++) {
var gx = Math.min(N - 1, (pxx / cellW) | 0);
var q = d[IX(gx + 1, gy + 1)];
var o = (py * cv.width + pxx) * 4;
if (q <= 0) { px[o] = 23; px[o + 1] = 20; px[o + 2] = 26; px[o + 3] = 255; continue; }
var band = q > 0.62 ? 2 : (q > 0.3 ? 1 : 0);
var c = pal[band];
var rr = parseInt(c.slice(1, 3), 16), gg = parseInt(c.slice(3, 5), 16), bb = parseInt(c.slice(5, 7), 16);
var a = Math.min(1, q);
px[o] = 23 + (rr - 23) * a; px[o + 1] = 20 + (gg - 20) * a; px[o + 2] = 26 + (bb - 26) * a; px[o + 3] = 255;
}
}
ctx.putImageData(img, 0, 0);
}
function frame() {
step(1 / 30);
render();
raf = requestAnimationFrame(frame);
}
// 실제 사용 — 클릭한 자리에 즉시 새 소용돌이를 심는다(같은 seedVortex 를 자동 루프와 공유).
field.addEventListener('pointerdown', function (e) {
var r = field.getBoundingClientRect();
var gx = 1 + ((e.clientX - r.left) / r.width * (N - 1));
var gy = 1 + ((e.clientY - r.top) / r.height * (N - 1));
cycle++;
seedVortex(gx, gy, cycle % 2 === 0 ? 1 : -1);
if (reduce) render();
});
field.addEventListener('keydown', function (e) {
if (e.key !== 'Enter' && e.key !== ' ') return;
e.preventDefault();
cycle++;
seedVortex(N * 0.5, N * 0.5, cycle % 2 === 0 ? 1 : -1);
if (reduce) render();
});
window.addEventListener('resize', function () { fit(); if (reduce) render(); });
fit();
seedVortex(N * 0.5, N * 0.5, 1);
if (reduce) {
// reduce — 40 걸음만 앞으로 감아 감쇠가 진행 중인 한 장을 그린다(빈 화면도, 갓 심은 화면도 아니다)
for (var k = 0; k < 40; k++) step(1 / 30);
render();
} else {
raf = requestAnimationFrame(frame);
}// VortexDecay — vanilla 판(run/308/demo/06-fluid-vortex-decay/index.html) 의 React 포트.
// 초기화 때 랭킨 소용돌이 속도장을 한 번 심고 점성 감쇠만 두면 시간이 갈수록 퍼져 사라지는 소용돌이가 관찰된다.
// 격자 필드는 ref 상자 안에서만 산다 — React 상태로 두면 리렌더가 매 프레임 일어나 60fps 예산을 못 맞춘다.
import { useEffect, useRef } from "react";
import type { CSSProperties } from "react";
import styles from "./VortexDecay.module.scss";
export type VortexDecayProps = {
duration?: string;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
type Box<T> = { current: T };
type KeyEvt = { key: string; preventDefault(): void };
type PtrEvt = { clientX: number; clientY: number };
const N = 32;
const SIZE = (N + 2) * (N + 2);
function IX(x: number, y: number): number { return x + (N + 2) * y; }
const R_CORE = N * 0.17;
const OMEGA = 1.35;
const LIFE = 110;
export default function VortexDecay({
duration = "2s",
easing = "cubic-bezier(.2, .8, .2, 1)",
color = "#2f6df6",
}: VortexDecayProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
const fieldRef = useRef<HTMLDivElement | null>(null);
const cvRef = useRef<HTMLCanvasElement | null>(null);
const ctxRef = useRef<CanvasRenderingContext2D | null>(null);
const palRef = useRef(["#9ac2df", "#b19edb", "#e0a3b8"]) as Box<string[]>;
const u = useRef(new Float32Array(SIZE)) as Box<Float32Array>;
const v = useRef(new Float32Array(SIZE)) as Box<Float32Array>;
const u0 = useRef(new Float32Array(SIZE)) as Box<Float32Array>;
const v0 = useRef(new Float32Array(SIZE)) as Box<Float32Array>;
const d = useRef(new Float32Array(SIZE)) as Box<Float32Array>;
const d0 = useRef(new Float32Array(SIZE)) as Box<Float32Array>;
const lifeStepRef = useRef(0) as Box<number>;
const cycleRef = useRef(0) as Box<number>;
const rafRef = useRef(0) as Box<number>;
const vars: Vars = { "--duration": duration, "--easing": easing, "--color": color };
function reduced(): boolean {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function fit(): void {
const field = fieldRef.current;
const cv = cvRef.current;
if (!field || !cv) return;
const r = field.getBoundingClientRect();
cv.width = Math.round(r.width);
cv.height = Math.round(r.height);
}
function advect(b: "u" | "v" | "d", dt: number): void {
const src = b === "u" ? u0.current : b === "v" ? v0.current : d0.current;
const dst = b === "u" ? u.current : b === "v" ? v.current : d.current;
const uu = u0.current, vv = v0.current;
for (let j = 1; j <= N; j++) {
for (let i = 1; i <= N; i++) {
let x = i - dt * N * uu[IX(i, j)];
let y = j - dt * N * vv[IX(i, j)];
if (x < 0.5) x = 0.5; else if (x > N + 0.5) x = N + 0.5;
const i0 = x | 0, i1 = i0 + 1;
if (y < 0.5) y = 0.5; else if (y > N + 0.5) y = N + 0.5;
const j0 = y | 0, j1 = j0 + 1;
const s1 = x - i0, s0 = 1 - s1, t1 = y - j0, t0 = 1 - t1;
dst[IX(i, j)] = s0 * (t0 * src[IX(i0, j0)] + t1 * src[IX(i0, j1)]) +
s1 * (t0 * src[IX(i1, j0)] + t1 * src[IX(i1, j1)]);
}
}
}
function diffuse(b: "u" | "v" | "d", k: number, dt: number): void {
const src = b === "u" ? u.current : b === "v" ? v.current : d.current;
const a = dt * k * N * N;
for (let iter = 0; iter < 2; iter++) {
for (let j = 1; j <= N; j++) {
for (let i = 1; i <= N; i++) {
const idx = IX(i, j);
src[idx] = (src[idx] + a * (src[IX(i - 1, j)] + src[IX(i + 1, j)] + src[IX(i, j - 1)] + src[IX(i, j + 1)])) / (1 + 4 * a);
}
}
}
}
function bounds(): void {
const dd = d.current, uu = u.current, vv = v.current;
for (let i = 1; i <= N; i++) {
dd[IX(i, 0)] = dd[IX(i, 1)] * 0.5; dd[IX(i, N + 1)] = dd[IX(i, N)] * 0.5;
uu[IX(i, 0)] = uu[IX(i, 1)] * 0.4; uu[IX(i, N + 1)] = uu[IX(i, N)] * 0.4;
vv[IX(i, 0)] = vv[IX(i, 1)] * 0.4; vv[IX(i, N + 1)] = vv[IX(i, N)] * 0.4;
}
for (let j = 1; j <= N; j++) {
dd[IX(0, j)] = dd[IX(1, j)] * 0.5; dd[IX(N + 1, j)] = dd[IX(N, j)] * 0.5;
uu[IX(0, j)] = uu[IX(1, j)] * 0.4; uu[IX(N + 1, j)] = uu[IX(N, j)] * 0.4;
vv[IX(0, j)] = vv[IX(1, j)] * 0.4; vv[IX(N + 1, j)] = vv[IX(N, j)] * 0.4;
}
}
function seedVortex(cx: number, cy: number, dir: number): void {
const uu = u.current, vv = v.current, dd = d.current;
const u0v = u0.current, v0v = v0.current, d0v = d0.current;
uu.fill(0); vv.fill(0); dd.fill(0);
u0v.fill(0); v0v.fill(0); d0v.fill(0);
for (let j = 1; j <= N; j++) {
for (let i = 1; i <= N; i++) {
const dx = i - cx, dy = j - cy;
const r = Math.sqrt(dx * dx + dy * dy) || 0.0001;
const vTheta = r <= R_CORE ? OMEGA * r : OMEGA * (R_CORE * R_CORE) / r;
const idx = IX(i, j);
uu[idx] = dir * (-dy / r) * vTheta;
vv[idx] = dir * (dx / r) * vTheta;
const ring = Math.exp(-Math.pow((r - R_CORE * 1.15) / (R_CORE * 0.85), 2));
dd[idx] = ring * 1.4;
}
}
lifeStepRef.current = 0;
}
function step(dt: number): void {
u0.current.set(u.current); v0.current.set(v.current); d0.current.set(d.current);
advect("u", dt); u0.current.set(u.current);
advect("v", dt); v0.current.set(v.current);
advect("d", dt);
diffuse("u", 0.0016, dt);
diffuse("v", 0.0016, dt);
diffuse("d", 0.0016, dt);
bounds();
const uu = u.current, vv = v.current, dd = d.current;
const decay = 0.9905;
for (let k = 0; k < SIZE; k++) { uu[k] *= decay; vv[k] *= decay; dd[k] *= 0.988; }
lifeStepRef.current++;
if (lifeStepRef.current >= LIFE) {
cycleRef.current++;
const c = cycleRef.current;
const dir = c % 2 === 0 ? 1 : -1;
const cx = N * 0.5 + (c % 3 - 1) * N * 0.05;
const cy = N * 0.5 + ((c + 1) % 3 - 1) * N * 0.05;
seedVortex(cx, cy, dir);
}
}
function render(): void {
const ctx = ctxRef.current, cv = cvRef.current;
if (!ctx || !cv) return;
const img = ctx.createImageData(cv.width, cv.height);
const px = img.data;
const cellW = cv.width / N, cellH = cv.height / N;
const pal = palRef.current;
const dd = d.current;
for (let py = 0; py < cv.height; py++) {
const gy = Math.min(N - 1, (py / cellH) | 0);
for (let pxx = 0; pxx < cv.width; pxx++) {
const gx = Math.min(N - 1, (pxx / cellW) | 0);
const q = dd[IX(gx + 1, gy + 1)];
const o = (py * cv.width + pxx) * 4;
if (q <= 0) { px[o] = 23; px[o + 1] = 20; px[o + 2] = 26; px[o + 3] = 255; continue; }
const band = q > 0.62 ? 2 : q > 0.3 ? 1 : 0;
const c = pal[band];
const rr = parseInt(c.slice(1, 3), 16), gg = parseInt(c.slice(3, 5), 16), bb = parseInt(c.slice(5, 7), 16);
const a = Math.min(1, q);
px[o] = 23 + (rr - 23) * a; px[o + 1] = 20 + (gg - 20) * a; px[o + 2] = 26 + (bb - 26) * a; px[o + 3] = 255;
}
}
ctx.putImageData(img, 0, 0);
}
function frame(): void {
step(1 / 30);
render();
rafRef.current = requestAnimationFrame(frame);
}
function onDown(e: PtrEvt): void {
const field = fieldRef.current;
if (!field) return;
const r = field.getBoundingClientRect();
const gx = 1 + (e.clientX - r.left) / r.width * (N - 1);
const gy = 1 + (e.clientY - r.top) / r.height * (N - 1);
cycleRef.current++;
seedVortex(gx, gy, cycleRef.current % 2 === 0 ? 1 : -1);
if (reduced()) render();
}
function onKey(e: KeyEvt): void {
if (e.key !== "Enter" && e.key !== " ") return;
e.preventDefault();
cycleRef.current++;
seedVortex(N * 0.5, N * 0.5, cycleRef.current % 2 === 0 ? 1 : -1);
if (reduced()) render();
}
function onResize(): void { fit(); if (reduced()) render(); }
useEffect(() => {
const cv = cvRef.current;
if (!cv) return;
ctxRef.current = cv.getContext("2d", { willReadFrequently: true });
if (!ctxRef.current) return;
const root = rootRef.current;
if (root) {
const css = getComputedStyle(root);
const p0 = css.getPropertyValue("--dye-0").trim();
const p1 = css.getPropertyValue("--dye-1").trim();
const p2 = css.getPropertyValue("--dye-2").trim();
if (p0 && p1 && p2) palRef.current = [p0, p1, p2];
}
fit();
window.addEventListener("resize", onResize);
seedVortex(N * 0.5, N * 0.5, 1);
if (reduced()) {
if (root) root.classList.add("is-still");
for (let k = 0; k < 40; k++) step(1 / 30);
render();
} else {
rafRef.current = requestAnimationFrame(frame);
}
return () => {
window.removeEventListener("resize", onResize);
cancelAnimationFrame(rafRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<main className={styles.stage}>
<div className={styles.root} ref={rootRef} style={vars}>
<p className={styles.hint}>
<svg className={styles.ico} viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M128 216a88 88 0 1 1 88-88 8 8 0 0 1-16 0 72 72 0 1 0-72 72 8 8 0 0 1 0 16Z" opacity=".2"/><path d="M128 24a104.2 104.2 0 1 0 73.5 30.5 8 8 0 0 0-11.3 11.3A88 88 0 1 1 40 128a8 8 0 0 0-16 0A104 104 0 0 0 128 24Zm0 40a64 64 0 1 1-64 64 8 8 0 0 0 16 0 48 48 0 1 0 48-48 8 8 0 0 1 0-16Z"/></g></svg>
<span>중심은 강체처럼 함께 돌고 바깥은 멀어질수록 느려지며, 점성으로 시간이 갈수록 흐려져 사라집니다</span>
</p>
<div
className={styles.field}
ref={fieldRef}
role="application"
aria-label="소용돌이 감쇠 실험판"
tabIndex={0}
onPointerDown={onDown}
onKeyDown={onKey}
>
<canvas className={styles.cv} ref={cvRef}></canvas>
<b className={styles.badge} aria-hidden="true">32<span className={styles.badgeUnit}>격자</span></b>
</div>
</div>
</main>
);
}06 Vortex decay — Measured area 61.031% · moving frames 20/23Original by GODRICH · SCSS and React ship in the zip · Canvas Fluid Simulation: 9 Grid Effects
The post this demo lives in
Canvas Fluid Simulation: 9 Grid EffectsA canvas fluid simulation doesn't solve the Navier-Stokes equations — it advects, diffuses, and decays density and veloc See all demos in this post


