08Camouflage Pattern Built From a Cell-size Variance Value
Seed density value differs from region to region, so the cell-size variance value grows large, and the result reads as an irregular animal-camouflage pattern.
Best forOutdoor and fashion product background
NOISE_WARP_PXvalueNoise2DwarpCoord

<main class="stage">
<div class="vd is-demo" id="vdRoot">
<canvas class="vd__canvas" id="vdCanvas" width="480" height="300"></canvas>
<p class="vd__caption">Camouflage Pattern Built From a Cell-size Variance Value</p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
@include stage($stage-paper);
.vd {
position: relative;
width: min(92vw, calc(160vh - 12.8vw));
aspect-ratio: 480 / 300;
margin: 0 auto;
border-radius: $r-card;
overflow: hidden;
box-shadow: $shadow-raised;
}
.vd__canvas {
display: block;
width: 100%;
height: 100%;
}
.vd__caption {
position: absolute;
left: $sp-3;
bottom: $sp-3;
max-width: 72%;
margin: 0;
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(255, 247, 230, .85);
color: $subject-ink;
font-weight: 500;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
.vd__step {
position: absolute;
right: $sp-3;
top: $sp-3;
margin: 0;
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(255, 247, 230, .85);
color: $subject-ink;
font-weight: 700;
font-size: 11px;
font-variant-numeric: tabular-nums;
pointer-events: none;
}
@media (max-width: 340px) {
.vd__caption, .vd__step { font-size: 10px; padding: $sp-1 $sp-2; }
}
@media (prefers-reduced-motion: reduce) {
.vd { cursor: default; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.vd {
position: relative;
width: min(92vw, 160vh - 12.8vw);
aspect-ratio: 480/300;
margin: 0 auto;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.vd__canvas {
display: block;
width: 100%;
height: 100%;
}
.vd__caption {
position: absolute;
left: 12px;
bottom: 12px;
max-width: 72%;
margin: 0;
padding: 4px 12px;
border-radius: 999px;
background: rgba(255, 247, 230, 0.85);
color: #17141a;
font-weight: 500;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
.vd__step {
position: absolute;
right: 12px;
top: 12px;
margin: 0;
padding: 4px 12px;
border-radius: 999px;
background: rgba(255, 247, 230, 0.85);
color: #17141a;
font-weight: 700;
font-size: 11px;
font-variant-numeric: tabular-nums;
pointer-events: none;
}
@media (max-width: 340px) {
.vd__caption, .vd__step {
font-size: 10px;
padding: 4px 8px;
}
}
@media (prefers-reduced-motion: reduce) {
.vd {
cursor: default;
}
}(function () {
var root = document.getElementById('vdRoot');
var canvas = document.getElementById('vdCanvas');
var ctx = canvas.getContext('2d');
var wrap = canvas.parentElement;
var CALC_W = 160, CALC_H = 100;
var LOOP_MS = 2000;
var NOISE_WARP_PX = 13;
var WARP_FREQ = Math.PI * 2 / LOOP_MS;
function seedRand(seed) {
var s = seed >>> 0;
return function () { s = (s * 1664525 + 1013904223) >>> 0; return s / 4294967296; };
}
var rand = seedRand(409081);
var off = document.createElement('canvas');
off.width = CALC_W; off.height = CALC_H;
var octx = off.getContext('2d');
var offImg = octx.createImageData(CALC_W, CALC_H);
var offBuf = offImg.data;
function hexToRgb(hex) {
var v = parseInt(hex.slice(1), 16);
return [(v >> 16) & 255, (v >> 8) & 255, v & 255];
}
var NEI = -1, ND = 0, ND2 = 0;
function nearestTwo(px, py, arr) {
var bd = Infinity, bd2 = Infinity, bi = -1;
for (var i = 0; i < arr.length; i += 1) {
var dx = px - arr[i].x, dy = py - arr[i].y, d = dx * dx + dy * dy;
if (d < bd) { bd2 = bd; bd = d; bi = i; } else if (d < bd2) { bd2 = d; }
}
NEI = bi; ND = Math.sqrt(bd); ND2 = Math.sqrt(bd2);
}
var camoPalette = ['#4cd4a6', '#6ec8ff', '#b9a0ff', '#17141a'];
var paletteRgb = {};
camoPalette.forEach(function (h) { paletteRgb[h] = hexToRgb(h); });
var MACRO_COUNT = 4;
var macroCenters = [];
for (var m0 = 0; m0 < MACRO_COUNT; m0 += 1) {
macroCenters.push({ x: rand() * CALC_W, y: rand() * CALC_H, spread: 10 + rand() * 26 });
}
var SEED_COUNT08 = 46;
var seeds = [];
for (var i8 = 0; i8 < SEED_COUNT08; i8 += 1) {
var mc = macroCenters[i8 % MACRO_COUNT];
seeds.push({
x: Math.min(CALC_W, Math.max(0, mc.x + (rand() - 0.5) * mc.spread * 2)),
y: Math.min(CALC_H, Math.max(0, mc.y + (rand() - 0.5) * mc.spread * 2)),
c: camoPalette[i8 % camoPalette.length]
});
}
var NOISE_GRID_W = 9, NOISE_GRID_H = 6;
var noiseGridX = [], noiseGridY = [];
for (var n0 = 0; n0 < NOISE_GRID_W * NOISE_GRID_H; n0 += 1) {
noiseGridX.push(rand()); noiseGridY.push(rand());
}
function valueNoise2D(gx, gy, arr) {
var x0 = Math.floor(gx), y0 = Math.floor(gy);
var x1 = Math.min(NOISE_GRID_W - 1, x0 + 1), y1 = Math.min(NOISE_GRID_H - 1, y0 + 1);
var tx = gx - x0, ty = gy - y0;
var v00 = arr[y0 * NOISE_GRID_W + x0], v10 = arr[y0 * NOISE_GRID_W + x1];
var v01 = arr[y1 * NOISE_GRID_W + x0], v11 = arr[y1 * NOISE_GRID_W + x1];
var top = v00 + (v10 - v00) * tx, bot = v01 + (v11 - v01) * tx;
return top + (bot - top) * ty;
}
function warpCoord(x, y, breathe) {
var gx = x / CALC_W * (NOISE_GRID_W - 1), gy = y / CALC_H * (NOISE_GRID_H - 1);
var n1 = valueNoise2D(gx, gy, noiseGridX), n2 = valueNoise2D(gx, gy, noiseGridY);
return { x: x + (n1 - 0.5) * 2 * NOISE_WARP_PX * breathe, y: y + (n2 - 0.5) * 2 * NOISE_WARP_PX * breathe };
}
function renderField(t) {
var breathe = 0.55 + 0.45 * Math.sin(t * WARP_FREQ);
var idx = 0;
for (var y = 0; y < CALC_H; y += 1) {
for (var x = 0; x < CALC_W; x += 1) {
var w = warpCoord(x + 0.5, y + 0.5, breathe);
nearestTwo(w.x, w.y, seeds);
var rgb = paletteRgb[seeds[NEI].c];
var edge = ND2 - ND;
var dark = edge < 1.6 ? 0.55 + edge / 3.6 : 1;
offBuf[idx] = rgb[0] * dark; offBuf[idx + 1] = rgb[1] * dark; offBuf[idx + 2] = rgb[2] * dark; offBuf[idx + 3] = 255;
idx += 4;
}
}
}
var cw = 480, ch = 300;
function fit() {
var r = wrap.getBoundingClientRect();
cw = Math.max(1, Math.round(r.width));
ch = Math.max(1, Math.round(r.height));
canvas.width = cw; canvas.height = ch;
draw(lastElapsed);
}
var lastElapsed = 0;
function draw(elapsed) {
lastElapsed = elapsed;
renderField(elapsed);
octx.putImageData(offImg, 0, 0);
ctx.imageSmoothingEnabled = false;
ctx.clearRect(0, 0, cw, ch);
ctx.drawImage(off, 0, 0, CALC_W, CALC_H, 0, 0, cw, ch);
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var playing = !reduce;
var elapsed = reduce ? LOOP_MS * 0.5 : 0;
if (reduce) { root.classList.remove('is-demo'); }
var lastTs = null;
function tick(ts) {
if (lastTs === null) lastTs = ts;
var dt = ts - lastTs;
lastTs = ts;
if (playing) {
elapsed += dt;
if (elapsed >= LOOP_MS) elapsed -= LOOP_MS;
}
draw(elapsed);
requestAnimationFrame(tick);
}
fit();
window.addEventListener('resize', fit);
draw(elapsed);
requestAnimationFrame(tick);
})();import { useEffect, useRef } from "react";
import styles from "./VoronoiOrganicCamouflagePattern.module.scss";
export default function VoronoiOrganicCamouflagePattern() {
const rootRef = useRef<HTMLDivElement>(null);
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const root = rootRef.current;
const canvas = canvasRef.current;
if (!root || !canvas) return;
const ctx = canvas.getContext("2d");
if (!ctx) return;
const wrap = canvas.parentElement as HTMLElement;
const CALC_W = 160, CALC_H = 100;
const LOOP_MS = 2000;
const NOISE_WARP_PX = 13;
const WARP_FREQ = (Math.PI * 2) / LOOP_MS;
function seedRand(seed: number) {
let s = seed >>> 0;
return function () { s = (s * 1664525 + 1013904223) >>> 0; return s / 4294967296; };
}
const rand = seedRand(409081);
const off = document.createElement("canvas");
off.width = CALC_W; off.height = CALC_H;
const octx = off.getContext("2d") as CanvasRenderingContext2D;
const offImg = octx.createImageData(CALC_W, CALC_H);
const offBuf = offImg.data;
function hexToRgb(hex: string): [number, number, number] {
const v = parseInt(hex.slice(1), 16);
return [(v >> 16) & 255, (v >> 8) & 255, v & 255];
}
type Vec = { x: number; y: number };
let NEI = -1, ND = 0, ND2 = 0;
function nearestTwo<T extends Vec>(px: number, py: number, arr: T[]): void {
let bd = Infinity, bd2 = Infinity, bi = -1;
for (let i = 0; i < arr.length; i += 1) {
const dx = px - arr[i].x, dy = py - arr[i].y, d = dx * dx + dy * dy;
if (d < bd) { bd2 = bd; bd = d; bi = i; } else if (d < bd2) { bd2 = d; }
}
NEI = bi; ND = Math.sqrt(bd); ND2 = Math.sqrt(bd2);
}
type Seed = { x: number; y: number; c: string };
const camoPalette = ["#4cd4a6", "#6ec8ff", "#b9a0ff", "#17141a"];
const paletteRgb: Record<string, [number, number, number]> = {};
camoPalette.forEach((h) => { paletteRgb[h] = hexToRgb(h); });
const MACRO_COUNT = 4;
const macroCenters: { x: number; y: number; spread: number }[] = [];
for (let m0 = 0; m0 < MACRO_COUNT; m0 += 1) {
macroCenters.push({ x: rand() * CALC_W, y: rand() * CALC_H, spread: 10 + rand() * 26 });
}
const SEED_COUNT08 = 46;
const seeds: Seed[] = [];
for (let i8 = 0; i8 < SEED_COUNT08; i8 += 1) {
const mc = macroCenters[i8 % MACRO_COUNT];
seeds.push({
x: Math.min(CALC_W, Math.max(0, mc.x + (rand() - 0.5) * mc.spread * 2)),
y: Math.min(CALC_H, Math.max(0, mc.y + (rand() - 0.5) * mc.spread * 2)),
c: camoPalette[i8 % camoPalette.length]
});
}
const NOISE_GRID_W = 9, NOISE_GRID_H = 6;
const noiseGridX: number[] = [], noiseGridY: number[] = [];
for (let n0 = 0; n0 < NOISE_GRID_W * NOISE_GRID_H; n0 += 1) {
noiseGridX.push(rand()); noiseGridY.push(rand());
}
function valueNoise2D(gx: number, gy: number, arr: number[]): number {
const x0 = Math.floor(gx), y0 = Math.floor(gy);
const x1 = Math.min(NOISE_GRID_W - 1, x0 + 1), y1 = Math.min(NOISE_GRID_H - 1, y0 + 1);
const tx = gx - x0, ty = gy - y0;
const v00 = arr[y0 * NOISE_GRID_W + x0], v10 = arr[y0 * NOISE_GRID_W + x1];
const v01 = arr[y1 * NOISE_GRID_W + x0], v11 = arr[y1 * NOISE_GRID_W + x1];
const top = v00 + (v10 - v00) * tx, bot = v01 + (v11 - v01) * tx;
return top + (bot - top) * ty;
}
function warpCoord(x: number, y: number, breathe: number): Vec {
const gx = (x / CALC_W) * (NOISE_GRID_W - 1), gy = (y / CALC_H) * (NOISE_GRID_H - 1);
const n1 = valueNoise2D(gx, gy, noiseGridX), n2 = valueNoise2D(gx, gy, noiseGridY);
return { x: x + (n1 - 0.5) * 2 * NOISE_WARP_PX * breathe, y: y + (n2 - 0.5) * 2 * NOISE_WARP_PX * breathe };
}
function renderField(t: number) {
const breathe = 0.55 + 0.45 * Math.sin(t * WARP_FREQ);
let idx = 0;
for (let y = 0; y < CALC_H; y += 1) {
for (let x = 0; x < CALC_W; x += 1) {
const w = warpCoord(x + 0.5, y + 0.5, breathe);
nearestTwo(w.x, w.y, seeds);
const rgb = paletteRgb[seeds[NEI].c];
const edge = ND2 - ND;
const dark = edge < 1.6 ? 0.55 + edge / 3.6 : 1;
offBuf[idx] = rgb[0] * dark; offBuf[idx + 1] = rgb[1] * dark; offBuf[idx + 2] = rgb[2] * dark; offBuf[idx + 3] = 255;
idx += 4;
}
}
}
let cw = 480, ch = 300;
function fit() {
const r = wrap.getBoundingClientRect();
cw = Math.max(1, Math.round(r.width));
ch = Math.max(1, Math.round(r.height));
canvas!.width = cw; canvas!.height = ch;
draw(lastElapsed);
}
let lastElapsed = 0;
function draw(elapsed: number) {
lastElapsed = elapsed;
renderField(elapsed);
octx.putImageData(offImg, 0, 0);
ctx!.imageSmoothingEnabled = false;
ctx!.clearRect(0, 0, cw, ch);
ctx!.drawImage(off, 0, 0, CALC_W, CALC_H, 0, 0, cw, ch);
}
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let playing = !reduce;
let elapsed = reduce ? LOOP_MS * 0.5 : 0;
if (reduce) { root.classList.remove("is-demo"); }
let lastTs: number | null = null;
let raf = 0;
function tick(ts: number) {
if (lastTs === null) lastTs = ts;
const dt = ts - lastTs;
lastTs = ts;
if (playing) {
elapsed += dt;
if (elapsed >= LOOP_MS) elapsed -= LOOP_MS;
}
draw(elapsed);
raf = requestAnimationFrame(tick);
}
fit();
window.addEventListener("resize", fit);
draw(elapsed);
raf = requestAnimationFrame(tick);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener("resize", fit);
};
}, []);
return (
<main className={styles.stage}>
<div className={`${styles.vd} is-demo`} ref={rootRef}>
<canvas className={styles.vd__canvas} ref={canvasRef} width={480} height={300} />
<p className={styles.vd__caption}>셀 크기 편차 값으로 만드는 위장 무늬</p>
</div>
</main>
);
}08 Camouflage Pattern Built From a Cell-size Variance Value — Measured area 27.205% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · Voronoi Diagram Generator — 9 Patterns
The post this demo lives in
Voronoi Diagram Generator — 9 PatternsA voronoi diagram isn't lines drawn by hand — it's every point finding its nearest seed value. Move one seed and item 1 See all demos in this post
If you like this effect - similar demos
Creative UI02 Voronoi cell tilesCSS Background Pattern Generator: 9 Seeded Scenes
Creative UI01 Custom Control Bar Drawn From a Playback Progress ValueCustom Audio Player CSS — 9 Computed UI Patterns
Creative UI02 Strip Automaton Whose Next Row Pattern Follows a Single Rule-Number ValueConway Game of Life in Canvas, 9 Patterns