mirror of
https://github.com/hex248/tsos.git
synced 2026-02-07 18:23:05 +00:00
applyWobble function that samples noise to displace points along the edge
This commit is contained in:
3
src/lib/noise.ts
Normal file
3
src/lib/noise.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createNoise2D } from "simplex-noise";
|
||||
|
||||
export const noise2D = createNoise2D();
|
||||
21
src/lib/shapes/wobble.ts
Normal file
21
src/lib/shapes/wobble.ts
Normal 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,
|
||||
};
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user