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, + }; + }); +}