0xe4f517a4…f7b9sent to0x96a83b48…d253·#22,569,707·view on Etherscan
ogramLinker=new Bt({width:this._width,height:this._height}),this._programLinker.init({uniforms:e,textures:t,vs:s,fs:i,dataFroms:l}),this.mesh=Br({uniforms:this._programLinker.uniforms,vertex:this._programLinker.vs,fragment:this._programLinker.fs,width:2,height:2}),this.addChild(this.mesh)),this._onInit()}_onInit(){}refreshTextures(e){this._programLinker.refreshTextures(e)}_createRT(e,t){const s={width:this._width,height:this._height,minFilter:a.gl.LINEAR,magFilter:a.gl.NEAREST,wrapS:a.gl.CLAMP_TO_EDGE,wrapT:a.gl.CLAMP_TO_EDGE,color:e,depth:!1},i=Object.assign({},s,t);return new Ie(a.gl,i)}generate(){}updateProgramLinker(){this._programLinker?.update()}render({hasToClear:e=!0,hasToUpdateUniforms:t=!0}={}){t&&this._programLinker?.update(),this._render(this,this._renderTarget,e)}_setClear(e=-1,t=1){e>=0&&(e=e instanceof E?e:new E(e),a.gl.clearColor(e.r,e.g,e.b,t))}_render(e,t,s=!0){a.renderer.render({scene:e,camera:this._camera,target:t,sort:!1,update:!1,clear:s})}clear(){a.gl.clearColor(a.bgColor.r,a.bgColor.g,a.bgColor.b,0),a.gl.renderer.autoClear=!0,this._render(this,this._renderTarget,!0),a.gl.renderer.autoClear=!1}get uniforms(){return this._programLinker.uniforms}get u(){return this.uniforms}get texture(){return this._renderTarget.texture}get textures(){return this._renderTarget.textures}get renderTarget(){return this._renderTarget}get camera(){return this._camera}}var Ir=`#define M_PI 3.1415926535897932384626433832795
#i_ noiseUtils
#i_ snoise2d
_v4 pperm(_v4 x){return mod(((x*34.0)+1.0)*x,289.0);}_v4 ptisq(_v4 r){return 1.79-0.85*r;}_v3 pfade(_v3 t){return t*t*t*(t*(t*6.0-15.0)+10.0);}_f pnoise(_v3 P){_v3 Pi0=floor(P);_v3 Pi1=Pi0+_v3(1.0);Pi0=mod(Pi0,289.0);Pi1=mod(Pi1,289.0);_v3 Pf0=fract(P);_v3 Pf1=Pf0-_v3(1.0);_v4 ix=_v4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);_v4 iy=_v4(Pi0.yy,Pi1.yy);_v4 iz0=Pi0.zzzz;_v4 iz1=Pi1.zzzz;_v4 ixy=pperm(pperm(ix)+iy);_v4 ixy0=pperm(ixy+iz0);_v4 ixy1=pperm(ixy+iz1);_v4 gx0=ixy0/7.0;_v4 gy0=fract(floor(gx0)/7.0)-0.5;gx0=fract(gx0);_v4 gz0=_v4(0.5)-abs(gx0)-abs(gy0);_v4 sz0=step(gz0,_v4(0.0));gx0-=sz0*(step(0.0,gx0)-0.5);gy0-=sz0*(step(0.0,gy0)-0.5);_v4 gx1=ixy1/7.0;_v4 gy1=fract(floor(gx1)/7.0)-0.5;gx1=fract(gx1);_v4 gz1=_v4(0.5)-abs(gx1)-abs(gy1);_v4 sz1=step(gz1,_v4(0.0));gx1-=sz1*(step(0.0,gx1)-0.5);gy1-=sz1*(step(0.0,gy1)-0.5);_v3 g000=_v3(gx0.x,gy0.x,gz0.x);_v3 g100=_v3(gx0.y,gy0.y,gz0.y);_v3 g010=_v3(gx0.z,gy0.z,gz0.z);_v3 g110=_v3(gx0.w,gy0.w,gz0.w);_v3 g001=_v3(gx1.x,gy1.x,gz1.x);_v3 g101=_v3(gx1.y,gy1.y,gz1.y);_v3 g011=_v3(gx1.z,gy1.z,gz1.z);_v3 g111=_v3(gx1.w,gy1.w,gz1.w);_v4 norm0=ptisq(_v4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));g000*=norm0.x;g010*=norm0.y;g100*=norm0.z;g110*=norm0.w;_v4 norm1=ptisq(_v4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));g001*=norm1.x;g011*=norm1.y;g101*=norm1.z;g111*=norm1.w;_f n000=dot(g000,Pf0);_f n100=dot(g100,_v3(Pf1.x,Pf0.yz));_f n010=dot(g010,_v3(Pf0.x,Pf1.y,Pf0.z));_f n110=dot(g110,_v3(Pf1.xy,Pf0.z));_f n001=dot(g001,_v3(Pf0.xy,Pf1.z));_f n101=dot(g101,_v3(Pf1.x,Pf0.y,Pf1.z));_f n011=dot(g011,_v3(Pf0.x,Pf1.yz));_f n111=dot(g111,Pf1);_v3 fade_xyz=pfade(Pf0);_v4 n_z=mix(_v4(n000,n100,n010,n110),_v4(n001,n101,n011,n111),fade_xyz.z);vec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);_f n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);return 2.2*n_xyz;}
#injectUniforms
_f sn3m(_v3 v,_f nb){const _v2 C=_v2(1.0/6.0,1.0/3.0);const _v4 D=_v4(0.0,0.5,1.0,2.0);_v3 i=floor(v+dot(v,C.yyy));_v3 x0=v-i+dot(i,C.xxx);_v3 g=step(x0.yzx,x0.xyz);_v3 l=1.0-g;_v3 i1=min(g.xyz,l.zxy);_v3 i2=max(g.xyz,l.zxy);_v3 x1=x0-i1+C.xxx;_v3 x2=x0-i2+C.yyy;_v3 x3=x0-D.yyy;i=mod289(i);_v4 p=permute(permute(permute(i.z+_v4(0.0,i1.z,i2.z,1.0))+i.y+_v4(0.0,i1.y,i2.y,1.0))+i.x+_v4(0.0,i1.x,i2.x,1.0));_f n_=0.1428;_v3 ns=n_*D.wyz-D.xzx;_v4 j=p-49.0*floor(p*ns.z*ns.z);_v4 x_=floor(j*ns.z);_v4 y_=floor(j-7.0*x_);_v4 x=x_*ns.x+ns.yyyy;_v4 y=y_*ns.x+ns.yyyy;_v4 h=1.0-abs(x)-abs(y);_v4 b0=_v4(x.xy,y.xy);_v4 b1=_v4(x.zw,y.zw);_v4 s0=floor(b0)*2.0+1.0;_v4 s1=floor(b1)*2.0+1.0;_v4 sh=-step(h,_v4(0.));_v4 a0=b0.xzyw+s0.xzyw*sh.xxyy;_v4 a1=b1.xzyw+s1.xzyw*sh.zzww;_v3 p0=_v3(a0.xy,h.x);_v3 p1=_v3(a0.zw,h.y);_v3 p2=_v3(a1.xy,h.z);_v3 p3=_v3(a1.zw,h.w);if(uModMax2==true){p0=max(p0,_v3(0.));p1=max(p1,_v3(0.));p2=max(p2,_v3(0.));p3=max(p3,_v3(0.));}_v4 norm=taylorInvSqrt(_v4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;_f m0=dot(x0,x0);_f m1=dot(x1,x1);_f m2=dot(x2,x2);_f m3=dot(x3,x3);_v4 m=_v4(0.);if(uModMax==true){m=max(nb-_v4(m0,m1,m2,m3),0.);}else{m=nb-_v4(m0,m1,m2,m3);};m=m*m;m=m*m*m*m*m;_f noise=42.*dot(m,_v4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));return noise;}_v3 snv3m(_v3 x,_f noiseBase){_f s=sn3m(_v3(x),noiseBase);_f s1=sn3m(_v3(x.y-19.1,x.z+33.4,x.x+47.2),noiseBase);_f s2=sn3m(_v3(x.z+74.2,x.x-124.5,x.y+99.4),noiseBase);_v3 c=_v3(s,s1,s2);return c;}_v3 cnm(_v3 p,_f nb){const _f e=.1;_v3 dx=_v3(e,0.0,0.0);_v3 dy=_v3(0.0,e,0.0);_v3 dz=_v3(0.0,0.0,e);_v3 p_x0=snv3m(p-dx,nb);_v3 p_x1=snv3m(p+dx,nb);_v3 p_y0=snv3m(p-dy,nb);_v3 p_y1=snv3m(p+dy,nb);_v3 p_z0=snv3m(p-dz,nb);_v3 p_z1=snv3m(p+dz,nb);_f x=p_y1.z-p_y0.z-p_z1.y+p_z0.y;_f y=p_z1.x-p_z0.x-p_x1.z+p_x0.z;_f z=p_x1.y-p_x0.y-p_y1.x+p_y0.x;const _f divisor=1.0/(2.0*e);return normalize(_v3(x,y,z)*divisor);}_u _f uSeed;_u _v2 uResolution;_u _f uScreenRatio;in _v2 vUv;_lay 0)out _v4 outColor0;_vm_v2 uv=vUv*_v2(uScreenRatio,1.);uv.x+=uOffset;_v2 uvOrigin=uv;_v3 curl=_v3(0.);_v2 zeroUV=_v2(0.);_v2 valueTest=_v2(0.);_f cum=uCUvMult;_f cra=uCRatioAccu;_v2 ucu=cum*_v2(uCUvMultX,uCUvMultY);_f crx=uCRatioX*cra;_f cry=uCRatioY*cra;curl=cnm(_v3((uv+zeroUV)*ucu,uSeed*uCSeedMult),uModBase);curl*=uCStr;uv.x+=curl.x*crx;uv.y+=curl.y*cry;valueTest.x+=curl.x*crx;valueTest.y+=curl.y*cry;for(int i=0;i<uCLoop;i++){curl=cnm(_v3((uv+zeroUV)*ucu,uSeed*uCSeedMult),uModBase);curl*=uCStr;uv.x+=curl.x*crx;uv.y+=curl.y*cry;valueTest.x+=curl.x*crx;valueTest.y+=curl.y*cry;}_v2 valueTest2=_v2(0.);_v2 uv2=uvOrigin;_v2 suv=_v2(uSnUvMultX,uSnUvMultY);_f cvalue=snoise2d(_v2(uv2*uSnUvMult*suv+uSeed*uSnSeedMult))*M_PI;cvalue*=uSnStr;_f srx=uSnRatioX*uSnRatioAccu;_f sry=uSnRatioY*uSnRatioAccu;uv2.x+=cos(cvalue)*srx;uv2.y+=sin(cvalue)*sry;valueTest2.x+=cos(cvalue)*srx;valueTest2.y+=sin(cvalue)*sry;for(int i=0;i<uSnLoop;i++){cvalue=snoise2d(_v2(uv2*uSnUvMult*suv+uSeed*uSnSeedMult))*M_PI;cvalue*=uSnStr;uv2.x+=cos(cvalue)*srx;uv2.y+=sin(cvalue)*sry;valueTest2.x+=cos(cvalue)*srx;valueTest2.y+=sin(cvalue)*sry;}_f pvalue=pnoise(_v3(uvOrigin*uPNoiseUvMult,uSeed*uPNoiseSeedMult))*uPNoiseStr;_v2 uvMix=mix(uv,uv2,uMixRatio);_v2 uvFinal=mix(uv,uvMix,pvalue);_v2 uvTestMix=mix(valueTest,valueTest2,uMixRatio*pvalue);_v2 uvTestFinal=mix(valueTest,uvTestMix,pvalue);outColor0=_v4(normalize(uvTestMix.xy),0.,1.);}`;class Gr extends j{constructor(e){const t=a.gl;super(.15,{type:t.FLOAT,internalFormat:t.renderer.isWebgl2?t.RGBA32F:t.RGBA,wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,generateMipmaps:!1,minFilter:t.NEAREST,magFilter:t.NEAREST}),this.init({fs:Ir,textures:e,dataFroms:[c.flowData]})}render(){this.uniforms.uSeed.value=a.seed,this.uniforms.uOffset.value=a.rand()*100-50,super.render({hasToUpdateUniforms:a.renderingMode=="animated"?!a.isOver:!0})}}class Nr{constructor(){this.possibleCols=[];let e=2048;for(;e>4;)this.possibleCols.push(e),e>>=1;this.possibleLines=[];let t=1024;for(;t>4;)this.possibleLines.push(t),t>>=1}getNewRandomCellSize(e=1024){const t=[];let s=e;for(;s>4;)t.push(s),s>>=1;return s=t[a.rand2()*t.length>>0],a.size.height/s}getNextPowerOfTwo(e){const t=[];let s=e;for(;s>=2;)s&s-1||t.push(s),s>>=1;const i=a.rand2()*t.length>>0;return t[i]}getPowerOfTwoBetween(e,t){const s=[];let i=t;for(;i>=e;)i&i-1||s.push(i),i>>=1;const n=a.rand2()*s.length>>0;return s[n]}}const Or=new Nr;class G{constructor({width:e=a.size.width,height:t=a.size.height,ratio:s=1,hasToCreateDebugMesh:i=!1,renderTargetOpts:n={},willReadFrequently:l=!1}={}){this._width=e*s,this._height=t*s,this._ratio=s,this._willReadFrequently=l,this._initEngine(n),i&&this._createDebugMesh()}_initEngine(e){this.canvas=document.createElement("canvas"),this.canvas.width=this._width,this.canvas.height=this._height,this.canvas.classList.add("patterns"),this.ctx=this.canvas.getContext("2d",{willReadFrequently:this._willReadFrequently});const t={image:this.canvas,minFilter:a.gl.NEAREST,magFilter:a.gl.NEAREST,generateMipmaps:!1},s=Object.assign({},t,e);this._texture=new oe(a.gl,s)}_createDebugMesh(){this._uniforms={uTexture:{value:this._texture},uOpacity:{value:.2}},this.mesh=new Le(a.gl,{geometry:new Ve(a.gl,{width:1,height:1}),program:new ae(a.gl,{vertex:`
attribute vec2 uv;
attribute vec3 position;
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = vec4( position * 2., 1.0 );
}
`,fragment:`
precision highp float;
uniform sampler2D uTexture;
uniform float uOpacity;
varying vec2 vUv;
void main() {
gl_FragColor = texture2D( uTexture, vUv ) * uOpacity;
}
`,uniforms:this._uniforms,transparent:!0})})}createDebugView({ratioSize:e=.05,marginTop:t=10}={}){this.canvas.style.zIndex=1001,this.canvas.style.width=this._width*e+"px",this.canvas.style.height=this._height*e+"px",this.canvas.style.top=idx*this._height*e+t+"px",this.canvas.style.left="5px",this.canvas.style.transform="translate( 0, 0 )",this.canvas.style.border="2px solid #444",this.canvas.classList.add("debug"+idx),document.body.appendChild(this.canvas)}clear({clearColor:e="#000"}={}){this.ctx.fillStyle=e,this.ctx.fillRect(0,0,this._width,this._height)}draw(){}render(){}_refreshDebugMesh(){this._uniforms.uOpacity.value=.1}resize(e,t){this._width=e*this._ratio,this._height=t*this._ratio,this.canvas.width=this._width,this.canvas.height=this._height,this.canvas.style.width=this._width+"px",this.canvas.style.height=this._height+"px",this._texture.needsUpdate=!0}dispose(){this.canvas.width=0,this.canvas.height=0,this.canvas=null,this._texture.dispose()}get texture(){return this._texture}get width(){return this._width}get height(){return this._height}get ratio(){return this._ratio}}const P=()=>new Promise(requestAnimationFrame);function je(r){this.p=new Uint8Array(256),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(var e=0;256>e;e++)this.p[e]=256*a.rand();for(e=0;512>e;e++)this.perm[e]=this.p[255&e],this.permMod12[e]=this.perm[e]%12}var Vr=1/3,N=1/6;je.prototype={grad3:new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),noise3D:function(r,e,t){var s,i,n,l,o,h,d,u,f,g,_=this.permMod12,m=this.perm,p=this.grad3,w=(r+e+t)*Vr,v=Math.floor(r+w),x=Math.floor(e+w),y=Math.floor(t+w),M=(v+x+y)*N,k=v-M,S=x-M,U=y-M,C=r-k,L=e-S,D=t-U;C>=L?L>=D?(o=1,h=0,d=0,u=1,f=1,g=0):C>=D?(o=1,h=0,d=0,u=1,f=0,g=1):(o=0,h=0,d=1,u=1,f=0,g=1):D>L?(o=0,h=0,d=1,u=0,f=1,g=1):D>C?(o=0,h=1,d=0,u=0,f=1,g=1):(o=0,h=1,d=0,u=1,f=1,g=0);var A=C-o+N,I=L-h+N,q=D-d+N,H=C-u+2*N,Y=L-f+2*N,Se=D-g+2*N,De=C-1+3*N,Ce=L-1+3*N,Ae=D-1+3*N,he=255&v,ue=255&x,de=255&y,Q=.6-C*C-L*L-D*D;if(0>Q)s=0;else{var Pe=3*_[he+m[ue+m[de]]];Q*=Q,s=Q*Q*(p[Pe]*C+p[Pe+1]*L+p[Pe+2]*D)}var ee=.6-A*A-I*I-q*q;if(0>ee)i=0;else{var Te=3*_[he+o+m[ue+h+m[de+d]]];ee*=ee,i=ee*ee*(p[Te]*A+p[Te+1]*I+p[Te+2]*q)}var te=.6-H*H-Y*Y-Se*Se;if(0>te)n=0;else{var ze=3*_[he+u+m[ue+f+m[de+g]]];te*=te,n=te*te*(p[ze]*H+p[ze+1]*Y+p[ze+2]*Se)}var se=.6-De*De-Ce*Ce-Ae*Ae;if(0>se)l=0;else{var ke=3*_[he+1+m[ue+1+m[de+1]]];se*=se,l=se*se*(p[ke]*De+p[ke+1]*Ce+p[ke+2]*Ae)}return 32*(s+i+n+l)}};class K{constructor(e,t,s,i){this.x=e,this.y=t,this.width=s,this.height=i,this._lines=[],this._data=c.gridData.divisions,this._isFinal=!1,this._isEmpty=!1}divide(e=0,t=1){this._idxDivision=e,this._chanceDivision=t;const s=this.x,i=this.y;this._idxDivision<this._data.linesDivisions&&(this._lines.push({xFrom:s,yFrom:i,xTo:s+this.width,yTo:i}),this._lines.push({xFrom:s,yFrom:i,xTo:s,yTo:i+this.height}),this._lines.push({xFrom:s+this.width,yFrom:i,xTo:s+this.width,yTo:i+this.height}),this._lines.push({xFrom:s,yFrom:i+this.height,xTo:s+this.width,yTo:i+this.height}));const n=this._divide(this.x,this.y,this.width,this.height),l=a.rand2(),o=this._data.activateChanceFilling?l<this._data.chanceFilling:!0;n||(o?this._isFinal=!0:this._isEmpty=!0)}_divide(e,t,s,i){const n=a.rand2(),l=a.rand2();if(this._idxDivision>=this._data.maxDivisions||n>this._chanceDivision)return!1;c.gridData.divisionsType;let o=c.gridData.margin;const h=s/2-o*.5,d=i/2-o*.5;this._cells=[],l<.95&&(this._cells.push(new K(e,t,h,d)),this._cells.push(new K(e+h+o,t,h,d)),this._cells.push(new K(e,t+d+o,h,d)),this._cells.push(new K(e+h+o,t+d+o,h,d)));for(let u of this._cells)u.divide(this._idxDivision+1,this._chanceDivision*this._data.friction);return!0}seasonize(e,t){if(!this._isFinal){for(let o of this._cells)o.seasonize();return}let s=e.noise3D(this.x/c.gridData.divisions.noiseScale,this.y/c.gridData.divisions.noiseScale,0+a.seed),i=e.noise3D(this.x/c.gridData.divisions.noiseScale,this.y/c.gridData.divisions.noiseScale,1e3+a.seed);if(s=(s+1)/2,i=(s+1)/2,c.gridData.divisions.useMacroScale){const o=c.gridData.divisions.noiseScale*c.gridData.divisions.macroScale;let h=e.noise3D(this.x/o,this.y/o,0+a.seed);s+=h*.5}const n=c.compositionsData.layers.totalDivider,l=c.compositionsData.layers.totalDivider2;this.value=Math.floor(s*n)/(n-1),this.value3=s,this.value2=Math.floor(i*l)/l}draw=(e,t,s=1)=>{if(!this._isFinal)return;const i=this.value*255>>0,n=this.value3*255>>0,l=this.value2*255>>0,o=this.x*s,h=this.y*s,d=this.width*s,u=this.height*s;e.fillStyle="rgb("+i+","+i+","+n+")",t.fillStyle="rgb("+l+","+l+","+l+")",e.fillRect(o,h,d,u),t.fillRect(o,h,d,u)};drawLines=e=>{if(!this._isFinal)return;const t=2,s=t>>1;e.save(),e.strokeStyle="#fff",e.lineWidth=t,e.translate(this.x,this.y),e.strokeRect(-s,-s,this.width+s,this.height+s),e.restore()};drawEmpty=e=>{this._isEmpty&&(e.save(),e.fillStyle="#fff",e.translate(this.x,this.y),e.fillRect(0,0,this.width,this.height),e.restore())};collectFinalCells(e){if(this._isFinal){e.push(this);return}if(this._cells)for(const t of this._cells)t.collectFinalCells(e)}collectFinalLines(e){if(this._lines)for(let t=0;t<this._lines.length;t++)e.push(this._lines[t]);if(this._cells)for(const t of this._cells)t.collectFinalLines(e)}get finalCells(){if(this._isFinal)return[this];if(!this._cells)return[];const e=[];for(const t of this._cells){const s=t.finalCells;for(let i=0;i<s.length;i++)e.push(s[i])}return e}get lines(){let e=[...this._lines||[]];if(this._cells)for(const t of this._cells)e=e.concat(t.lines);return e}get emptyCells(){if(this._isEmpty)return[this];{let e=[];if(this._cells)for(let t of this._cells)e=e.concat(t.emptyCells);return e}}}class $r{constructor(e){this._ratio=e}generate(e=null,t,s){e==null&&this.clear(),this._ctx=e||this.ctx,this._ctx.willReadFrequently=!0,s.willReadFrequently=!0;let i=100+a.rand()*200>>0;const n=[{x:0,y:1},{x:1,y:0},{x:-1,y:0},{x:0,y:-1}];let l=[2,1];t==512&&(l=[4,2]),i=a.rand()*50+150>>0;for(let o=0;o<i;o++){const h=t/l[a.rand()*l.length>>0],d=a.size.width/h,u=a.size.height/h,f=a.rand()*d>>0,g=u*.5+a.rand()*u*.5>>0;let _=a.rand()*255>>0,m=_,p=_,w=0;if(e&&a.rand()<.5){p=0;for(let v of n){const x=(f+v.x)*h,y=(g+v.y)*h;if(x>=0&&x<a.size.width&&y>=0&&y<a.size.height){let M=this._getImageData(this._ctx,x,y,1,1);p+=M,M=this._getImageData(s,x,y,1,1),w++}}w>0&&(p=p/w>>0,_=p>127?Math.max(0,p-100):Math.min(255,p+100),m=p>127?Math.max(0,p-100):Math.min(255,p+100))}this._ctx.fillStyle=`rgba( ${_}, ${_}, ${_}, .5 )`,this._fillRect(this._ctx,f*h,g*h,h,h),a.rand()<.8&&(s.fillStyle=`rgba( ${m}, ${m}, ${m}, .5 )`,this._fillRect(s,f*h,g*h,h,h))}e==null&&(this.texture.needsUpdate=!0)}generateVertLines(e=null,t,s){this._ctx=e;let i=30+a.rand()*40>>0,n=1;switch(t){case 512:n=4;break;case 256:n=2;break;case 128:n=2;break}for(let l=0;l<i;l++){const o=t/n,h=a.size.height/o,d=a.size.width/o,u=a.rand()*d>>0,f=1+a.rand()*h*.5>>0,g=a.size.height/o;let _=(a.rand()*(g-Math.ceil(f/o))>>0)*o,m=a.rand()*75>>0;m=0;let p=m+75+a.rand()*100>>0;if(p=255,_<a.size.height*.5){let x=m;m=p,p=x}const w=_/o,v=f/w>>0;_-=o;for(let x=0;x<w;x++){const y=u*o,M=_+x*o*v;let k=0,S=0,U=0,C=0;y>0&&(k=this._getImageData(this._ctx,y-o,M),S=this._getImageData(s,y-o,M)),y+o<a.size.width&&(U=this._getImageData(this._ctx,y+o,M),C=this._getImageData(s,y+o,M));let L=m+(p-m)*x/w>>0,D=L;const A=(k+U)/2;Math.abs(L-A)<50&&(L=A>127?Math.max(0,A-100):Math.min(255,A+100));const I=(S+C)/2;Math.abs(D-I)<50&&(D=I>127?Math.max(0,I-100):Math.min(255,I+100)),this._ctx.fillStyle=`rgba(${L}, ${L}, ${L}, .85)`,this._fillRect(this._ctx,y,M,o,o*v),s.fillStyle=`rgba(${D}, ${D}, ${D}, .85)`,this._fillRect(s,y,M,o,o*v)}}}generateVertLines2(e=null,t,s){this._ctx=e,this._ctx.willReadFrequently=!0,s.willReadFrequently=!0;let i=30+a.rand()*40>>0,n=1;switch(t){case 512:n=4;break;case 256:n=2;break;case 128:n=2;break}for(let l=0;l<i;l++){const o=t/n,h=a.size.height/o,d=a.size.width/o,u=a.rand()*d>>0,f=1+a.rand()*h*.5>>0,g=a.size.height/o,_=a.size.height-(a.rand()*(g-Math.ceil(f/o))>>0)*o-o*f;let m=a.rand()*75>>0;m=0;let p=m+75+a.rand()*100>>0;if(p=255,_>a.size.height*.5){let v=m;m=p,p=v}const w=f;for(let v=0;v<w;v++){const x=u*o,y=_+v*o;let M=0,k=0,S=0,U=0;x>0&&(M=this._getImageData(this._ctx,x-o,y),k=this._getImageData(s,x-o,y)),x+o<a.size.width&&(S=this._getImageData(this._ctx,x+o,y),U=this._getImageData(s,x+o,y));let C=m+(p-m)*v/w>>0,L=C;const D=(M+S)/2;Math.abs(C-D)<50&&(C=D>127?Math.max(0,D-100):Math.min(255,D+100));const A=(k+U)/2;Math.abs(L-A)<50&&(L=A>127?Math.max(0,A-100):Math.min(255,A+100)),this._ctx.fillStyle=`rgba(${C}, ${C}, ${C}, .85)`,this._fillRect(this._ctx,x,y,o,o),s.fillStyle=`rgba(${L}, ${L}, ${L}, .85)`,this._fillRect(s,x,y,o,o)}}}_fillRect(e,t,s,i,n){e.fillRect(t*this._ratio,s*this._ratio,i*this._ratio,n*this._ratio)}_getImageData(e,t,s){return e.getImageData(t*this._ratio,s*this._ratio,1,1).data[0]}}class jr extends G{constructor(){const t={flipY:!1};super({renderTargetOpts:t,ratio:.25,willReadFrequently:!0}),this._textures=[],this._gridLines=new G({renderTargetOpts:t}),this._gridScene=new G({renderTargetOpts:t,ratio:.25,willReadFrequently:!0}),this._gridCustom=new $r(.25),this._noise=new je(a.rand2)}getNoiseValues(e,t){const s=Math.floor(e/this._cellSizeMin),i=Math.floor(t/this._cellSizeMin);return this._noiseCompiled[i][s]}async generate(e){this._cellSize=e,this._cells=[],this._finalCells=null;const t=c.gridData,s=t.margin,i=a.size.width/e,n=a.size.height/e,l=(a.size.width-s*(i+1))/i,o=(a.size.height-s*(n+1))/n;let h=s,d=s;for(let u=0;u<n;u++){for(let f=0;f<i;f++){const g=new K(h,d,l,o);g.divide(0,t.divisions.chance),this._cells.push(g),h+=l+s}h=s,d+=o+s,await P()}this._finalCells=[],this._finalLines=[],this._finalLines.push({xFrom:s,yFrom:s,xTo:a.size.width-s,yTo:s}),this._finalLines.push({xFrom:s,yFrom:s,xTo:s,yTo:a.size.height-s}),this._finalLines.push({xFrom:a.size.width-s,yFrom:s,xTo:a.size.width-s,yTo:a.size.height-s}),this._finalLines.push({xFrom:s,yFrom:a.size.height-s,xTo:a.size.width-s,yTo:a.size.height-s});for(const u of this._cells)u.collectFinalCells(this._finalCells),u.collectFinalLines(this._finalLines)}async seasonize(){let e=0;for(let t of this.finalCells)t.seasonize(this._noise,this),e++,e%1e3===0&&await P()}async render(){this.clear({clearColor:"#000"}),this._gridLines.clear(),this._gridScene.clear();let e=0;for(let t of this._finalCells)t.draw(this.ctx,this._gridScene.ctx,this._ratio),e%1e3==0&&await P(),e+=1;a.generator.isBroken&&(this._customizeGrid(),this._gridCustom.generate(this._gridScene.ctx,this._cellSize,this.ctx),a.generator.isBrokenVerticaly&&this._gridCustom.generateVertLines(this._gridScene.ctx,this._cellSize,this.ctx),a.generator.isExtraBrokenVerticaly&&this._gridCustom.generateVertLines2(this._gridScene.ctx,this._cellSize,this.ctx)),await P(),this.texture.needsUpdate=!0,this._gridScene.texture.needsUpdate=!0,this._gridLines.ctx.strokeStyle="rgba(255, 255, 255, 0.8)",this._gridLines.ctx.lineCap="square";for(let t of this.finalLines){if(!t||a.rand()>c.gridData.divisions.chanceDrawLine)continue;const s=t.xFrom===t.xTo,i=1+a.rand3()*6>>0;for(let n=0;n<i;n++)this._gridLines.ctx.beginPath(),this._gridLines.ctx.lineWidth=c.gridPatternData.width,s?(this._gridLines.ctx.moveTo(t.xFrom+a.rand()*8-4,t.yFrom+a.rand()*4-2),this._gridLines.ctx.lineTo(t.xTo+a.rand()*8-4,t.yTo+a.rand()*4-2)):(this._gridLines.ctx.moveTo(t.xFrom+a.rand()*4-2,t.yFrom+a.rand()*8-4),this._gridLines.ctx.lineTo(t.xTo+a.rand()*4-2,t.yTo+a.rand()*8-4)),this._gridLines.ctx.stroke(),this._gridLines.ctx.closePath()}await P(),this._gridLines.texture.needsUpdate=!0}_customizeGrid(){this._cellSize=this._cellSize;const e=a.size.width/this._cellSize,t=a.size.height/this._cellSize;if(Math.floor(a.size.width/this._cellSize),Math.floor(a.size.height/this._cellSize),a.generator.isBroken)for(let s=0;s<e;s++){let i=-1;const n=a.rand3();if(n<.33?i=a.rand3()*255:n<.66?i=a.rand3()*125:n<.75&&(i=-2),i!=-1)for(let l=0;l<t;l++){i==-2&&(i=l%2===0?25:150,s%4===0?i=l%2===0?25:150:s%4===1?i=l%2===0?125:10:s%4===2?i=200:s%4===3&&(i=l%2===0?25:225));const o=s*this._cellSize,h=l*this._cellSize;this._gridScene.ctx.fillStyle=`rgba(${i}, ${i}, ${i}, 0.5)`,this._gridScene.ctx.fillRect(o*this._ratio,h*this._ratio,this._cellSize*this._ratio,this._cellSize*this._ratio)}}for(let s=0;s<10;s++)for(let i=0;i<e;i++){if(a.rand()<.25)return;const n=i*this._cellSize,l=s*this._cellSize;this.ctx.fillStyle=`rgba(${10}, ${10}, ${10}, 0.25)`,this.ctx.fillRect(n*this._ratio,l*this._ratio,this._cellSize*this._ratio,this._cellSize*this._ratio)}}get finalCells(){return this._finalCells}get finalLines(){return this._finalLines}get textures(){return this._textures}get textureLines(){return this._gridLines.texture}get textureUV(){return this._gridUV.texture}get textureEmpty(){return this._gridEmpty.texture}get textureScene(){return this._gridScene.texture}}class qr extends G{constructor(){const e={flipY:!1};super({renderTargetOpts:e,ratio:.1})}render(e){this.clear();for(const t of e)this._renderBranch(t);this.texture.needsUpdate=!0}_renderBranch(e){this._renderLeaves(e)}_renderLeaves(e){for(const t of e.leaves){const s=this.ctx,i=this._createLinearGradient(s,t.x-t.size,t.y,t.x+t.size,t.y);i.addColorStop(0,"rgba(0,0,255,1)"),i.addColorStop(1,"rgba(255,0,255,1)");const n=this._createLinearGradient(s,t.x,t.y-t.size,t.x,t.y+t.size);n.addColorStop(0,"rgba(0,0,255,1)"),n.addColorStop(1,"rgba(0,255,255,1)"),s.save(),s.beginPath(),this._rect(s,t.x-t.size,t.y-t.size,t.size*2,t.size*2),s.clip(),s.fillStyle=i,this._fillRect(s,t.x-t.size,t.y-t.size,t.size*2,t.size*2),s.globalCompositeO