0x1808bbab…0434sent to0x99a9b7c1…b069·#18,287,315·view on Etherscan
iform("U3",3),shaderBuffer.rect(-targetSzX/2,-targetSzY/2,targetSzX,targetSzY),shaderBuffer.pop(),materialBuffer.image(shaderBuffer,0,0),materialBuffer.loadPixels();let e=ceil(random(cloudTimeOffset-1e5*floor(cloudTimeOffset/1e5))/1e3);print("count",e);for(let a=0;a<e;a++)random(1)}else{if(push(),scale(sizeAdjust,sizeAdjust),packingHouse){for(let $=0;$<1e3;$++)if(FG())fail=0;else if(++fail>4e5||0==el_pts.length&&$>10){print("done packing",packedPoints.length),packingHouse=!1,packingLand=!0;for(let t=0;t<8e3;t++)el_pts.push(Fa(random(targetSzX),random(targetSzY)));break}}else if(packingLand){for(let _=0;_<1e3;_++)if(FE([0,1,4]))fail=0;else if(++fail>6e5||0==el_pts.length&&_>10){print("done packing",packedPoints.length),packingLand=!1,packingSky=!0;for(let r=0;r<2e3;r++)el_pts.push(Fa(random(targetSzX),random(targetSzY)));break}}else if(packingSky){let l=0==skyType?FD:FE;for(let i=0;i<1e3;i++)if(l([2],1))fail=0;else if(++fail>4e6||0==el_pts.length&&i>10){print("done packing",packedPoints.length),packingSky=!1,packingClouds=!0;for(let f=0;f<8e3;f++)el_pts.push(Fa(random(targetSzX),random(.4*targetSzY)));print("drawingFills"),background(color("#dfd8ce"));break}}else if(packingClouds){for(let n=0;n<1e3;n++)if(FE([2],0))fail=0;else if(++fail>4e6||0==el_pts.length&&n>10){print("done packing",packedPoints.length),packingClouds=!1,packedPoints.sort(function(e,a){return-(e.xyz.z-a.xyz.z)}),background(color("#dfd8ce"));break}}else for(let o=0;o<1e3;o++)if(strokeWeight(1),drawInd<packedPoints.length){let s=packedPoints[drawInd],u=s.center.x,c=s.center.y;if(stroke(inkColor),"grass"==s.type){let p=Fi(Fc(Fa(1,-1,1)),s.nrm),d=map(atan2(p.x,p.y),-PI,PI,s.amin,s.amax),F=round(map(pow(1.1*Fl({x:15*s.xyz.x+100,y:15*s.xyz.z+1023,z:0,nOctaves:3,scaleFallout:2.5,weightFallout:.5}),3),0,1,5,15)),m=map(pow(1*Fl({x:.3*s.xyz.x-100,y:.3*s.xyz.z-2023,z:0,nOctaves:3,scaleFallout:2.5,weightFallout:.5}),1),0,1,-1,1)*PI/3;if(s.burned)line(u-.8*F*cos(d+=random(-1,1)*PI/8+(1-s.burnedAmt)*PI/2),c-.8*F*sin(d),u+.8*F*cos(d),c+.8*F*sin(d));else{let x=noise(10*s.xyz.x+1020,10*s.xyz.z+1231);if(x<.25*random(1)){let h=5/(s.xyz.z+2),y=-(2*F)*(x+1)/(s.xyz.z+2);push(),translate(u,c),rotate(d+random(-1,1)*PI/8),line(0,y,0,0),push(),translate(0,y),rotate(random(PI));let g=ceil(random(2,3));for(let z=0;z<g;z++)rotate(PI/g+random(-1,1)*PI/8),line(-h,0,h,0);pop(),pop()}FH(u,c,F,d,m)}}else if("leaves"==s.type){let v=noise(.1*s.xyz.x+1e3,.1*s.xyz.z+-1023),b=sunPosX<0?1:-1,S=map(1.1*Fl({x:5*s.xyz.x+-1500,y:5*s.xyz.z+9082,z:0,nOctaves:1,scaleFallout:2.5,weightFallout:.5}),0,1,-1,1),U=Fi(Fc(Fa(b,-1,1)),Fd(Fe(s.nrm,Fa(1,1,S)),Fa(0,.7,map(v,0,1,-.4,-1)))),k=map(atan2(U.x,U.y),-PI,PI,s.amin,s.amax)-PI/6+random(-1,1)*PI/8,D=1.5*round(map(pow(1.1*Fl({x:10*s.xyz.x+100,y:10*s.xyz.z+1023,z:0,nOctaves:3,scaleFallout:2.5,weightFallout:.5}),3),0,1,3,10));flameFactor>0&&s.lightR>100&&0==s.lightB&&stroke(255,0,0),line(u-D*cos(k),c-D*sin(k),u,c)}else if("house"==s.type){let B=dist(s.p1.x,s.p1.y,s.p2.x,s.p2.y),q=ceil(1*B);if(B<=2)flameFactor>0&&s.lightR>100&&0==s.lightB&&stroke(255,0,0),line(s.p1.x,s.p1.y,s.p2.x,s.p2.y);else for(let M=0;M<q;M++){let P=map(M,0,q-1,0,1),w=map(M+1,0,q-1,0,1);flameFactor>0&&s.lightR>100&&0==s.lightB&&stroke(255,0,0),line(lerp(s.p1.x,s.p2.x,P),lerp(s.p1.y,s.p2.y,P),lerp(s.p1.x,s.p2.x,w),lerp(s.p1.y,s.p2.y,w))}}else if("fire"==s.type){if(flameFactor>0){let X=Fi(Fc(Fa(1,-1,1)),Fd(s.nrm,Fa(0,0,0))),Y=-map(atan2(X.x,X.y),-PI,PI,s.amin,s.amax),W=map(noise(10*s.xyz.x,10*s.xyz.y,10*s.xyz.z),0,1,0,1),A=map(pow(noise(20*s.xyz.x,0,20*s.xyz.z),1),0,1,0,1);stroke(255,150*A,0);let H=map(W,0,1,1,2.5);line(u-cos(Y)*s.radius*H*.5,c-sin(Y)*s.radius*H*.5,u+cos(Y)*s.radius*.5,c+sin(Y)*s.radius*.5)}}else if(void 0==s.pts)strokeWeight(1.5),point(u,c);else{strokeWeight(.5);for(let I=0;I<s.pts.length-1;I++)line(s.pts[I].p.x,s.pts[I].p.y,s.pts[I+1].p.x,s.pts[I+1].p.y)}drawInd++}else{print("done rendering"),noLoop();break}pop()}}function FD(){let e=16,a=null;for(;el_pts.length>0&&null==a;)Fx(a=el_pts.pop(),packingBuffer)&&(a=null);null==a&&(a=Fa(random(targetSzX),random(targetSzY)));let $,t,_=0;if(!Fx(a,packingBuffer)){let r=FF(a);if(2!=(t=r.materialId))return;_++,$=r.lightG,e=map(a.y,0,targetSzY,8,32);let l=function(e,a){let $=Fl({x:(targetSzX/2-e)*.0016*map(a,0,targetSzY*map(skyAngle,-.3,-.2,.2,.5),.8,1)+13200,y:.0016*a+10216323,z:0,nOctaves:2,scaleFallout:3,weightFallout:.8});$=map($,0,1,-1,1)*TAU;let t=e-targetSzX/2+map(sunPosX,-8,8,1,-1)*targetSzX*.4,_=a-targetSzY/2+map(skyAngle,-.3,-.2,.2,0)*targetSzX,r=pow(map(sqrt(sq(t)+sq(_)),0,targetSzX/2,0,1),1);return atan2(_,t)+PI/2+$*map(r,0,1,0,.5)},i=l(a.x,a.y),f=random([-1,1]),n=Fk(Fa(f,0),i,0,0),o=Fd(a,n),s=[{p:a,r:e}],u=null;for(let c=0;c<200;c++){u=Fb(o),o=Fd(o,n),cloudNs=Fw(o.x,o.y),i=l(o.x,o.y),n=Fk(Fa(f,0),i,0,0);let p=FF(o).materialId;e=map(o.y,0,targetSzY,8,32);if(2==p&&!Fx(o,packingBuffer)&&cloudNs<.25)_++,FC(o,1*e),s.push({p:Fb(o),r:e});else{if(null!=u){for(let d=0;d<s.length-1;d++)line(s[d].p.x,s[d].p.y,s[d+1].p.x,s[d+1].p.y),FB(s[d].p,s[d+1].p,max(1*s[d].r,.5),packingBuffer);packedPoints.push({center:Fb(a),radius:e,type:"sky",pts:s,xyz:r.xyz})}return}}a=null}}function FE(e,a){let $=8,t=null;for(;el_pts.length>0&&null==t;)Fx(t=el_pts.pop(),packingBuffer)&&(t=null);if(null==t&&(t=Fa(random(targetSzX),random(targetSzY))),!Fx(t,packingBuffer)){let _=FF(t),r=_.materialId,l=_.lightG;if(2==r){let i=Fw(t.x,t.y);if(0==a){let f=Fw(t.x+map(sunPosX,-8,8,1,-1),t.y+1);$=f<i&&i<.4?map(i-f,0,.008,3,15):15}else if(1==a&&($=4*map(l,0,255,materials[r].rmin,materials[r].rmax)*random(.98,1.02),i>.25))return}let n=!1;for(let o=0;o<e.length;o++)if(r==e[o]){n=!0;break}if(!n)return;2!=r&&(_.burned?$*=map(pow(map(l,0,255,0,1),2),0,1,materials[r].rmin,lerp(materials[r].rmax,materials[r].rmin,_.burnedAmt))*map(noise(5*_.xyz.x,5*_.xyz.z),0,1,1,2)*map(l,0,255,.6,1):$*=map(l,0,255,materials[r].rmin,materials[r].rmax)),FA(t.x,t.y,$,$,packingBuffer),square(t.x,t.y,.5*$),packedPoints.push({center:Fb(t),radius:$,type:["grass","leaves","sky","house","fire"][r],amin:materials[r].amin,amax:materials[r].amax,nrm:_.nrm,xyz:_.xyz,lightR:_.lightR,lightG:_.lightG,lightB:_.lightB,burned:_.burned,burnedAmt:_.burnedAmt}),FC(t,$),t=null}}function FF(e){let a=floor(map(e.x,0,targetSzX,0,bufferWidth)),$=floor(map(e.y,0,targetSzY,0,bufferHeight)),t=(a+$*lightBuffer.width)*4,_=materialBuffer.pixels[t+0]>128?1:0,r=materialBuffer.pixels[t+1]>128?1:0,l=materialBuffer.pixels[t+2]>128?1:0,i=!1,f=0,n=0;1==_&&1==l?n=3:1==_&&1==r?n=4:materialBuffer.pixels[t+1]>0&&materialBuffer.pixels[t+2]>0?(n=0,i=!0,f=materialBuffer.pixels[t+2]/255):1==_?n=0:1==r?n=1:1==l&&(n=2);let o=lightBuffer.pixels[t+0],s=lightBuffer.pixels[t+1],u=lightBuffer.pixels[t+2],c=map(normalBuffer.pixels[t+0],0,255,-1,1),p=map(normalBuffer.pixels[t+1],0,255,-1,1),d=map(normalBuffer.pixels[t+2],0,255,-1,1),F=Fa(c,p,d),m=map(xyzBuffer.pixels[t+0],0,255,-1,1),x=map(xyzBuffer.pixels[t+1],0,255,-1,1),h=map(xyzBuffer.pixels[t+2],0,255,-1,1);return{materialId:n,lightR:o,lightG:s,lightB:u,nrm:F,xyz:Fa(m,x,h),burned:i,burnedAmt:f}}function FG(){let e=8,a=null;for(;el_pts.length>0&&null==a;)Fx(a=el_pts.pop(),packingBuffer)&&(a=null);null==a&&(a=Fa(random(targetSzX),random(targetSzY)));let $,t,_=0;if(!Fx(a,packingBuffer)){let r=FF(a);if(3!=(t=r.materialId))return;_++,e*=map($=r.lightG,0,255,materials[t].rmin,materials[t].rmax);let l=r.nrm,i=Fk(l,0,-houseAngle,0),f=2*map(i.x/i.z,-1,1,-TAU,TAU)+PI/2,n=Fk(Fa(random([-1,1]),0),f,0,0),o=Fd(a,n),s=null;for(let u=0;u<1e3;u++){s=Fb(o),o=Fd(o,n);let c=FF(o),p=c.materialId,d=c.lightG,F=c.nrm;if(3==p&&!Fx(o,packingBuffer)&&Fh(l,F)/(Fg(l)*Fg(F))>.5&&5>abs($-d))_++,FC(o,1*e);else{if(null!=s){Fy(a.x,a.y,.25,packingBuffer),FB(a,s,max(1*e,.5),packingBuffer),line(a.x,a.y,s.x,s.y);let m=FF(s);packedPoints.push({center:Fb(a),radius:e,type:"house",amin:materials[t].amin,amax:materials[t].amax,nrm:l,p1:a,p2:s,xyz:c.xyz,lightR:c.lightR,lightG:c.lightG,lightB:c.lightB,lightR2:m.lightR,lightG2:m.lightG,lightB2:m.lightB})}return}}a=null}}function FH(e,a,$,t,_){let r=Fa(e,a),l=Fk(Fa(0,-1),t,0,0);for(let i=0;i<$;i++){let f=map(i,0,$,1,0),n=Fb(r);r=Fd(r,l);let o=map(noise(.01*e,.01*a,2*i),0,1,-1,1)*_*f;l=Fk(l,o,0,0),line(n.x,n.y,r.x,r.y)}}function FI(){targetSzX=floor((targetSzY=1e3)/heightToWidth),print("here 2"),print("targetSzX",targetSzX),print("targetSzY",targetSzY),windowHeight/windowWidth>heightToWidth?(canvSzX=windowWidth*mag,canvSzY=round(windowWidth*heightToWidth*mag)):(canvSzY=windowHeight*mag,canvSzX=round(windowHeight/heightToWidth*mag))}function FJ(){houseX=random(-2,2),houseZ=random(-6,6);for(let e=0;e<2e4;e++){let a=floor(map(houseX,-10,10,0,mapW)),$=floor(map(houseZ,-10,10,mapH,0)),t=Fs(a,$,terrainNoiseScale,terrainHt),_=Ft(a,$,terrainNoiseScale,terrainHt),r=Fr(a,$,terrainNoiseScale,1),l=Fr(a,$-25,terrainNoiseScale,1),i=Fr(a,$-10,terrainNoiseScale,1);if(sq(t)+sq(_)<1e-5&&r>i&&r>l&&_<0){print("done",e);break}houseX=random(1,3)*random([-1,1]),houseZ=random(-6,6)}houseScale=map(houseZ,-6,7,.8,.7),houseW=.5,houseH=map(houseZ,-6,7,.42,.5),houseD=.2,houseAngle=map(abs(houseX),2,5,PI/8,PI/3)*(houseX<0?1:-1)}function FK(){burnStart=round(random(289,319)),burnDuration=round(random(10,15)),print("burnStart",burnStart),print("burnDuration",burnDuration);let e=new Date,a=new Date(e.getFullYear(),0,0),$=Math.floor((e-a)/864e5)-burnStart;console.log("Day's since burning:",$),cloudTimeOffset=Date.now(),timeOffset=Date.now()/1e7,(flameFactor=max(map($,0,burnDuration,0,flameFactorMax),0))>flameFactorMax&&(flameFactor=0,print("fire is done"))}function FL(){materials.push({rmin:.55,rmax:1.4,amin:-PI/1.5+PI/4,amax:PI/1.5+PI/4}),materials.push({rmin:.43,rmax:.7,amin:0+PI/4,amax:TAU+PI/4}),materials.push({rmin:4,rmax:1,amin:0,amax:0}),materials.push({rmin:.2,rmax:.45,amin:0,amax:TAU}),materials.push({rmin:.4,rmax:.8,amin:-TAU,amax:TAU})}function FM(){bufferWidth=floor(2*targetSzX),bufferHeight=floor(2*targetSzY),print("here 3"),print("bufferWidth",bufferWidth),print("bufferHeight",bufferHeight);for(let e=0;e<bufferWidth;e++){let a=new Uint8Array(bufferHeight);for(let $=0;$<bufferHeight;$++)a[$]=1;packingBuffer.push(a)}for(let t=0;t<2e3;t++)el_pts.push(Fa(map(houseX,-3,3,.22,.78)*targetSzX+random(-1,1)*targetSzX*.1,map(houseZ,6,-6,.4,.78)*targetSzY+random(-1,1)*targetSzY*.15));lightBuffer=createGraphics(bufferWidth,bufferHeight),normalBuffer=createGraphics(bufferWidth,bufferHeight),xyzBuffer=createGraphics(bufferWidth,bufferHeight),materialBuffer=createGraphics(bufferWidth,bufferHeight),myShader=(shaderBuffer=createGraphics(bufferWidth,bufferHeight,WEBGL)).createShader(vertShader,fragShader)}