From e0a207a842bb8785d961a7f9b57d781cb74e0a83 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Sun, 25 Jan 2026 09:36:48 +0000 Subject: [PATCH] applyWobble function that samples noise to displace points along the edge --- src/lib/noise.ts | 3 +++ src/lib/shapes/wobble.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/lib/noise.ts create mode 100644 src/lib/shapes/wobble.ts diff --git a/src/lib/noise.ts b/src/lib/noise.ts new file mode 100644 index 0000000..0dd4ae5 --- /dev/null +++ b/src/lib/noise.ts @@ -0,0 +1,3 @@ +import { createNoise2D } from "simplex-noise"; + +export const noise2D = createNoise2D(); diff --git a/src/lib/shapes/wobble.ts b/src/lib/shapes/wobble.ts new file mode 100644 index 0000000..5321d5f --- /dev/null +++ b/src/lib/shapes/wobble.ts @@ -0,0 +1,21 @@ +import { noise2D } from "@/lib/noise"; +import type { Point } from "./points"; + +// apply noise-based displacement to points. this gives a wobble effect. points are displaced radially +export function applyWobble(points: Point[], time: number, amount: number, noiseScale = 0.5): Point[] { + if (amount === 0) return points; + + return points.map((point, i) => { + // use point index and time for noise input + const noiseX = i * noiseScale; + const noiseY = time; + const displacement = noise2D(noiseX, noiseY) * amount; + + const angle = Math.atan2(point.y, point.x); + + return { + x: point.x + Math.cos(angle) * displacement, + y: point.y + Math.sin(angle) * displacement, + }; + }); +}