UNPKG

@fluritheme/fluri

Version:

Interactive snowfall for websites: DOM-aware snow accumulation, mouse interactions, snow physics, Canvas 2D rendering, and Christmas effects.

29 lines • 1.26 kB
export const clamp = (value, minimum, maximum) => Math.min(maximum, Math.max(minimum, value)); /** A small reproducible PRNG: simulation output never depends on Math.random(). */ export function seededRandom(seed) { let state = seed >>> 0; return () => { state += 0x6d2b79f5; let value = state; value = Math.imul(value ^ (value >>> 15), value | 1); value ^= value + Math.imul(value ^ (value >>> 7), value | 61); return ((value ^ (value >>> 14)) >>> 0) / 4294967296; }; } /** Surface-local y is positive below its edge; deposits occupy negative local y. */ export function localToWorld(surface, x, y = 0) { const cosine = Math.cos(surface.angle); const sine = Math.sin(surface.angle); return { x: surface.x + x * cosine - y * sine, y: surface.y + x * sine + y * cosine }; } export function worldToLocal(surface, point) { const cosine = Math.cos(surface.angle); const sine = Math.sin(surface.angle); const x = point.x - surface.x; const y = point.y - surface.y; return { x: x * cosine + y * sine, y: -x * sine + y * cosine }; } export function surfaceNormal(surface) { return { x: Math.sin(surface.angle), y: -Math.cos(surface.angle) }; } //# sourceMappingURL=math.js.map