06Loader an Erosion-thickness Value Eats into a Noise Ring
The inner radius of a ring drawn over a 2D noise field is driven by an erosion-thickness value tied to progress, so the noise eats jaggedly inward and the ring thins.
Best forSearch-results wait screens and long-form submit loaders
LATTICE_NfieldNoiseevenodd

<main class="stage">
<div class="ld" id="ld">
<p class="ld__hint">
<svg class="ld__ico" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M232 56v56a8 8 0 0 1-16 0V91.3l-25.6 25.7A80 80 0 1 1 174 60a8 8 0 1 1-9 13.2A64 64 0 1 0 179.7 128H216a8 8 0 0 1 0 16h-56a8 8 0 0 1-8-8V80a8 8 0 0 1 16 0v20.7L192.7 76A80.1 80.1 0 0 0 64 128a8 8 0 0 1-16 0a96 96 0 0 1 163.6-68.3L224 71.3V56a8 8 0 0 1 8 8" opacity=".2"/><path d="M224 48a8 8 0 0 0-8 8v15.3l-11.7-11.6a96 96 0 1 0 27.6 51.6a8 8 0 0 0-15.8 2.5a80 80 0 1 1-23-43l-25.7 25.7A8 8 0 0 0 173 112h56a8 8 0 0 0 8-8V56a8 8 0 0 0-13-8"/></g></svg>
<span>Click or press the space bar to pause or restart</span>
</p>
<div class="ld__field" id="field" role="application" aria-label="Noise ring erosion test panel" tabindex="0">
<canvas class="ld__cv" id="cv"></canvas>
<b class="ld__badge" aria-hidden="true"><span class="ld__badgeNum" id="pct">0%</span><span class="ld__badgeUnit">Erode</span></b>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 노이즈 링 로더 — 두 옥타브 값-노이즈로 링의 바깥 경계를 진행률만큼 갉아먹는다(침식 두께 = 진행률).
// 움직임은 전부 캔버스 rAF 루프 안에 있다. CSS 는 무대·판·배지만 맡는다(@keyframes 0개 — 077 선례와 같은 이유).
$duration: $dur-loop;
$easing: $ease-pop;
$color: $subject-blue-deep;
@include stage($stage-yellow);
.ld {
--paper: #{$subject-cream};
--ring: #{rgba($subject-blue, .82)};
--ring-edge: #{$subject-blue-deep};
--inner: #{$subject-cream};
display: flex; flex-direction: column; gap: $sp-2;
width: 100%; max-width: 424px;
}
.ld__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-ink;
}
.ld__ico { width: 16px; height: 16px; flex: 0 0 auto; color: $subject-blue-deep; }
.ld__field {
position: relative; height: 208px;
border-radius: $r-card; overflow: hidden;
background: $subject-cream;
box-shadow: inset 0 0 0 1px rgba($subject-ink, .16);
cursor: pointer;
}
.ld__field:focus-visible { outline: 2px solid $subject-blue-deep; outline-offset: 2px; }
.ld__cv { display: block; width: 100%; height: 100%; }
.ld__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;
}
.ld__badgeNum { font-size: 13px; color: $subject-blue-light; }
.ld__badgeUnit { font-weight: 700; }
@media (max-width: 340px) {
.ld { gap: $sp-1; }
.ld__field { height: 124px; }
.ld__badge { font-size: 10px; padding: 0 $sp-1; }
.ld__badgeNum { font-size: 11px; }
}
// reduce — 루프를 시작하지 않고 진행률 62% 언저리에서 멈춘 한 장만 그린다.
@media (prefers-reduced-motion: reduce) {
.ld.is-still .ld__field { cursor: default !important; }
.ld.is-still .ld__badge { opacity: .92 !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.ld {
--paper: #fff7e6;
--ring: rgba(47, 109, 246, 0.82);
--ring-edge: #0a4fe8;
--inner: #fff7e6;
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
max-width: 424px;
}
.ld__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: #17141a;
}
.ld__ico {
width: 16px;
height: 16px;
flex: 0 0 auto;
color: #0a4fe8;
}
.ld__field {
position: relative;
height: 208px;
border-radius: 16px;
overflow: hidden;
background: #fff7e6;
box-shadow: inset 0 0 0 1px rgba(23, 20, 26, 0.16);
cursor: pointer;
}
.ld__field:focus-visible {
outline: 2px solid #0a4fe8;
outline-offset: 2px;
}
.ld__cv {
display: block;
width: 100%;
height: 100%;
}
.ld__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;
}
.ld__badgeNum {
font-size: 13px;
color: #5b8cf8;
}
.ld__badgeUnit {
font-weight: 700;
}
@media (max-width: 340px) {
.ld {
gap: 4px;
}
.ld__field {
height: 124px;
}
.ld__badge {
font-size: 10px;
padding: 0 4px;
}
.ld__badgeNum {
font-size: 11px;
}
}
@media (prefers-reduced-motion: reduce) {
.ld.is-still .ld__field {
cursor: default !important;
}
.ld.is-still .ld__badge {
opacity: 0.92 !important;
}
}// 노이즈 링 로더 — 두 옥타브 값-노이즈(LCG 격자점 보간)를 각도에 따라 흐르게 하고, 그 값에
// 진행률을 곱한 만큼 링의 바깥 경계를 안쪽으로 갉아먹는다. Erode 두께가 곧 진행률이다.
var root = document.getElementById('ld');
var field = document.getElementById('field');
var cv = document.getElementById('cv');
var ctx = cv.getContext('2d');
var pctEl = document.getElementById('pct');
var css = getComputedStyle(root);
var PAPER = css.getPropertyValue('--paper').trim();
var RING = css.getPropertyValue('--ring').trim();
var RING_EDGE = css.getPropertyValue('--ring-edge').trim();
var INNER = css.getPropertyValue('--inner').trim();
function makeRng(seed) {
var s = seed >>> 0;
return function () {
s = (1103515245 * s + 12345) >>> 0;
return (s >>> 8) / 16777216;
};
}
var LATTICE_N = 24;
var rng = makeRng(20260926);
var lattice = [];
for (var i = 0; i < LATTICE_N; i++) lattice.push(rng());
function smooth(f) { return f * f * (3 - 2 * f); }
function valueNoise(x) {
var xi = ((x % LATTICE_N) + LATTICE_N) % LATTICE_N;
var i0 = Math.floor(xi);
var i1 = (i0 + 1) % LATTICE_N;
var f = smooth(xi - i0);
return lattice[i0] * (1 - f) + lattice[i1] * f;
}
function fieldNoise(theta, sec) {
var x1 = (theta / (Math.PI * 2)) * LATTICE_N + sec * 1.6;
var x2 = (theta / (Math.PI * 2)) * LATTICE_N * 2.3 + 40 - sec * 2.4;
return valueNoise(x1) * 0.68 + valueNoise(x2) * 0.32;
}
var LOOP = 2.6;
var SAMPLES = 96;
var W = 0, H = 0, dpr = 1, cxp = 0, cyp = 0, outerR = 0, innerR = 0, maxErode = 0;
function fit() {
var r = field.getBoundingClientRect();
dpr = window.devicePixelRatio || 1;
W = r.width; H = r.height;
cv.width = Math.round(W * dpr); cv.height = Math.round(H * dpr);
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
cxp = W * 0.5; cyp = H * 0.5;
outerR = Math.min(W, H) * 0.42;
innerR = outerR * 0.52;
maxErode = outerR - innerR;
}
function draw(sec) {
var t = sec % LOOP;
var p = t / LOOP;
ctx.fillStyle = PAPER;
ctx.fillRect(0, 0, W, H);
ctx.beginPath();
for (var i = 0; i <= SAMPLES; i++) {
var theta = (i / SAMPLES) * Math.PI * 2;
var n = fieldNoise(theta, sec);
var r = outerR - p * maxErode * n;
var x = cxp + Math.cos(theta) * r;
var y = cyp + Math.sin(theta) * r;
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
}
ctx.closePath();
ctx.moveTo(cxp + innerR, cyp);
ctx.arc(cxp, cyp, innerR, 0, Math.PI * 2, true);
ctx.fillStyle = RING;
ctx.fill('evenodd');
ctx.beginPath();
for (var j = 0; j <= SAMPLES; j++) {
var th = (j / SAMPLES) * Math.PI * 2;
var nn = fieldNoise(th, sec);
var rr = outerR - p * maxErode * nn;
var xx = cxp + Math.cos(th) * rr;
var yy = cyp + Math.sin(th) * rr;
if (j === 0) ctx.moveTo(xx, yy); else ctx.lineTo(xx, yy);
}
ctx.closePath();
ctx.strokeStyle = RING_EDGE;
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = INNER;
ctx.beginPath();
ctx.arc(cxp, cyp, innerR * 0.86, 0, Math.PI * 2);
ctx.fill();
pctEl.textContent = Math.round(p * 100) + '%';
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var paused = false;
var t0 = 0;
var raf = 0;
function togglePause() {
paused = !paused;
root.classList.toggle('is-paused', paused);
}
function restart() {
t0 = performance.now();
draw(0);
}
field.addEventListener('click', function () { togglePause(); });
field.addEventListener('keydown', function (e) {
if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); togglePause(); }
else if (e.key === 'r' || e.key === 'R') { e.preventDefault(); restart(); }
});
window.addEventListener('resize', function () {
fit();
if (paused || reduce) draw(((performance.now() - t0) / 1000));
});
function frame(now) {
if (!paused) draw((now - t0) / 1000);
raf = requestAnimationFrame(frame);
}
t0 = performance.now();
fit();
if (reduce) {
root.classList.add('is-still');
draw(LOOP * 0.62);
} else {
raf = requestAnimationFrame(frame);
}// NoiseErosion — vanilla 판(run/395/demo/06-canvas-loader-noise-flow-ring-erosion/index.html) 의 React 포트.
// 두 옥타브 값-노이즈(LCG 격자점 보간)가 각도를 따라 흐르고, 그 값에 진행률을 곱해 링의 바깥 경계를 갉아먹는다.
import { useEffect, useRef } from "react";
import type { CSSProperties } from "react";
import styles from "./NoiseErosion.module.scss";
export type NoiseErosionProps = {
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 };
function makeRng(seed: number): () => number {
let s = seed >>> 0;
return function () {
s = (1103515245 * s + 12345) >>> 0;
return (s >>> 8) / 16777216;
};
}
const LATTICE_N = 24;
const LOOP = 2.6;
const SAMPLES = 96;
const FIELD_LABEL = "노이즈 링 침식 실험판";
function makeLattice(): number[] {
const rng = makeRng(20260926);
const list: number[] = [];
for (let i = 0; i < LATTICE_N; i++) list.push(rng());
return list;
}
function smooth(f: number): number {
return f * f * (3 - 2 * f);
}
export default function NoiseErosion({
duration = "2.6s",
easing = "cubic-bezier(.2, 1.4, .4, 1)", // vanilla $easing: $ease-pop
color = "#0a4fe8", // vanilla $color: $subject-blue-deep
}: NoiseErosionProps) {
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 pctRef = useRef<HTMLSpanElement | null>(null);
const sizeRef = useRef({ w: 0, h: 0, dpr: 1, cx: 0, cy: 0, outerR: 0, innerR: 0, maxErode: 0 }) as Box<{ w: number; h: number; dpr: number; cx: number; cy: number; outerR: number; innerR: number; maxErode: number }>;
const latticeRef = useRef<number[]>(makeLattice()) as Box<number[]>;
const pausedRef = useRef(false) as Box<boolean>;
const t0Ref = 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 valueNoise(x: number): number {
const lattice = latticeRef.current;
const xi = ((x % LATTICE_N) + LATTICE_N) % LATTICE_N;
const i0 = Math.floor(xi);
const i1 = (i0 + 1) % LATTICE_N;
const f = smooth(xi - i0);
return lattice[i0] * (1 - f) + lattice[i1] * f;
}
function fieldNoise(theta: number, sec: number): number {
const x1 = (theta / (Math.PI * 2)) * LATTICE_N + sec * 1.6;
const x2 = (theta / (Math.PI * 2)) * LATTICE_N * 2.3 + 40 - sec * 2.4;
return valueNoise(x1) * 0.68 + valueNoise(x2) * 0.32;
}
function fit(): void {
const field = fieldRef.current;
const cv = cvRef.current;
const ctx = ctxRef.current;
if (!field || !cv || !ctx) return;
const r = field.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
const size = sizeRef.current;
size.w = r.width; size.h = r.height; size.dpr = dpr;
cv.width = Math.round(r.width * dpr);
cv.height = Math.round(r.height * dpr);
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
size.cx = r.width * 0.5; size.cy = r.height * 0.5;
size.outerR = Math.min(r.width, r.height) * 0.42;
size.innerR = size.outerR * 0.52;
size.maxErode = size.outerR - size.innerR;
}
function draw(sec: number): void {
const ctx = ctxRef.current;
const root = rootRef.current;
if (!ctx || !root) return;
const size = sizeRef.current;
const W = size.w, H = size.h;
const t = sec % LOOP;
const p = t / LOOP;
const cssv = (n: string) => getComputedStyle(root).getPropertyValue(n).trim();
const PAPER = cssv("--paper"), RING = cssv("--ring"), RING_EDGE = cssv("--ring-edge"), INNER = cssv("--inner");
ctx.fillStyle = PAPER;
ctx.fillRect(0, 0, W, H);
ctx.beginPath();
for (let i = 0; i <= SAMPLES; i++) {
const theta = (i / SAMPLES) * Math.PI * 2;
const n = fieldNoise(theta, sec);
const r = size.outerR - p * size.maxErode * n;
const x = size.cx + Math.cos(theta) * r;
const y = size.cy + Math.sin(theta) * r;
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
}
ctx.closePath();
ctx.moveTo(size.cx + size.innerR, size.cy);
ctx.arc(size.cx, size.cy, size.innerR, 0, Math.PI * 2, true);
ctx.fillStyle = RING;
ctx.fill("evenodd");
ctx.beginPath();
for (let j = 0; j <= SAMPLES; j++) {
const th = (j / SAMPLES) * Math.PI * 2;
const nn = fieldNoise(th, sec);
const rr = size.outerR - p * size.maxErode * nn;
const xx = size.cx + Math.cos(th) * rr;
const yy = size.cy + Math.sin(th) * rr;
if (j === 0) ctx.moveTo(xx, yy); else ctx.lineTo(xx, yy);
}
ctx.closePath();
ctx.strokeStyle = RING_EDGE;
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = INNER;
ctx.beginPath();
ctx.arc(size.cx, size.cy, size.innerR * 0.86, 0, Math.PI * 2);
ctx.fill();
if (pctRef.current) pctRef.current.textContent = Math.round(p * 100) + "%";
}
function togglePause(): void {
pausedRef.current = !pausedRef.current;
const root = rootRef.current;
if (root) root.classList.toggle("is-paused", pausedRef.current);
}
function restart(): void {
t0Ref.current = performance.now();
draw(0);
}
function onKey(e: KeyEvt): void {
if (e.key === " " || e.key === "Enter") { e.preventDefault(); togglePause(); }
else if (e.key === "r" || e.key === "R") { e.preventDefault(); restart(); }
}
function onClick(): void {
togglePause();
}
function onResize(): void {
fit();
if (pausedRef.current || reduced()) draw((performance.now() - t0Ref.current) / 1000);
}
function frame(now: number): void {
if (!pausedRef.current) draw((now - t0Ref.current) / 1000);
rafRef.current = requestAnimationFrame(frame);
}
useEffect(() => {
const cv = cvRef.current;
if (!cv) return;
ctxRef.current = cv.getContext("2d");
if (!ctxRef.current) return;
t0Ref.current = performance.now();
fit();
window.addEventListener("resize", onResize);
if (reduced()) {
const root = rootRef.current;
if (root) root.classList.add("is-still");
draw(LOOP * 0.62);
} else {
rafRef.current = requestAnimationFrame(frame);
}
return () => {
window.removeEventListener("resize", onResize);
cancelAnimationFrame(rafRef.current);
};
}, []);
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="M232 56v56a8 8 0 0 1-16 0V91.3l-25.6 25.7A80 80 0 1 1 174 60a8 8 0 1 1-9 13.2A64 64 0 1 0 179.7 128H216a8 8 0 0 1 0 16h-56a8 8 0 0 1-8-8V80a8 8 0 0 1 16 0v20.7L192.7 76A80.1 80.1 0 0 0 64 128a8 8 0 0 1-16 0a96 96 0 0 1 163.6-68.3L224 71.3V56a8 8 0 0 1 8 8" opacity=".2"/><path d="M224 48a8 8 0 0 0-8 8v15.3l-11.7-11.6a96 96 0 1 0 27.6 51.6a8 8 0 0 0-15.8 2.5a80 80 0 1 1-23-43l-25.7 25.7A8 8 0 0 0 173 112h56a8 8 0 0 0 8-8V56a8 8 0 0 0-13-8"/></g></svg>
<span>클릭하거나 스페이스바를 누르면 멈추거나 다시 갑니다</span>
</p>
<div
className={styles.field}
ref={fieldRef}
role="application"
aria-label={FIELD_LABEL}
tabIndex={0}
onClick={onClick}
onKeyDown={onKey}
>
<canvas className={styles.cv} ref={cvRef}></canvas>
<b className={styles.badge} aria-hidden="true"><span className={styles.badgeNum} ref={pctRef}>0%</span><span className={styles.badgeUnit}>침식</span></b>
</div>
</div>
</main>
);
}06 Loader an Erosion-thickness Value Eats into a Noise Ring — Measured area 8.508% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · 9 CSS Loading Animation Patterns, Canvas Physics
The post this demo lives in
9 CSS Loading Animation Patterns, Canvas PhysicsA css loading animation: A 0.92 damping constant shrinks the gravity loader's bounce; the automaton loader turns one rul See all demos in this post
If you like this effect - similar demos
Loaders05 Icon progress ring — an indicator whose circular progress value fills with the pulled distance and morphs into a checkmark once completePull to Refresh CSS: 9 Loading Patterns
Loaders02 Loader Whose Wireframe Vertices Settle Into Place With the Progress ValueCSS 3D Cube Animation Loaders, 9 Patterns
Loaders01 Halo Ring AI Loader Whose Hue Value Turns Toward DoneAI Loading Animation: 9 Patterns by One Value