UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 4.35 kB
var t,e;t=void 0,e=function(){class t{constructor(t,e,r){this.x=t,this.y=e,this.z=r}dot2(t,e){return this.x*t+this.y*e}dot3(t,e,r){return this.x*t+this.y*e+this.z*r}}const e=[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)],r=[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,i=1/3,a=1/6;var n=function(t){return t*t*t*(t*(6*t-15)+10)},h=function(t,e,r){return(1-r)*t+r*e};class d{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 i=0;i<256;i++){var a;a=1&i?r[i]^255&t:r[i]^t>>8&255,o[i]=o[i+256]=a,s[i]=s[i+256]=e[a%12]}}simplex2(t,e){var r,i,a=this.perm,n=this.gradP,h=(t+e)*o,d=Math.floor(t+h),l=Math.floor(e+h),c=(d+l)*s,u=t-d+c,v=e-l+c;u>v?(r=1,i=0):(r=0,i=1);var f=u-r+s,p=v-i+s,y=u-1+2*s,w=v-1+2*s,M=n[(d&=255)+a[l&=255]],g=n[d+r+a[l+i]],m=n[d+1+a[l+1]],P=.5-u*u-v*v,x=.5-f*f-p*p,S=.5-y*y-w*w;return 70*((P<0?0:(P*=P)*P*M.dot2(u,v))+(x<0?0:(x*=x)*x*g.dot2(f,p))+(S<0?0:(S*=S)*S*m.dot2(y,w)))}simplex3(t,e,r){var o,s,n,h,d,l,c=this.perm,u=this.gradP,v=(t+e+r)*i,f=Math.floor(t+v),p=Math.floor(e+v),y=Math.floor(r+v),w=(f+p+y)*a,M=t-f+w,g=e-p+w,m=r-y+w;M>=g?g>=m?(o=1,s=0,n=0,h=1,d=1,l=0):M>=m?(o=1,s=0,n=0,h=1,d=0,l=1):(o=0,s=0,n=1,h=1,d=0,l=1):g<m?(o=0,s=0,n=1,h=0,d=1,l=1):M<m?(o=0,s=1,n=0,h=0,d=1,l=1):(o=0,s=1,n=0,h=1,d=1,l=0);var P=M-o+a,x=g-s+a,S=m-n+a,b=M-h+2*a,j=g-d+2*a,q=m-l+2*a,z=M-1+.5,A=g-1+.5,T=m-1+.5,V=u[(f&=255)+c[(p&=255)+c[y&=255]]],X=u[f+o+c[p+s+c[y+n]]],Y=u[f+h+c[p+d+c[y+l]]],B=u[f+1+c[p+1+c[y+1]]],G=.6-M*M-g*g-m*m,I=.6-P*P-x*x-S*S,O=.6-b*b-j*j-q*q,U=.6-z*z-A*A-T*T;return 32*((G<0?0:(G*=G)*G*V.dot3(M,g,m))+(I<0?0:(I*=I)*I*X.dot3(P,x,S))+(O<0?0:(O*=O)*O*Y.dot3(b,j,q))+(U<0?0:(U*=U)*U*B.dot3(z,A,T)))}perlin2(t,e){var r=this.perm,o=this.gradP,s=Math.floor(t),i=Math.floor(e);t-=s,e-=i;var a=o[(s&=255)+r[i&=255]].dot2(t,e),d=o[s+r[i+1]].dot2(t,e-1),l=o[s+1+r[i]].dot2(t-1,e),c=o[s+1+r[i+1]].dot2(t-1,e-1),u=n(t);return h(h(a,l,u),h(d,c,u),n(e))}perlin3(t,e,r){var o=this.perm,s=this.gradP,i=Math.floor(t),a=Math.floor(e),d=Math.floor(r);t-=i,e-=a,r-=d;var l=s[(i&=255)+o[(a&=255)+o[d&=255]]].dot3(t,e,r),c=s[i+o[a+o[d+1]]].dot3(t,e,r-1),u=s[i+o[a+1+o[d]]].dot3(t,e-1,r),v=s[i+o[a+1+o[d+1]]].dot3(t,e-1,r-1),f=s[i+1+o[a+o[d]]].dot3(t-1,e,r),p=s[i+1+o[a+o[d+1]]].dot3(t-1,e,r-1),y=s[i+1+o[a+1+o[d]]].dot3(t-1,e-1,r),w=s[i+1+o[a+1+o[d+1]]].dot3(t-1,e-1,r-1),M=n(t),g=n(e),m=n(r);return h(h(h(l,f,M),h(c,p,M),m),h(h(u,y,M),h(v,w,M),m),g)}}const l=Phaser.Utils.Objects.GetValue;class c{constructor(t){this.active=!0,this.noise=new d(l(t,"seed",Math.random())),this.periodScale=l(t,"periodScale",2e-4),this.rotateScale=l(t,"rotateScale",.3),this.velocity=new Phaser.Math.Vector2}update(t,e){var r=e*this.periodScale,o=this.noise.perlin2(t.x*r,t.y*r)*Math.PI;this.velocity.set(t.velocityX,t.velocityY).rotate(o*this.rotateScale),t.velocityX=this.velocity.x,t.velocityY=this.velocity.y}}class u extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t){return new c(t)}}return u},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexperlingrivatywellplugin=e();