UNPKG

@litecanvas/utils

Version:

Utilities to help build litecanvas games

2 lines (1 loc) 1.21 kB
(()=>{var E=Object.defineProperty;var T=(o,e)=>{for(var t in e)E(o,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let e in globalThis.utils)e!=="global"&&(o||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var v={};T(v,{Noise:()=>N});var k=4,h=1<<k,A=8,P=1<<A,n=4095,y=o=>.5*(1-Math.cos(o*Math.PI)),N=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,s=0){e<0&&(e=-e),t<0&&(t=-t),s<0&&(s=-s);let m=Math.floor(e),l=Math.floor(t),p=Math.floor(s),b=e-m,c=t-l,f=s-p,u,g,w=0,x=.5,i,a,d;for(let _=0;_<this._po;_++){let r=m+(l<<k)+(p<<A);u=y(b),g=y(c),i=this._p[r&n],i+=u*(this._p[r+1&n]-i),a=this._p[r+h&n],a+=u*(this._p[r+h+1&n]-a),i+=g*(a-i),r+=P,a=this._p[r&n],a+=u*(this._p[r+1&n]-a),d=this._p[r+h&n],d+=u*(this._p[r+h+1&n]-d),a+=g*(d-a),i+=y(f)*(a-i),w+=i*x,x*=this._pf,m<<=1,b*=2,l<<=1,c*=2,p<<=1,f*=2,b>=1&&(m++,b--),c>=1&&(l++,c--),f>=1&&(p++,f--)}return w}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.rseed(e);let t=this._e.rand||Math.random;for(let s=0;s<n+1;s++)this._p[s]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},v);})();