@litecanvas/utils
Version:
Utilities to help build litecanvas games
2 lines (1 loc) • 1.17 kB
JavaScript
(()=>{var D=Object.defineProperty;var H=(s,e)=>{for(var t in e)D(s,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let s in globalThis.utils)s!=="global"&&(globalThis[s]=globalThis.utils[s])};var b={};H(b,{Noise:()=>E});var I=4,_=1<<I,v=8,S=1<<v,a=4095,T=s=>.5*(1-Math.cos(s*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,n=0){e<0&&(e=-e),t<0&&(t=-t),n<0&&(n=-n);let c=Math.floor(e),f=Math.floor(t),u=Math.floor(n),p=e-c,h=t-f,d=n-u,r,m,y=0,x=.5,l,o,g;for(let w=0;w<this._po;w++){let i=c+(f<<I)+(u<<v);r=T(p),m=T(h),l=this._p[i&a],l+=r*(this._p[i+1&a]-l),o=this._p[i+_&a],o+=r*(this._p[i+_+1&a]-o),l+=m*(o-l),i+=S,o=this._p[i&a],o+=r*(this._p[i+1&a]-o),g=this._p[i+_&a],g+=r*(this._p[i+_+1&a]-g),o+=m*(g-o),l+=T(d)*(o-l),y+=l*x,x*=this._pf,c<<=1,p*=2,f<<=1,h*=2,u<<=1,d*=2,p>=1&&(c++,p--),h>=1&&(f++,h--),d>=1&&(u++,d--)}return y}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let n=0;n<a+1;n++)this._p[n]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},b);})();