phaser3-rex-plugins
Version:
2 lines (1 loc) • 6.21 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexperlinplugin=e();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(o=n.key,i=void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?i:String(i)),n);}var o,i;}function r(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function u(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var r,o=n(t);if(e){var u=n(this).constructor;r=Reflect.construct(o,arguments,u);}else r=o.apply(this,arguments);return i(this,r)}}var f=function(){function e(r,n,o){t(this,e),this.x=r,this.y=n,this.z=o;}return r(e,[{key:"dot2",value:function(t,e){return this.x*t+this.y*e}},{key:"dot3",value:function(t,e,r){return this.x*t+this.y*e+this.z*r}}]),e}(),a=[new f(1,1,0),new f(-1,1,0),new f(1,-1,0),new f(-1,-1,0),new f(1,0,1),new f(-1,0,1),new f(1,0,-1),new f(-1,0,-1),new f(0,1,1),new f(0,-1,1),new f(0,1,-1),new f(0,-1,-1)],c=[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],s=.5*(Math.sqrt(3)-1),l=(3-Math.sqrt(3))/6,d=1/6,h=function(t){return t*t*t*(t*(6*t-15)+10)},p=function(t,e,r){return (1-r)*t+r*e},y=function(){function e(r){t(this,e),void 0===r&&(r=0),this.perm=new Array(512),this.gradP=new Array(512),this.setSeed(r);}return r(e,[{key:"setSeed",value:function(t){var e=this.perm,r=this.gradP;t>0&&t<1&&(t*=65536),(t=Math.floor(t))<256&&(t|=t<<8);for(var n=0;n<256;n++){var o;o=1&n?c[n]^255&t:c[n]^t>>8&255,e[n]=e[n+256]=o,r[n]=r[n+256]=a[o%12];}}},{key:"simplex2",value:function(t,e){var r,n,o=this.perm,i=this.gradP,u=(t+e)*s,f=Math.floor(t+u),a=Math.floor(e+u),c=(f+a)*l,d=t-f+c,h=e-a+c;d>h?(r=1,n=0):(r=0,n=1);var p=d-r+l,y=h-n+l,v=d-1+2*l,b=h-1+2*l,w=i[(f&=255)+o[a&=255]],m=i[f+r+o[a+n]],g=i[f+1+o[a+1]],P=.5-d*d-h*h,O=.5-p*p-y*y,j=.5-v*v-b*b;return 70*((P<0?0:(P*=P)*P*w.dot2(d,h))+(O<0?0:(O*=O)*O*m.dot2(p,y))+(j<0?0:(j*=j)*j*g.dot2(v,b)))}},{key:"simplex3",value:function(t,e,r){var n,o,i,u,f,a,c=this.perm,s=this.gradP,l=.3333333333333333*(t+e+r),h=Math.floor(t+l),p=Math.floor(e+l),y=Math.floor(r+l),v=(h+p+y)*d,b=t-h+v,w=e-p+v,m=r-y+v;b>=w?w>=m?(n=1,o=0,i=0,u=1,f=1,a=0):b>=m?(n=1,o=0,i=0,u=1,f=0,a=1):(n=0,o=0,i=1,u=1,f=0,a=1):w<m?(n=0,o=0,i=1,u=0,f=1,a=1):b<m?(n=0,o=1,i=0,u=0,f=1,a=1):(n=0,o=1,i=0,u=1,f=1,a=0);var g=b-n+d,P=w-o+d,O=m-i+d,j=b-u+2*d,M=w-f+2*d,k=m-a+2*d,x=b-1+.5,_=w-1+.5,R=m-1+.5,S=s[(h&=255)+c[(p&=255)+c[y&=255]]],T=s[h+n+c[p+o+c[y+i]]],E=s[h+u+c[p+f+c[y+a]]],B=s[h+1+c[p+1+c[y+1]]],q=.6-b*b-w*w-m*m,z=.6-g*g-P*P-O*O,A=.6-j*j-M*M-k*k,C=.6-x*x-_*_-R*R;return 32*((q<0?0:(q*=q)*q*S.dot3(b,w,m))+(z<0?0:(z*=z)*z*T.dot3(g,P,O))+(A<0?0:(A*=A)*A*E.dot3(j,M,k))+(C<0?0:(C*=C)*C*B.dot3(x,_,R)))}},{key:"perlin2",value:function(t,e){var r=this.perm,n=this.gradP,o=Math.floor(t),i=Math.floor(e);t-=o,e-=i;var u=n[(o&=255)+r[i&=255]].dot2(t,e),f=n[o+r[i+1]].dot2(t,e-1),a=n[o+1+r[i]].dot2(t-1,e),c=n[o+1+r[i+1]].dot2(t-1,e-1),s=h(t);return p(p(u,a,s),p(f,c,s),h(e))}},{key:"perlin3",value:function(t,e,r){var n=this.perm,o=this.gradP,i=Math.floor(t),u=Math.floor(e),f=Math.floor(r);t-=i,e-=u,r-=f;var a=o[(i&=255)+n[(u&=255)+n[f&=255]]].dot3(t,e,r),c=o[i+n[u+n[f+1]]].dot3(t,e,r-1),s=o[i+n[u+1+n[f]]].dot3(t,e-1,r),l=o[i+n[u+1+n[f+1]]].dot3(t,e-1,r-1),d=o[i+1+n[u+n[f]]].dot3(t-1,e,r),y=o[i+1+n[u+n[f+1]]].dot3(t-1,e,r-1),v=o[i+1+n[u+1+n[f]]].dot3(t-1,e-1,r),b=o[i+1+n[u+1+n[f+1]]].dot3(t-1,e-1,r-1),w=h(t),m=h(e),g=h(r);return p(p(p(a,d,w),p(c,y,w),g),p(p(s,v,w),p(l,b,w),g),m)}}]),e}();return function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}(i,Phaser.Plugins.BasePlugin);var n=u(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new y(t)}}]),i}()}));