Some checks are pending
Deploy to Cloudflare Workers (OpenNext) / deploy (push) Waiting to run
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { createRng } from "@/lib/voronoi-mesh";
|
|
|
|
/** Organic contour paths for light backgrounds (topographic wave lines). */
|
|
export function buildWavyContourPaths(
|
|
lineCount: number,
|
|
width: number,
|
|
height: number,
|
|
seed: number
|
|
): string[] {
|
|
const rng = createRng(seed);
|
|
const paths: string[] = [];
|
|
|
|
for (let i = 0; i < lineCount; i++) {
|
|
const yBase = ((i + 0.5) / lineCount) * height;
|
|
const amp = 2 + rng() * 4.5;
|
|
const freq1 = 0.035 + rng() * 0.038;
|
|
const freq2 = 0.008 + rng() * 0.014;
|
|
const phase1 = rng() * Math.PI * 2;
|
|
const phase2 = rng() * Math.PI * 2;
|
|
const drift = (rng() - 0.5) * 3;
|
|
const steps = 80;
|
|
let d = "";
|
|
|
|
for (let s = 0; s <= steps; s++) {
|
|
const x = (s / steps) * width;
|
|
const y =
|
|
yBase +
|
|
drift * (x / width - 0.5) +
|
|
amp * Math.sin(x * freq1 + phase1) +
|
|
amp * 0.42 * Math.sin(x * freq2 + phase2);
|
|
d += s === 0 ? `M ${x.toFixed(2)} ${y.toFixed(2)}` : ` L ${x.toFixed(2)} ${y.toFixed(2)}`;
|
|
}
|
|
|
|
paths.push(d);
|
|
}
|
|
|
|
return paths;
|
|
}
|