phaser4-rex-plugins
Version:
2 lines (1 loc) • 3.9 kB
JavaScript
var t,r;t=void 0,r=function(){class t{constructor(t,r,e){this.x=t,this.y=r,this.z=e}dot2(t,r){return this.x*t+this.y*r}dot3(t,r,e){return this.x*t+this.y*r+this.z*e}}const r=[new t(1,1,0),new t(-1,1,0),new t(1,-1,0),new t(-1,-1,0),new t(1,0,1),new t(-1,0,1),new t(1,0,-1),new t(-1,0,-1),new t(0,1,1),new t(0,-1,1),new t(0,1,-1),new t(0,-1,-1)],e=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],o=.5*(Math.sqrt(3)-1),s=(3-Math.sqrt(3))/6,n=1/3,d=1/6;var a=function(t){return t*t*t*(t*(6*t-15)+10)},i=function(t,r,e){return(1-e)*t+e*r};class h{constructor(t){void 0===t&&(t=0),this.perm=new Array(512),this.gradP=new Array(512),this.setSeed(t)}setSeed(t){var o=this.perm,s=this.gradP;t>0&&t<1&&(t*=65536),(t=Math.floor(t))<256&&(t|=t<<8);for(var n=0;n<256;n++){var d;d=1&n?e[n]^255&t:e[n]^t>>8&255,o[n]=o[n+256]=d,s[n]=s[n+256]=r[d%12]}}simplex2(t,r){var e,n,d=this.perm,a=this.gradP,i=(t+r)*o,h=Math.floor(t+i),l=Math.floor(r+i),f=(h+l)*s,u=t-h+f,p=r-l+f;u>p?(e=1,n=0):(e=0,n=1);var v=u-e+s,c=p-n+s,w=u-1+2*s,M=p-1+2*s,g=a[(h&=255)+d[l&=255]],m=a[h+e+d[l+n]],y=a[h+1+d[l+1]],x=.5-u*u-p*p,P=.5-v*v-c*c,b=.5-w*w-M*M;return 70*((x<0?0:(x*=x)*x*g.dot2(u,p))+(P<0?0:(P*=P)*P*m.dot2(v,c))+(b<0?0:(b*=b)*b*y.dot2(w,M)))}simplex3(t,r,e){var o,s,a,i,h,l,f=this.perm,u=this.gradP,p=(t+r+e)*n,v=Math.floor(t+p),c=Math.floor(r+p),w=Math.floor(e+p),M=(v+c+w)*d,g=t-v+M,m=r-c+M,y=e-w+M;g>=m?m>=y?(o=1,s=0,a=0,i=1,h=1,l=0):g>=y?(o=1,s=0,a=0,i=1,h=0,l=1):(o=0,s=0,a=1,i=1,h=0,l=1):m<y?(o=0,s=0,a=1,i=0,h=1,l=1):g<y?(o=0,s=1,a=0,i=0,h=1,l=1):(o=0,s=1,a=0,i=1,h=1,l=0);var x=g-o+d,P=m-s+d,b=y-a+d,q=g-i+2*d,z=m-h+2*d,A=y-l+2*d,S=g-1+.5,T=m-1+.5,j=y-1+.5,B=u[(v&=255)+f[(c&=255)+f[w&=255]]],k=u[v+o+f[c+s+f[w+a]]],C=u[v+i+f[c+h+f[w+l]]],D=u[v+1+f[c+1+f[w+1]]],E=.6-g*g-m*m-y*y,F=.6-x*x-P*P-b*b,G=.6-q*q-z*z-A*A,H=.6-S*S-T*T-j*j;return 32*((E<0?0:(E*=E)*E*B.dot3(g,m,y))+(F<0?0:(F*=F)*F*k.dot3(x,P,b))+(G<0?0:(G*=G)*G*C.dot3(q,z,A))+(H<0?0:(H*=H)*H*D.dot3(S,T,j)))}perlin2(t,r){var e=this.perm,o=this.gradP,s=Math.floor(t),n=Math.floor(r);t-=s,r-=n;var d=o[(s&=255)+e[n&=255]].dot2(t,r),h=o[s+e[n+1]].dot2(t,r-1),l=o[s+1+e[n]].dot2(t-1,r),f=o[s+1+e[n+1]].dot2(t-1,r-1),u=a(t);return i(i(d,l,u),i(h,f,u),a(r))}perlin3(t,r,e){var o=this.perm,s=this.gradP,n=Math.floor(t),d=Math.floor(r),h=Math.floor(e);t-=n,r-=d,e-=h;var l=s[(n&=255)+o[(d&=255)+o[h&=255]]].dot3(t,r,e),f=s[n+o[d+o[h+1]]].dot3(t,r,e-1),u=s[n+o[d+1+o[h]]].dot3(t,r-1,e),p=s[n+o[d+1+o[h+1]]].dot3(t,r-1,e-1),v=s[n+1+o[d+o[h]]].dot3(t-1,r,e),c=s[n+1+o[d+o[h+1]]].dot3(t-1,r,e-1),w=s[n+1+o[d+1+o[h]]].dot3(t-1,r-1,e),M=s[n+1+o[d+1+o[h+1]]].dot3(t-1,r-1,e-1),g=a(t),m=a(r),y=a(e);return i(i(i(l,v,g),i(f,c,g),y),i(i(u,w,g),i(p,M,g),y),m)}}class l extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t){return new h(t)}}return l},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).rexperlinplugin=r();