applyWobble function that samples noise to displace points along the edge

This commit is contained in:
2026-01-25 09:36:48 +00:00
parent 0638425c67
commit e0a207a842
2 changed files with 24 additions and 0 deletions

3
src/lib/noise.ts Normal file
View File

@@ -0,0 +1,3 @@
import { createNoise2D } from "simplex-noise";
export const noise2D = createNoise2D();

21
src/lib/shapes/wobble.ts Normal file
View File

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