pixel/js/core-utils.js
2026-06-02 17:19:36 +09:00

33 lines
730 B
JavaScript

(function () {
'use strict';
const root = window.PixelIslandModules ||= {};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function mod(n, m) {
return ((n % m) + m) % m;
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function fnv1a(value) {
let hash = 0x811c9dc5;
const text = String(value);
for (let i = 0; i < text.length; i++) {
hash ^= text.charCodeAt(i);
hash = Math.imul(hash, 0x01000193);
}
return (hash >>> 0).toString(16).padStart(8, '0');
}
function uid() {
return Math.random().toString(36).slice(2, 9) + Date.now().toString(36).slice(-5);
}
root.CoreUtils = { clamp, mod, lerp, fnv1a, uid };
})();