@litecanvas/utils
Version:
Utilities to help build litecanvas games
2 lines (1 loc) • 1.18 kB
JavaScript
(()=>{var u=Object.defineProperty;var w=(n,i)=>{for(var t in i)u(n,t,{get:i[t],enumerable:!0})};window.utils=window.utils||{};window.utils.global=(n=!0)=>{for(let i in window.utils)i!=="global"&&(n||globalThis[i]===void 0)&&(globalThis[i]=window.utils[i])};var a={};w(a,{Noise:()=>p});var N=n=>.5*(1-Math.cos(n*Math.PI)),p=class{_p=[];_po=4;_pf=.5;_e=null;constructor(i){this._e=i||globalThis,this.noiseSeed()}noise(i,t=0,o=0){i<0&&(i=-i),t<0&&(t=-t),o<0&&(o=-o);let R=Math.floor(i),e=Math.floor(t),I=Math.floor(o),E=i-R,h=t-e,f=o-I,P,r,c=0,d=.5,l,s,L;for(let Z=0;Z<this._po;Z++){let _=R+(e<<4)+(I<<8);P=N(E),r=N(h),l=this._p[_&4095],l+=P*(this._p[_+1&4095]-l),s=this._p[_+16&4095],s+=P*(this._p[_+16+1&4095]-s),l+=r*(s-l),_+=256,s=this._p[_&4095],s+=P*(this._p[_+1&4095]-s),L=this._p[_+16&4095],L+=P*(this._p[_+16+1&4095]-L),s+=r*(L-s),l+=N(f)*(s-l),c+=l*d,d*=this._pf,R<<=1,E*=2,e<<=1,h*=2,I<<=1,f*=2,E>=1&&(R++,E--),h>=1&&(e++,h--),f>=1&&(I++,f--)}return c}noiseDetail(i,t){i>0&&(this._po=i),t>0&&(this._pf=t)}noiseSeed(i=null){i!=null&&this._e.rseed(i);let t=this._e.rand||Math.random;for(let o=0;o<4096;o++)this._p[o]=t()}};window.utils=Object.assign(window.utils||{},a);})();