01Noise field contour map
Random values on a grid are smoothed into heights, then lines join points of equal height layer by layer.
Best forHero background on an about page, a divider band on a maps or travel service
stroke-dasharraystroke-dashoffsetanimation-fill-mode

<main class="stage">
<div class="nc is-demo" id="root">
<svg class="nc__art" id="art" viewBox="0 0 240 150" role="img" data-label="A map of random heights drawn as contour lines, seed {n}"></svg>
<div class="nc__bar">
<p class="nc__seed">
<svg xmlns="http://www.w3.org/2000/svg" class="nc__ic" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M216 64v128a24 24 0 0 1-24 24H64a24 24 0 0 1-24-24V64a24 24 0 0 1 24-24h128a24 24 0 0 1 24 24" opacity=".2"/><path d="M192 32H64a32 32 0 0 0-32 32v128a32 32 0 0 0 32 32h128a32 32 0 0 0 32-32V64a32 32 0 0 0-32-32m16 160a16 16 0 0 1-16 16H64a16 16 0 0 1-16-16V64a16 16 0 0 1 16-16h128a16 16 0 0 1 16 16ZM104 92a12 12 0 1 1-12-12a12 12 0 0 1 12 12m72 0a12 12 0 1 1-12-12a12 12 0 0 1 12 12m-72 72a12 12 0 1 1-12-12a12 12 0 0 1 12 12m36-36a12 12 0 1 1-12-12a12 12 0 0 1 12 12m36 36a12 12 0 1 1-12-12a12 12 0 0 1 12 12"/></g></svg>
Seed <b id="num">7</b>
</p>
<button class="nc__btn" type="button" id="again">
<svg xmlns="http://www.w3.org/2000/svg" class="nc__ic" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M107.14 98.8L128 128l-20.86 29.2A64 64 0 0 1 55.06 184H32V72h23.06a64 64 0 0 1 52.08 26.8m93.8-26.8a64 64 0 0 0-52.08 26.8L128 128l20.86 29.2a64 64 0 0 0 52.08 26.8H232V72Z" opacity=".2"/><path d="M237.66 178.34a8 8 0 0 1 0 11.32l-24 24a8 8 0 0 1-11.32-11.32L212.69 192h-11.75a72.12 72.12 0 0 1-58.59-30.15l-41.72-58.4A56.1 56.1 0 0 0 55.06 80H32a8 8 0 0 1 0-16h23.06a72.12 72.12 0 0 1 58.59 30.15l41.72 58.4A56.1 56.1 0 0 0 200.94 176h11.75l-10.35-10.34a8 8 0 0 1 11.32-11.32ZM143 107a8 8 0 0 0 11.16-1.86l1.2-1.67A56.1 56.1 0 0 1 200.94 80h11.75l-10.35 10.34a8 8 0 0 0 11.32 11.32l24-24a8 8 0 0 0 0-11.32l-24-24a8 8 0 0 0-11.32 11.32L212.69 64h-11.75a72.12 72.12 0 0 0-58.59 30.15l-1.2 1.67A8 8 0 0 0 143 107m-30 42a8 8 0 0 0-11.16 1.86l-1.2 1.67A56.1 56.1 0 0 1 55.06 176H32a8 8 0 0 0 0 16h23.06a72.12 72.12 0 0 0 58.59-30.15l1.2-1.67A8 8 0 0 0 113 149"/></g></svg>
<span class="nc__label">Regenerate</span>
</button>
<button class="nc__btn" type="button" id="copy" data-done="Copied">
<svg xmlns="http://www.w3.org/2000/svg" class="nc__ic" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M216 40v128h-48V88H88V40Z" opacity=".2"/><path d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8m-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z"/></g></svg>
<span class="nc__label">Copy SVG</span>
</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 노이즈 등고선 지도 — 값 노이즈로 높이를 만들고 마칭 스퀘어로 같은 높이를 잇는 선을 뽑는다.
// 경로 생성은 JS 지만 **그리는 연출은 CSS** 다: path 마다 pathLength="1" 로 길이를 1 로 정규화해
// stroke-dasharray: 1 · stroke-dashoffset 1 → 0 → -1 을 키프레임으로 돌린다.
// demo.py 는 CSS 애니메이션 시계로 24장을 뽑으므로 rAF 로 그리면 전부 같은 장면이 된다.
$duration: $dur-loop;
$easing: cubic-bezier(.7, 0, .85, .4);
$color: $subject-cream;
@include stage($stage-ink);
.nc { display: grid; justify-items: center; gap: $sp-3; width: 100%; }
.nc__art { display: block; width: clamp(176px, 60vw, 320px); height: auto; }
// 정적(미리보기를 뗀) 상태가 기본값 — 시드로 뽑힌 지도가 다 그려져 있다
.nc__line {
fill: none;
stroke: $color;
stroke-width: 1.4;
stroke-linecap: round;
stroke-dasharray: 1; // pathLength="1" 이라 1 = 경로 전체 길이
stroke-dashoffset: 0;
opacity: calc(.44 + var(--i) * .1);
}
.nc__bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: $sp-2; }
.nc__seed {
margin: 0;
display: inline-flex; align-items: center; gap: $sp-1;
color: rgba(255, 247, 230, .8);
font-weight: 700; font-size: clamp(9px, 2.4vw, 11px);
}
.nc__btn {
display: inline-flex; align-items: center; gap: $sp-1;
border: 0; border-radius: $r-pill;
padding: $sp-1 $sp-3;
background: $subject-cream; color: $subject-ink;
font-family: inherit; font-weight: 700; font-size: clamp(9px, 2.4vw, 11px);
cursor: pointer;
}
.nc__btn:focus-visible { outline: 3px solid $subject-blue; outline-offset: 2px; }
.nc__ic { width: 12px; height: 12px; flex: none; }
// ── 미리보기 루프: 아래 dashoffset 궤적은 「다시 생성」을 눌렀을 때 실제로 도는 것과 같은 그리기 연출이다.
// 양 끝(1 과 -1)이 둘 다 "감춰짐" 이라 한 바퀴가 끝날 때 튀지 않는다.
.nc.is-demo .nc__line {
animation-name: ncScan;
animation-duration: $duration;
animation-timing-function: $easing;
animation-iteration-count: infinite;
animation-fill-mode: backwards; // 지연 구간에 다 그려진 기본 상태가 번쩍이지 않게
animation-delay: calc(var(--i) * 110ms);
}
// 사람이 「다시 생성」을 누르면 루프를 떼고 한 번만 그린다
.nc.is-draw .nc__line {
animation-name: ncDraw;
animation-duration: $dur-enter;
animation-timing-function: $ease-out;
animation-iteration-count: 1;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * 110ms);
}
// 그리기는 느리게 시작해 끝에서 빨라지고 지우기는 그 반대다 — 프레임당 변화가 가장 큰 순간이
// 「선이 거의 다 있는」 장면에 오게 해서 poster(앞 장과 가장 크게 달라진 장)가 빈 지도로 뽑히지 않는다
@keyframes ncScan {
0% { stroke-dashoffset: 1; animation-timing-function: $easing; }
38% { stroke-dashoffset: 0; animation-timing-function: linear; }
50% { stroke-dashoffset: 0; animation-timing-function: $ease-out; }
86% { stroke-dashoffset: -1; }
100% { stroke-dashoffset: -1; }
}
@keyframes ncDraw {
from { stroke-dashoffset: 1; }
to { stroke-dashoffset: 0; }
}
@media (max-width: 340px) {
.nc { gap: $sp-2; }
.nc__ic { width: 10px; height: 10px; }
}
@media (prefers-reduced-motion: reduce) {
.nc.is-demo .nc__line,
.nc.is-draw .nc__line { animation: none !important; stroke-dashoffset: 0 !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);
}
.nc {
display: grid;
justify-items: center;
gap: 12px;
width: 100%;
}
.nc__art {
display: block;
width: clamp(176px, 60vw, 320px);
height: auto;
}
.nc__line {
fill: none;
stroke: #fff7e6;
stroke-width: 1.4;
stroke-linecap: round;
stroke-dasharray: 1;
stroke-dashoffset: 0;
opacity: calc(0.44 + var(--i) * 0.1);
}
.nc__bar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 8px;
}
.nc__seed {
margin: 0;
display: inline-flex;
align-items: center;
gap: 4px;
color: rgba(255, 247, 230, 0.8);
font-weight: 700;
font-size: clamp(9px, 2.4vw, 11px);
}
.nc__btn {
display: inline-flex;
align-items: center;
gap: 4px;
border: 0;
border-radius: 999px;
padding: 4px 12px;
background: #fff7e6;
color: #17141a;
font-family: inherit;
font-weight: 700;
font-size: clamp(9px, 2.4vw, 11px);
cursor: pointer;
}
.nc__btn:focus-visible {
outline: 3px solid #2f6df6;
outline-offset: 2px;
}
.nc__ic {
width: 12px;
height: 12px;
flex: none;
}
.nc.is-demo .nc__line {
animation-name: ncScan;
animation-duration: 2s;
animation-timing-function: cubic-bezier(0.7, 0, 0.85, 0.4);
animation-iteration-count: infinite;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * 110ms);
}
.nc.is-draw .nc__line {
animation-name: ncDraw;
animation-duration: 600ms;
animation-timing-function: ease-out;
animation-iteration-count: 1;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * 110ms);
}
@keyframes ncScan {
0% {
stroke-dashoffset: 1;
animation-timing-function: cubic-bezier(0.7, 0, 0.85, 0.4);
}
38% {
stroke-dashoffset: 0;
animation-timing-function: linear;
}
50% {
stroke-dashoffset: 0;
animation-timing-function: ease-out;
}
86% {
stroke-dashoffset: -1;
}
100% {
stroke-dashoffset: -1;
}
}
@keyframes ncDraw {
from {
stroke-dashoffset: 1;
}
to {
stroke-dashoffset: 0;
}
}
@media (max-width: 340px) {
.nc {
gap: 8px;
}
.nc__ic {
width: 10px;
height: 10px;
}
}
@media (prefers-reduced-motion: reduce) {
.nc.is-demo .nc__line,
.nc.is-draw .nc__line {
animation: none !important;
stroke-dashoffset: 0 !important;
}
}var root = document.getElementById('root');
var art = document.getElementById('art');
var num = document.getElementById('num');
var W = 240, H = 150, COLS = 9, ROWS = 6, LEVELS = 6, NX = 32, NY = 20;
var seed = 7;
// mulberry32 — 32비트 정수 Seed 하나로 언제나 같은 난수열을 돌려준다. 재현 가능한 생성의 뿌리
function mulberry32(a) {
return function () {
a = a + 0x6D2B79F5 | 0;
var t = Math.imul(a ^ a >>> 15, 1 | a);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
// 격자 꼭짓점에만 난수를 놓고 사이는 smoothstep 으로 이어 붙인다 (값 노이즈)
function makeField(s) {
var rand = mulberry32(s), lat = [], r, c;
for (r = 0; r <= ROWS; r++) { lat.push([]); for (c = 0; c <= COLS; c++) { lat[r].push(rand()); } }
return function (x, y) {
var gx = x * COLS, gy = y * ROWS;
var ix = Math.min(COLS - 1, Math.floor(gx)), iy = Math.min(ROWS - 1, Math.floor(gy));
var fx = gx - ix, fy = gy - iy;
var sx = fx * fx * (3 - 2 * fx), sy = fy * fy * (3 - 2 * fy);
var top = lat[iy][ix] + (lat[iy][ix + 1] - lat[iy][ix]) * sx;
var bot = lat[iy + 1][ix] + (lat[iy + 1][ix + 1] - lat[iy + 1][ix]) * sx;
return top + (bot - top) * sy;
};
}
// 칸 네 꼭짓점의 높이를 문턱과 견줘 어느 변에서 선이 드나드는지 고른다 (마칭 스퀘어 16가지)
var TABLE = [[], [[2, 3]], [[1, 2]], [[1, 3]], [[0, 1]], [[0, 3], [1, 2]], [[0, 2]], [[0, 3]],
[[0, 3]], [[0, 2]], [[0, 1], [2, 3]], [[0, 1]], [[1, 3]], [[1, 2]], [[2, 3]], []];
function cut(ax, ay, av, bx, by, bv, level) {
var t = (level - av) / (bv - av);
return ((ax + (bx - ax) * t) * W).toFixed(1) + ' ' + ((ay + (by - ay) * t) * H).toFixed(1);
}
function contour(field, level) {
var d = '', i, j, k;
for (j = 0; j < NY; j++) {
for (i = 0; i < NX; i++) {
var x0 = i / NX, y0 = j / NY, x1 = (i + 1) / NX, y1 = (j + 1) / NY;
var v = [field(x0, y0), field(x1, y0), field(x1, y1), field(x0, y1)];
var code = (v[0] > level ? 8 : 0) | (v[1] > level ? 4 : 0) | (v[2] > level ? 2 : 0) | (v[3] > level ? 1 : 0);
var pairs = TABLE[code];
if (!pairs.length) { continue; }
var edge = [cut(x0, y0, v[0], x1, y0, v[1], level), cut(x1, y0, v[1], x1, y1, v[2], level),
cut(x1, y1, v[2], x0, y1, v[3], level), cut(x0, y1, v[3], x0, y0, v[0], level)];
for (k = 0; k < pairs.length; k++) { d += 'M' + edge[pairs[k][0]] + 'L' + edge[pairs[k][1]]; }
}
}
return d;
}
function build() {
var field = makeField(seed), parts = [], i;
for (i = 0; i < LEVELS; i++) {
parts.push('<path class="nc__line" style="--i:' + i + '" pathLength="1" d="' + contour(field, 0.26 + i * 0.1) + '"/>');
}
art.innerHTML = parts.join('');
art.setAttribute('aria-label', art.getAttribute('data-label').replace('{n}', seed));
num.textContent = seed;
}
document.getElementById('again').addEventListener('click', function () {
seed = (seed * 7 + 13) % 991 + 1;
build();
root.classList.remove('is-demo');
root.classList.remove('is-draw');
void art.getBoundingClientRect().width; // 한 번 읽어 리플로를 일으켜야 같은 애니메이션이 처음부터 다시 돈다
root.classList.add('is-draw');
});
var copyBtn = document.getElementById('copy');
copyBtn.addEventListener('click', function () {
var label = copyBtn.querySelector('.nc__label');
var before = label.textContent;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(art.outerHTML).catch(function () {});
}
label.textContent = copyBtn.getAttribute('data-done');
setTimeout(function () { label.textContent = before; }, 1200);
});
build();// NoiseContourMap — vanilla 판(run/293/demo/01-generative-noise-contour/index.html) 의 React 포트.
// 값 노이즈로 높이를 만들고 마칭 스퀘어로 같은 높이를 잇는 선을 뽑는다. 경로는 JS, 그리는 연출은 CSS.
// 시드·격자 수·문턱은 vanilla 와 같은 값이다.
import { useMemo, useRef, useState } from "react";
import type { CSSProperties } from "react";
import styles from "./NoiseContourMap.module.scss";
export type NoiseContourMapProps = {
duration?: number;
easing?: string;
color?: string;
label?: string;
seedText?: string;
regenerateText?: string;
copyText?: string;
copiedText?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
// useRef 는 T | null 을 돌려준다. 처음부터 값이 있고 절대 비지 않는 상자는 이렇게 좁혀 쓴다
type Box<T> = { current: T };
const W = 240;
const H = 150;
const COLS = 9;
const ROWS = 6;
const LEVELS = 6;
const NX = 32;
const NY = 20;
// 칸 네 꼭짓점의 높이를 문턱과 견줘 어느 변에서 선이 드나드는지 고른다 (마칭 스퀘어 16가지)
const TABLE: number[][][] = [[], [[2, 3]], [[1, 2]], [[1, 3]], [[0, 1]], [[0, 3], [1, 2]], [[0, 2]], [[0, 3]],
[[0, 3]], [[0, 2]], [[0, 1], [2, 3]], [[0, 1]], [[1, 3]], [[1, 2]], [[2, 3]], []];
// mulberry32 — 32비트 정수 시드 하나로 언제나 같은 난수열을 돌려준다. 재현 가능한 생성의 뿌리
function mulberry32(a: number): () => number {
return function (): number {
a = a + 0x6D2B79F5 | 0;
let t = Math.imul(a ^ a >>> 15, 1 | a);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
// 격자 꼭짓점에만 난수를 놓고 사이는 smoothstep 으로 이어 붙인다 (값 노이즈)
function makeField(s: number): (x: number, y: number) => number {
const rand = mulberry32(s);
const lat: number[][] = [];
for (let r = 0; r <= ROWS; r++) {
const row: number[] = [];
for (let c = 0; c <= COLS; c++) { row.push(rand()); }
lat.push(row);
}
return function (x: number, y: number): number {
const gx = x * COLS;
const gy = y * ROWS;
const ix = Math.min(COLS - 1, Math.floor(gx));
const iy = Math.min(ROWS - 1, Math.floor(gy));
const fx = gx - ix;
const fy = gy - iy;
const sx = fx * fx * (3 - 2 * fx);
const sy = fy * fy * (3 - 2 * fy);
const top = lat[iy][ix] + (lat[iy][ix + 1] - lat[iy][ix]) * sx;
const bot = lat[iy + 1][ix] + (lat[iy + 1][ix + 1] - lat[iy + 1][ix]) * sx;
return top + (bot - top) * sy;
};
}
function cut(ax: number, ay: number, av: number, bx: number, by: number, bv: number, level: number): string {
const t = (level - av) / (bv - av);
return ((ax + (bx - ax) * t) * W).toFixed(1) + " " + ((ay + (by - ay) * t) * H).toFixed(1);
}
function contour(field: (x: number, y: number) => number, level: number): string {
let d = "";
for (let j = 0; j < NY; j++) {
for (let i = 0; i < NX; i++) {
const x0 = i / NX, y0 = j / NY, x1 = (i + 1) / NX, y1 = (j + 1) / NY;
const v = [field(x0, y0), field(x1, y0), field(x1, y1), field(x0, y1)];
const code = (v[0] > level ? 8 : 0) | (v[1] > level ? 4 : 0) | (v[2] > level ? 2 : 0) | (v[3] > level ? 1 : 0);
const pairs = TABLE[code];
if (!pairs.length) { continue; }
const edge = [cut(x0, y0, v[0], x1, y0, v[1], level), cut(x1, y0, v[1], x1, y1, v[2], level),
cut(x1, y1, v[2], x0, y1, v[3], level), cut(x0, y1, v[3], x0, y0, v[0], level)];
for (let k = 0; k < pairs.length; k++) { d += "M" + edge[pairs[k][0]] + "L" + edge[pairs[k][1]]; }
}
}
return d;
}
export default function NoiseContourMap({
duration = 2000,
easing = "cubic-bezier(.7, 0, .85, .4)",
color = "#fff7e6",
label = "A map of random heights drawn as contour lines, seed {n}",
seedText = "Seed",
regenerateText = "Regenerate",
copyText = "Copy SVG",
copiedText = "Copied",
}: NoiseContourMapProps) {
const artRef = useRef<SVGSVGElement | null>(null);
const timerRef = useRef<number>(0) as Box<number>;
const [seed, setSeed] = useState(7);
const [mode, setMode] = useState("demo");
const [copyLabel, setCopyLabel] = useState(copyText);
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--color": color };
// 시드가 바뀔 때만 다시 계산한다 — 같은 시드면 언제나 같은 경로 문자열이 나온다
const paths = useMemo(() => {
const field = makeField(seed);
const out: string[] = [];
for (let i = 0; i < LEVELS; i++) { out.push(contour(field, 0.26 + i * 0.1)); }
return out;
}, [seed]);
function regenerate(): void {
setSeed((prev: number) => (prev * 7 + 13) % 991 + 1);
setMode("draw");
}
function copySvg(): void {
const art = artRef.current;
if (!art) { return; }
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(art.outerHTML).catch(function () {});
}
setCopyLabel(copiedText);
clearTimeout(timerRef.current);
timerRef.current = window.setTimeout(() => setCopyLabel(copyText), 1200);
}
const rootClass = `${styles.nc} ${mode === "demo" ? styles.isDemo : styles.isDraw}`;
return (
<div className={rootClass} style={vars}>
<svg
ref={artRef}
className={styles.art}
viewBox={`0 0 ${W} ${H}`}
role="img"
aria-label={label.replace("{n}", String(seed))}
>
{paths.map((d: string, i: number) => (
<path key={i} className={styles.line} style={{ "--i": i } as CSSProperties} pathLength={1} d={d} />
))}
</svg>
<div className={styles.bar}>
<p className={styles.seed}>{seedText} <b>{seed}</b></p>
<button className={styles.btn} type="button" onClick={regenerate}>{regenerateText}</button>
<button className={styles.btn} type="button" onClick={copySvg}>{copyLabel}</button>
</div>
</div>
);
}01 Noise field contour map — Measured area 11.925% · moving frames 16/23Original by GODRICH · SCSS and React ship in the zip · CSS Background Pattern Generator: 9 Seeded Scenes
The post this demo lives in
CSS Background Pattern Generator: 9 Seeded ScenesA CSS background pattern generator turns one number into a drawing instead of an image file. Feed these nine the same se See all demos in this post


