/
githubmirror
/
anime
Обзор
Документация
Войти
/
githubmirror
/
anime
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/easings/irregular/index.js
36 строк
960 B
Julian Garnier
v4.2.0
29 сен 2025, 17:54
29 сен 2025, 17:54
00106be
Код
Авторство
О чём код?
import { clamp, } from "../../core/helpers.js"; import { linear, } from "../linear/index.js"; /** * @import { * EasingFunction, * } from '../../types/index.js' */ /** * Generate random steps * @param {Number} [length] - The number of steps * @param {Number} [randomness] - How strong the randomness is * @return {EasingFunction} */ export const irregular = (length = 10, randomness = 1) => { const values = [0]; const total = length - 1; for (let i = 1; i < total; i++) { const previousValue = values[i - 1]; const spacing = i / total; const segmentEnd = (i + 1) / total; const randomVariation = spacing + (segmentEnd - spacing) * Math.random(); // Mix the even spacing and random variation based on the randomness parameter const randomValue = spacing * (1 - randomness) + randomVariation * randomness; values.push(clamp(randomValue, previousValue, 1)); } values.push(1); return linear(...values); }