0x1808bbab…0434sent to0x5306e34b…cbe7·#21,017,678·view on Etherscan
let f=_rotate(_createV(0,map(p,0,this.hPoints,this.h,0)),0,0,n);f.x+=this.x,f.y+=this.y,this.points.push(f),this.lineSegVis.push(!0)}this.calculateBoundingBox()}}function sqr(e){return e*e}function dist2(e,t){return sqr(e.x-t.x)+sqr(e.y-t.y)}function distToSegmentSquared(e,t,_){var $=dist2(t,_);if(0==$)return dist2(e,t);var i=((e.x-t.x)*(_.x-t.x)+(e.y-t.y)*(_.y-t.y))/$;return i=Math.max(0,Math.min(1,i)),dist2(e,{x:t.x+i*(_.x-t.x),y:t.y+i*(_.y-t.y)})}function distToSegment(e,t,_){return Math.sqrt(distToSegmentSquared(e,t,_))}class _WeightedLine extends _Rect{constructor(e,t,_,$,i,n){let a;super(e,t,dist(e,t,_,$),i,n,atan2($-t,_-e)),this.a=_createV(e,t),this.b=_createV(_,$),this.dir=_sub(this.b,this.a),this.centerOffset=_rotate(_setMag(this.dir,i/2),0,0,PI/2),this.lengthOffset=_setMag(this.dir,10),this.a=_add(this.a,this.centerOffset),this.b=_add(this.b,this.centerOffset),this.wt=i}pointInside(e){return distToSegment(e,_sub(this.a,this.lengthOffset),_add(this.b,this.lengthOffset))<.5*this.wt}}class _Ellipse extends _Shape{constructor(e,t,_,$,i,n){super(!0),this.x=e,this.y=t,this.w=_,this.h=$,this.nPoints=n;for(let a=0;a<this.nPoints;a++){let r=map(a,0,this.nPoints,0,TAU),s=this.w*cos(r),l=this.h*sin(r),o=_rotate(_createV(s,l),0,0,i);o.x+=this.x,o.y+=this.y,this.points.push(o),this.lineSegVis.push(!0)}this.calculateBoundingBox()}}let petalPalette,stemPalette,leafPalette,grassPalette,petalColor,lightPalette;function pickPalette(e){if(print("palette",e),1==e){petalPalette=[[color("#386270"),color("#7d8cb5"),color("#cda7e4"),color("#ec8880"),color("#f79c66"),color("#f8efaf"),],[color("#386270"),color("#799f89"),color("#cda7e4"),color("#fde6d7"),color("#e1f4fd"),]],stemPalette=[color("#354e6f"),color("#4a887a"),color("#799f89"),color("#f8efaf"),];let t=color("#223f6a"),_=color("#3e6d95"),$=color("#99bfbf"),i=color("#e2dd7a");leafPalette=[t,t,_,_,_,$,$,i,i,color("#ffdf5e"),],grassPalette=[color("#354e6f"),color("#7d8cb5"),color("#799f89"),color("#ca830b"),color("#ec8880"),color("#f7c066"),color("#efdb50"),color("#efc9d7"),color("#f8efaf"),],lightPalette=[color("#1a172f"),color("#29264E"),color("#354e6f"),color("#efdb50"),color("#efc9d7"),color("#f8efaf"),]}else if(2==e){petalPalette=[[color("#47448a"),color("#f7ae06"),color("#f5c607"),color("#fadf47"),color("#fbe773"),]],stemPalette=[color("#624835"),color("#926b50"),color("#ab8263"),color("#b997b6"),color("#d5b67b"),];let n=color("#547666"),a=color("#577769"),r=color("#7ba488"),s=color("#ece980");leafPalette=[n,n,n,a,a,r,r,r,s,s,],grassPalette=[color("#577769"),color("#4b837a"),color("#4b837a"),color("#5277cf"),color("#92bc63"),color("#91d2a6"),color("#d6dd42"),color("#d6dd42"),color("#ece980"),color("#ece980"),]}else if(4==e){petalPalette=[[color("#300a0d"),color("#f2520d"),color("#f1960e"),color("#f3cc54"),color("#f8de8f"),color("#faeab8"),],[color("#324578"),color("#dcc1ff"),color("#fdd9fa"),color("#feffe1"),color("#fdf7e1"),]],stemPalette=[color("#1f3630"),color("#839f63"),color("#9ea859"),];let l=color("#4f7442"),o=color("#9fca75"),h=color("#efdd61");leafPalette=[color("#1f3630"),color("#1f3630"),l,l,o,o,color("#bad06f"),h,h,];let p=color("#f3d354");grassPalette=[color("#3e446c"),color("#4b7a67"),color("#406cbf"),color("#d6967c"),color("#f1ad0e"),p,p,p,color("#ece3bb"),]}}function paletteLerp(e,t,_){if(_){let $=floor(map(t,0,1,0,e.length-1)),i;i=$+1;let n=e[constrain($,0,e.length-1)],a=e[constrain(i,0,e.length-1)];return lerpColor(n,a,t*(e.length-1)-$)}{let r=floor(map(t,0,1,0,e.length-1));return e[constrain(r,0,e.length-1)]}}function prepHeightmap(){noiseDetail(1,.25);let e=.006*1.5*(targetSzX/600);for(let t=0;t<mapW;t++){let _=[];for(let $=0;$<mapH;$++){let i=pow(map($,0,mapH,0,1),2)*map(pow(1*fractalNoise({x:t*e*2.5,y:0,z:$*e*5,nOctaves:2,scaleFallout:2,weightFallout:.5}),1),0,1,0,1);_.push(doubleExponentialSigmoid(i,0))}terrainHt.push(_)}for(let n=0;n<mapW-1;n++){let a=[],r=[];for(let s=0;s<mapH-1;s++){let l=_normalize(_createV(terrainHt[n+1][s]-terrainHt[n][s],0,terrainHt[n][s+1]-terrainHt[n][s]));r.push(l),a.push(map(-_dot(l,lightDir),-1,1,.9,1))}lightMap.push(a),terrainNorm.push(r)}noiseDetail(3,.5)}function heightMap(e,t){let _=constrain(floor(map(e,-(1.2*targetSzX)/2,1.2*targetSzX/2,0,mapW)),0,mapW-1),$=constrain(floor(map(t,-maxZ,maxZ,0,mapH)),0,mapH-1);return -500*terrainHt[_][$]}function terrainLight(e,t){let _=floor(map(e,-(1.2*targetSzX)/2,1.2*targetSzX/2,0,mapW)),$=floor(map(t,-maxZ,maxZ,0,mapH));return _>=0&&_<=mapW-2&&$>=0&&$<=mapH-2?lightMap[_][$]:1}function setTerrainLight(e,t,_){let $=floor(map(e,-(1.2*targetSzX)/2,1.2*targetSzX/2,0,mapW)),i=floor(map(t,-maxZ,maxZ,0,mapH));$>=0&&$<=mapW-2&&i>=0&&i<=mapH-2&&(lightMap[$][i]=_)}function placeShadow(e,t,_,$){for(let i=-_;i<=_;i++)for(let n=-(1*_);n<=1*_;n++){let a=sq(i)+sq(n/1),r=sq(_);a<r&&setTerrainLight(i+e,n+t,max(0,terrainLight(i+e,n+t)-map(a,0,r,$,0)))}}let saveMode=!1,saving=!1,saveTime=0,doDownload=!1,canv,targetSzX,targetSzY,heightToWidth=.8,sizeAdjust,mag=1,canvSzX,canvSzY,margin=0,booleanShapes=[],hashes=[],bgHashes=[],maxZ=2e3,terrainHt=[],lightMap=[],terrainNorm=[],mapW=100,mapH=175,slopeDir,lightAngle,lightDir,lightLeftRight,toEye,crayonShader,blendShader,geometryBuffer,crayonBuffer,drawnBuffer,renderMode="texture",unionBuffer=[],unionBufferW,unionBufferH,bgColor,vertShader="precision lowp float;varying vec2 var;attribute vec3 aPosition;attribute vec2 aTexCoord;void main(){var=aTexCoord;vec4 v=vec4(aPosition,1);v.xy=v.xy*2.-1.;gl_Position=v;}",crayonFragShader="precision highp float;varying vec2 var;uniform sampler2D u3;uniform vec2 u4,u5;uniform float u2;float v(float v,float u){return u+v*(1.-u);}float v(vec2 u){return fract(sin(dot(u,vec2(12.9898,4.1414)))*43758.5453);}float u(vec2 u){u*=vec2(1,u5.y/u5.x);vec2 w=floor(u+u4);u=fract(u+u4);u=u*u*(3.-2.*u);float f=mix(mix(v(w),v(w+vec2(1,0)),u.x),mix(v(w+vec2(0,1)),v(w+vec2(1)),u.x),u.y);return f*f;}void main(){vec2 w=vec2(v(var.x,-1.),v(var.y,-1.));vec3 f=vec3(5e-4,.00025,0);float z=(v(u(w*4e2),0.)+v(u(w*8e2),0.)*.5+v(u(w*1600.),0.)*.25)/1.75,x=u(w*50.)*3.14159*2.;vec4 m=texture2D(u3,var+vec2(cos(x),sin(x))*5e-4),r;if(m.w==0.)r=vec4(0);else r.xyz=m.xyz,r.w=m.w,r.w*=step(.6,v(1.-z,u2));r.w*=v(pow((texture2D(u3,var+f.xz).w+texture2D(u3,var-f.xz).w+texture2D(u3,var+f.zy).w+texture2D(u3,var-f.zy).w)/4.,.2),.8);gl_FragColor=r;}",blendFragShader=`precision highp float;varying vec2 var;uniform sampler2D u6,u7;uniform float u1;
#ifndef SPECTRAL
#define SPECTRAL
float v(float v){return v<.04045?v/12.92:pow((v+.055)/1.055,2.4);}float f(float v){return v<.0031308?v*12.92:1.055*pow(v,1./2.4)-.055;}vec3 w(vec3 f){return vec3(v(f[0]+.01),v(f[1]+.01),v(f[2]+.01));}vec3 t(vec3 v){return clamp(vec3(f(v[0]-.01),f(v[1]-.01),f(v[2]-.01)),0.,1.);}void f(vec3 v,inout float f[7]){f[0]=0.;f[1]=0.;f[2]=0.;f[3]=0.;f[4]=0.;f[5]=0.;f[6]=0.;if(v[0]<=v[1]&&v[0]<=v[2]){f[0]=v[0];if(v[1]<=v[2])f[1]=v[1]-v[0],f[6]=v[2]-v[1];else f[1]=v[2]-v[0],f[5]=v[1]-v[2];}else if(v[1]<=v[0]&&v[1]<=v[2]){f[0]=v[1];if(v[0]<=v[2])f[2]=v[0]-v[1],f[6]=v[2]-v[0];else f[2]=v[2]-v[1],f[4]=v[0]-v[2];}else if(v[2]<=v[0]&&v[2]<=v[1]){f[0]=v[2];if(v[0]<=v[1])f[3]=v[0]-v[2],f[5]=v[1]-v[0];else f[3]=v[1]-v[2],f[4]=v[0]-v[1];}}void t(vec3 v,inout float i[38]){float p[7];f(v,p);i[0]=p[0]+p[1]*.96853629+p[2]*.51567122+p[3]*.02055257+p[4]*.03147571+p[5]*.49108579+p[6]*.97901834;i[1]=p[0]+p[1]*.96855103+p[2]*.5401552+p[3]*.02059936+p[4]*.03146636+p[5]*.46944057+p[6]*.97901649;i[2]=p[0]+p[1]*.96859338+p[2]*.62645502+p[3]*.02062723+p[4]*.03140624+p[5]*.4016578+p[6]*.97901118;i[3]=p[0]+p[1]*.96877345+p[2]*.75595012+p[3]*.02073387+p[4]*.03119611+p[5]*.2449042+p[6]*.97892146;i[4]=p[0]+p[1]*.96942204+p[2]*.92826996+p[3]*.02114202+p[4]*.03053888+p[5]*.0682688+p[6]*.97858555;i[5]=p[0]+p[1]*.97143709+p[2]*.97223624+p[3]*.02233154+p[4]*.02856855+p[5]*.02732883+p[6]*.97743705;i[6]=p[0]+p[1]*.97541862+p[2]*.98616174+p[3]*.02556857+p[4]*.02459485+p[5]*.013606+p[6]*.97428075;i[7]=p[0]+p[1]*.98074186+p[2]*.98955255+p[3]*.03330189+p[4]*.0192952+p[5]*.01000187+p[6]*.96663223;i[8]=p[0]+p[1]*.98580992+p[2]*.98676237+p[3]*.05185294+p[4]*.01423112+p[5]*.01284127+p[6]*.94822893;i[9]=p[0]+p[1]*.98971194+p[2]*.97312575+p[3]*.10087639+p[4]*.01033111+p[5]*.02636635+p[6]*.89937713;i[10]=p[0]+p[1]*.99238027+p[2]*.91944277+p[3]*.24000413+p[4]*.00765876+p[5]*.07058713+p[6]*.76070164;i[11]=p[0]+p[1]*.99409844+p[2]*.32564851+p[3]*.53589066+p[4]*.00593693+p[5]*.70421692+p[6]*.4642044;i[12]=p[0]+p[1]*.995172+p[2]*.13820628+p[3]*.79874659+p[4]*.00485616+p[5]*.85473994+p[6]*.20123039;i[13]=p[0]+p[1]*.99576545+p[2]*.05015143+p[3]*.91186529+p[4]*.00426186+p[5]*.95081565+p[6]*.08808402;i[14]=p[0]+p[1]*.99593552+p[2]*.02912336+p[3]*.95399623+p[4]*.00409039+p[5]*.9717037+p[6]*.04592894;i[15]=p[0]+p[1]*.99564041+p[2]*.02421691+p[3]*.97137099+p[4]*.00438375+p[5]*.97651888+p[6]*.02860373;i[16]=p[0]+p[1]*.99464769+p[2]*.02660696+p[3]*.97939505+p[4]*.00537525+p[5]*.97429245+p[6]*.02060067;i[17]=p[0]+p[1]*.99229579+p[2]*.03407586+p[3]*.98345207+p[4]*.00772962+p[5]*.97012917+p[6]*.01656701;i[18]=p[0]+p[1]*.98638762+p[2]*.04835936+p[3]*.98553736+p[4]*.0136612+p[5]*.9425863+p[6]*.01451549;i[19]=p[0]+p[1]*.96829712+p[2]*.0001172+p[3]*.98648905+p[4]*.03181352+p[5]*.99989207+p[6]*.01357964;i[20]=p[0]+p[1]*.89228016+p[2]*8.554e-5+p[3]*.98674535+p[4]*.10791525+p[5]*.99989891+p[6]*.01331243;i[21]=p[0]+p[1]*.53740239+p[2]*.85267882+p[3]*.98657555+p[4]*.46249516+p[5]*.13823139+p[6]*.01347661;i[22]=p[0]+p[1]*.15360445+p[2]*.93188793+p[3]*.98611877+p[4]*.84604333+p[5]*.06968113+p[6]*.01387181;i[23]=p[0]+p[1]*.05705719+p[2]*.94810268+p[3]*.98559942+p[4]*.94275572+p[5]*.05628787+p[6]*.01435472;i[24]=p[0]+p[1]*.03126539+p[2]*.94200977+p[3]*.98507063+p[4]*.96860996+p[5]*.06111561+p[6]*.01479836;i[25]=p[0]+p[1]*.02205445+p[2]*.91478045+p[3]*.98460039+p[4]*.97783966+p[5]*.08987709+p[6]*.0151525;i[26]=p[0]+p[1]*.01802271+p[2]*.87065445+p[3]*.98425301+p[4]*.98187757+p[5]*.13656016+p[6]*.01540513;i[27]=p[0]+p[1]*.0161346+p[2]*.78827548+p[3]*.98403909+p[4]*.98377315+p[5]*.22169624+p[6]*.01557233;i[28]=p[0]+p[1]*.01520947+p[2]*.65738359+p[3]*.98388535+p[4]*.98470202+p[5]*.32176956+p[6]*.0156571;i[29]=p[0]+p[1]*.01475977+p[2]*.59909403+p[3]*.98376116+p[4]*.98515481+p[5]*.36157329+p[6]*.01571025;i[30]=p[0]+p[1]*.01454263+p[2]*.56817268+p[3]*.98368246+p[4]*.98537114+p[5]*.4836192+p[6]*.01571916;i[31]=p[0]+p[1]*.01444459+p[2]*.54031997+p[3]*.98365023+p[4]*.98546685+p[5]*.46488579+p[6]*.01572133;i[32]=p[0]+p[1]*.01439897+p[2]*.52110241+p[3]*.98361309+p[4]*.98550011+p[5]*.47440306+p[6]*.01572502;i[33]=p[0]+p[1]*.0143762+p[2]*.51041094+p[3]*.98357259+p[4]*.98551031+p[5]*.4857699+p[6]*.01571717;i[34]=p[0]+p[1]*.01436343+p[2]*.50526577+p[3]*.98353856+p[4]*.98550741+p[5]*.49267971+p[6]*.01571905;i[35]=p[0]+p[1]*.01435687+p[2]*.5025508+p[3]*.98351247+p[4]*.98551323+p[5]*.49625685+p[6]*.01571059;i[36]=p[0]+p[1]*.0143537+p[2]*.50126452+p[3]*.98350101+p[4]*.98551563+p[5]*.49807754+p[6]*.01569728;i[37]=p[0]+p[1]*.01435408+p[2]*.50083021+p[3]*.98350852+p[4]*.98551547+p[5]*.49889859+p[6]*.0157002;}vec3 x(vec3 f){mat3 p;p[0]=vec3(3.24306333,-1.53837619,-.49893282);p[1]=vec3(-.96896309,1.87542451,.04154303);p[2]=vec3(.05568392,-.20417438,1.05799454);float v=dot(p[0],f),i=dot(p[1],f),r=dot(p[2],f);return t(vec3(v,i,r));}vec3 p(float p[38]){return vec3(0)+p[0]*vec3(6.469e-5,1.84e-6,.00030502)+p[1]*vec3(.00021941,6.21e-6,.00103681)+p[2]*vec3(.00112057,3.101e-5,.00531314)+p[3]*vec3(.00376661,.00010475,.01795439)+p[4]*vec3(.01188055,.00035364,.05707758)+p[5]*vec3(.02328644,.00095147,.11365162)+p[6]*vec3(.03455942,.00228226,.17335873)+p[7]*vec3(.03722379,.00420733,.19620658)+p[8]*vec3(.03241838,.0066888,.18608237)+p[9]*vec3(.02123321,.0098884,.13995048)+p[10]*vec3(.01049099,.01524945,.08917453)+p[11]*vec3(.00329584,.02141831,.04789621)+p[12]*vec3(.00050704,.03342293,.02814563)+p[13]*vec3(.00094867,.05131001,.01613766)+p[14]*vec3(.00627372,.07040208,.0077591)+p[15]*vec3(.01686462,.08783871,.00429615)+p[16]*vec3(.02868965,.09424905,.00200551)+p[17]*vec3(.04267481,.09795667,.00086147)+p[18]*vec3(.05625475,.09415219,.00036904)+p[19]*vec3(.0694704,.08678102,.00019143)+p[20]*vec3(.08305315,.07885653,.00014956)+p[21]*vec3(.0861261,.0635267,9.231e-5)+p[22]*vec3(.09046614,.05374142,6.813e-5)+p[23]*vec3(.08500387,.04264606,2.883e-5)+p[24]*vec3(.07090667,.03161735,1.577e-5)+p[25]*vec3(.05062889,.02088521,3.94e-6)+p[26]*vec3(.03547396,.01386011,1.58e-6)+p[27]*vec3(.02146821,.00810264,0)+p[28]*vec3(.01251646,.0046301,0)+p[29]*vec3(.00680458,.00249138,0)+p[30]*vec3(.00346457,.0012593,0)+p[31]*vec3(.00149761,.00054165,0)+p[32]*vec3(.0007697,.00027795,0)+p[33]*vec3(.00040737,.00014711,0)+p[34]*vec3(.00016901,6.103e-5,0)+p[35]*vec3(9.522e-5,3.439e-5,0)+p[36]*vec3(4.903e-5,1.771e-5,0)+p[37]*vec3(2e-5,7.22e-6,0);}float f(float v,float p,float f){p*=pow(f,2.);return p/(v*pow(1.-f,2.)+p);}vec3 p(vec3 v,vec3 i,float r){float u[38],m[38];t(w(v),u);t(w(i),m);float S=p(u)[1],z=p(m)[1];r=f(S,z,r);float e[38];for(int i=0;i<38;i++){float p=(1.-r)*(pow(1.-u[i],2.)/(2.*u[i]))+r*(pow(1.-m[i],2.)/(2.*m[i]));e[i]=1.+p-sqrt(pow(p,2.)+2.*p);}return x(p(e));}vec4 p(vec4 v,vec4 f,float i){return vec4(p(v.xyz,f.xyz,i),mix(v.w,f.w,i));}
#endif
void main(){vec4 v=texture2D(u6,vec2(var.x,1.+var.y*-1.)),f=texture2D(u7,var),i,r=p(v,f,f.w);i=mix(v*mix(vec4(1),f,u1),r,.2);gl_FragColor=i;}`,rSeed,nSeed,sNoise;function setup(){rSeed=round(random(1e7)),nSeed=round(random(1e7));let e,t=[{rSeed:8077733,nSeed:4239393},{rSeed:6335389,nSeed:7709717},{rSeed:6711193,nSeed:8046416,paletteOverride:2},{rSeed:6862698,nSeed:8114669},{rSeed:7897312,nSeed:3981128},{rSeed:9340939,nSeed:9852448,paletteOverride:2},{rSeed:7589951,nSeed:9385453},{rSeed:4526625,nSeed:6452396},{rSeed:7838216,nSeed:8818273},{rSeed:7882561,nSeed:1244},{rSeed:7732610,nSeed:8393707}][parseInt(tokenData.tokenId)%1e6];rSeed=t.rSeed,nSeed=t.nSeed;let _=t.paletteOverride;sNoise=new openSimplexNoise(nSeed),print(rSeed,nSeed),randomSeed(rSeed),noiseSeed(nSeed),prepareCanvas(1e3),background(200),geometryBuffer=createGraphics(canvSzX,canvSzY),drawnBuffer=createGraphics(canvSzX,canvSzY,WEBGL),crayonBuffer=createGraphics(canvSzX,canvSzY,WEBGL),geometryBuffer.background(color("#d0c6b9")),drawnBuffer.background(color("#b0a394")),crayonBuffer.background(0),geometryBuffer.noSmooth(),crayonShader=crayonBuffer.createShader(vertShader,crayonFragShader),blendShader=drawnBuffer.createShader(vertShader,blendFragShader),unionBufferW=targetSzX,unionBufferH=targetSzY;for(let $=0;$<unionBufferW*unionBufferH;$++)unionBuffer.push(!1);slopeDir=random([-1,1]),lightAngle=random([PI/2+PI/4,-PI/4]),print(degrees(lightAngle)),toEye=createVector(0,1,-1).normalize(),lightDir=_normalize(_createV(cos(lightAngle),-.8,sin(lightAngle))),prepHeightmap(),print("perspectiveType",perspectiveType),print("perspectivePower",perspectivePower),print("perspectiveShift",perspectiveShift),booleanShapes=[],hashes=[],pickPalette(random([1,2,4])),_&&pickPalette(_),bgColor=color("#f4eaea"),random(1),random(1);let i,n,a=random(100,120);for(let r=0;r<2;r++)for(let s=0;s<1;s++){let l=_rotate(_createV(map(r,0,max(1,1),-1,1)*a*2,0,100*map(r,0,max(1,1),-1,1)),0,0,0);l.z+=350,l.y=heightMap(l.x,l.z);let o;print("nSegs",20),o=stem({basePos:l,nSegs:20,branchNSegsFunc:function(e,t,_,$){let i;return max(ceil((e-t)*(i=_==$?.5:1==_?.1:2.7)),1)},branchPlacementFunc:function(){return 0},pitch:0,roll:PI,weightFunc:function(e,t){return e==t?.8:.3},weight:12,baseDepth:4,depth:4,trunk:!0,_basePos:l,branchProbLerpVal:0,baseBranchProb:-.15,tipBranchProb:2.5,fruitProb:.1,type:"fruit tree",trunkTwistAngle:PI/1.5,leafMultiplier:1,nChildBranchesMin:1,nChildBranchesMax:1,leafProbTip:2,petalPalette:petalPalette[0],trunkWonkNoiseScale:.1,branchWonkNoiseScale:.1,branchWindStrength:1,minTrunkWindStrength:0,maxTrunkWindStrength:1,minChildBranchAngle:PI/5,maxChildBranchAngle:PI/2.5,stemPalette:stemPalette,nTrunkGrowthDirections:2,straightTrunkStrengthBase:.025,straightTrunkStrengthTip:.0125,straightBaseExp:1});for(let h=0;h<o.length;h++){let p=o[h];if(p.fruit&&(n=i,i=p.tipPos,ball({flowerRotation:_createV(p.pitch,0,p.roll+PI),flowerTranslation:p.tipPos,flowerProportions:_createV(100,100,200),flowerScale:1.1*random(.35,.35),xExtents:.5,nPetals:2,scl:p.flowerScale,stem:p,palette:p.petalPalette,br:doubleExponentialSigmoid(pow(norm(_dot(_normalize(p.normal),_scalarMult(lightDir,1)),-1,1),1),.5)}),.3>random(1))){let f=_add(_createV(p.tipPos.x,heightMap(p.tipPos.x,p.tipPos.z)+3,p.tipPos.z),_rotate(_createV(random(100),0,0),0,random(TAU),0));ball({flowerRotation:_createV(p.pitch,0,p.roll+PI),flowerTranslation:f,flowerProportions:_createV(100,100,200),flowerScale:1.1*random(.35,.35),xExtents:.5,nPetals:2,scl:p.flowerScale,stem:p,palette:p.petalPalette,br:constrain(pow(terrainLight(f.x,f.z),1)+.1*random(-1,1),0,1)}),placeShadow(f.x,f.z,3,1)}for(let u=0;u<p.leaves.length;u++){let d=p.leaves[u],c=_createV(0,random(-1,1)*PI/4,p.roll+PI),g=_createV(120,100,20),m=1*random(.25,.3),v=pow(doubleExponentialSigmoid(norm(_dot(_normalize(d.normal),_scalarMult(lightDir,1)),-1,1),0),1),x=pow(doubleExponentialSigmoid(norm(_dot(_normalize(p.normal),_scalarMult(lightDir,1)),-1,1),.8),2),b=lerp(v,x,.7);if(cupShape({xSegments:4,ySegments:4,transforms:[{type:"s",val:_scalarMult(g,m)},{type:"r",val:c},{type:"t",val:d}],xMinExtent:-.3,xMaxExtent:.3,yMinExtent:0,yMaxExtent:1,palette:leafPalette,br:b,brLerp:.4,contrast:0,drawPolygonLines:!0}),.05>random(1)){let S=_createV(d.x,heightMap(d.x,d.z)-13,d.z);cupShape({xSegments:4,ySegments:4,transforms:[{type:"s",val:_scalarMult(g,m)},{type:"r",val:_createV(PI/2,0,0)},{type:"r",val:_createV(0,random(TAU),0)},{type:"t",val:S}],xMinExtent:-.3,xMaxExtent:.3,yMinExtent:0,yMaxExtent:1,palette:leafPalette,br:constrain(pow(terrainLight(d.x,d.z),1)+.2*random(-1,1),0,1),brLerp:.8,contrast:0,drawPolygonLines:!1})}}}}for(let y=0;y<15e3;y++){let w=1200*random(1),z=_createV(map(w,0,1200,1,1.03)*random(-1,1)*targetSzX*1.2/2,0,w);z.y=heightMap(z.x,z.z);let k=pow(terrainLight(z.x,z.z),1)+.2*random(-1,1);grassShape({pos:z,scale:_createV(10,random(5,20),0),palette:grassPalette,br:k})}addHashes(),booleanShapes.sort(function(e,t){return t.zIndex-e.zIndex});var P=performance.now();occlude();var B=performance.now();print("occluding time:",B-P),P=performance.now(),hashes.sort(function(e,t){return t.zIndex-e.zIndex}),print("sorting time:",(B=performance.now())-P)}function stem(e){let t=_copyV(e.basePos),_=_rotate(_createV(0,25,0),e.pitch,0,e.roll),$=[_3dTo2d(e.basePos)];$[0].weightAdjust=1;let i=e.pitch,n=0,a=e.roll,r=[],s=[],l=[],o=e.nTrunkGrowthDirections,h=[];if(e.trunk)for(let p=0;p<o;p++)if(p==o-1)l.push({targetOffset:PI+random([-1,1])*random(.5,1)*PI/2,turnStep:.3});else if(0==p)l.push({targetOffset:PI,turnStep:.8});else{let f=sNoise.noise3D(.01*t.x+p*e.trunkWonkNoiseScale+1213,.01*t.y+p*e.trunkWonkNoiseScale+12213,.01*t.z+p*e.trunkWonkNoiseScale+12421)*e.trunkTwistAngle+PI;l.push({targetOffset:f,turnStep:.5})}else for(let u=0;u<2;u++)if(0==u)h.push({targetOffset:-PI,turnStep:.2});else if(1==u){if(0==e.depth)h.push({targetOffset:0,turnStep:random(.5,.8)});else{let d=sNoise.noise3D(.001*t.x+u*e.branchWonkNoiseScale+1321213,.001*t.y+u*e.branchWonkNoiseScale+122153,.001*t.z+u*e.branchWonkNoiseScale+1242211)*PI/16+PI;h.push({targetOffset:d,turnStep:.2})}}else{let c=random([-1,1])*random(0,1)*PI;h.push({targetOffset:c,turnStep:.2})}let g=1;for(let m=0;m<e.nSegs;m++){let v=!1;if(e.depth>0){let x=round(map(m,0,e.nSegs,e.nChildBranchesMin,e.nChildBranchesMax));for(let b=0;b<x;b++)if(e.trunk&&m==e.nSegs-1||random(1)<map(m,0,e.nSegs-1,e.baseBranchProb,(e.trunk?.85:1)*e.tipBranchProb)){let S=_add(t,_lerp(_createV(),_,e.branchPlacementFunc())),y=sNoise.noise3D(.8*S.x,.8*S.z,b);y=map(m,e.nSegs,0,e.minChildBranchAngle,e.maxChildBranchAngle)*(y>0?1:-1);let w=stem({basePos:S,nSegs:e.branchNSegsFunc(e.nSegs,m,e.depth,e.baseDepth),branchNSegsFunc:e.branchNSegsFunc,branchPlacementFunc:e.branchPlacementFunc,pitch:i+random([-1,1])*random(PI/5,PI/3)*1,roll:a+1*y,weightFunc:e.weightFunc,weight:e.weight*e.weightFunc(e.depth,e.baseDepth),baseDepth:e.baseDepth,depth:max(0,e.depth-round(random(1,map(m,0,e.nSegs,1,e.depth)))),trunk:!1,_basePos:e._basePos,branchProbLerpVal:e.branchProbLerpVal,baseBranchProb:e.baseBranchProb,baseBranchProb:lerp(e.baseBranchProb,e.tipBranchProb,e.branchProbLerpVal),tipBranchProb:e.tipBranchProb,fruitProb:e.fruitProb,type:e.type,trunkTwistAngle:e.trunkTwistAngle,leafMultiplier:e.leafMultiplier,nChildBranchesMin:e.nChildBranchesMin,nChildBranchesMax:e.nChildBranchesMax,leafProbTip:e.leafProbTip,petalPalette:e.petalPalette,trunkWonkNoiseScale:e.trunkWonkNoiseScale,branchWonkNoiseScale:e.branchWonkNoiseScale,trunkBranchAngleExp:e.trunkBranchAngleExp,branchWindStrength:e.branchWindStrength,minTrunkWindStrength:e.minTrunkWindStrength,maxTrunkWindStrength:e.maxTrunkWindStrength,minChildBranchAngle:e.minChildBranchAngle,maxChildBranchAngle:e.maxChildBranchAngle,stemPalette:e.stemPalette,nTrunkGrowthDirections:e.nTrunkGrowthDirections,straightTrunkStrengthBase:e.straightTrunkStrengthBase,straightTrunkStrengthTip:e.straightTrunkStrengthTip,straightBaseExp:e.straightBaseExp});for(let z=0;z<w.length;z++)r.push(w[z]);v=!0}}let k,P;if(e.trunk){let B=floor(pow(map(m,0,e.nSegs,0,1),.5)*l.length);k=l[B].targetOffset,k+=lerpAngle(k,PI,expSkewMap(m,0,e.nSegs,e.straightTrunkStrengthBase,e.straightTrunkStrengthTip,e.straightBaseExp)),P=l[B].turnStep}else{let V=floor(map(m,0,e.nSegs,0,h.length));k=h[V].targetOffset,P=h[V].turnStep}let M=sNoise.noise3D(.004*t.x+124213,.004*t.y+124213,.012*t.z+124213)*map(m,0,e.nSegs,PI/16,PI/32),T=lerpAngle(i,n=sNoise.noise2D(.03*t.x+14213,.03*t.z+12423)*PI/2,e.trunk?0:.2)+M;i+=T,_=_rotate(_,T,0,0);let W=lerpAngle(a,0+k,P)+M*(e.trunk?map(m,0,e.nSegs,e.minTrunkWindStrength,e.maxTrunkWindStrength):e.branchWindStrength)+(v?e.depth/3*PI/16:0)*random([-1,1]);a+=W,_=_rotate(_,0,0,W);let A=max(1,ceil(.1*_mag(_)));for(let q=0;q<A;q++){let j=map(q,0,A,0,1),H=_add(t,_scalarMult(_,j)),X=_add(_scalarMult(_createV(cos(lightAngle),sin(lightAngle)),(H.y-heightMap(H.x,H.z))*.25),_rotate(_createV(40*pow((e._basePos.y-H.y)*.001,2)+1,0),0,0,random(TAU)));placeShadow(H.x+X.x,H.z+X.y,3,max(0,.1*pow((1-(e._basePos.y-H.y)*.001)*2-1,2)))}t=_add(t,_),g*=v?.95:1;let D=_3dTo2d(t);if(D.weightAdjust=g,D.weight=e.weight*g,$.push(D),random(1)<pow(map(m,-1,e.nSegs,0,e.leafProbTip),1)*(e.trunk?.5:1)){let Y=.05*_mag(_)*e.leafMultiplier;for(let F=0;F<Y;F++){let I;I=0==e.depth?random(.25):random(1);let E=_add(_add(t,_scalarMult(_,I)),_createV(0,0,0*random(-1,1)));E.normal=_normalize(_),s.push(E)}}}let L=[],N=[],C,O=0;for(let R=0;R<$.length;R++){let U,Z,J,G,K;if(R<$.length-1){J=$[R];let Q=_sub(G=$[R+1],J);C=O,O=atan2(Q.y,Q.x),K=C+lerpAngle(C,O,.5)}else J=$[R],K=O=C;0==R&&(K=e.roll+PI/2);let ee=max(1.5,e.weight*$[R].weightAdjust);U=_rotate(_createV(0,-ee,0),0,0,K),Z=_rotate(_createV(0,ee,0),0,0,K);let et=_add(U,J),e_=_add(Z,J);et.hashAngle=O,e_.hashAngle=O,L.push(et),N.push(e_)}for(let e$=0;e$<L.length-1;e$++){let e0=max(2,round(.23*$[e$].weight));for(let ei=0;ei<e0;ei++){let en=map(ei,0,e0,0,1),ea=map(ei+1,0,e0,0,1),er=_scalarMult(_normalize(_rotate(_sub($[e$+1],$[e$]),0,0,PI/2)),map(ei,0,e0-1,-1,1)),es=doubleExponentialSigmoid(pow(norm(_dot(er,lightDir),-1,1),1),.8),el=new _Shape(!0);el.setPoints([_lerp(L[e$],N[e$],en),_lerp(L[e$+1],N[e$+1],en),_lerp(L[e$+1],N[e$+1],ea),_lerp(L[e$],N[e$],ea),]);let eo=constrain(map($[e$].y,_3dTo2d(e.basePos).y,_3dTo2d(e.basePos).y-200,0,1),0,1),eh=lerp(es,eo,.5);el.fill=paletteLerp(e.stemPalette,eh,!0),el.zIndex=e.basePos.z,el.occlude=!0,el.hashWeight=1.5,el.nHashesMult=.9,el.scaleAmt=3,el.hashAngle=L[e$].hashAngle,el.nSegments=1,booleanShapes.push(el)}}let ep={tipDir:_,tipPos:t,pitch:i,roll:a,flowerScale:random(.5,1),normal:_sub(t,_add(e._basePos,_createV(0,-350,0))),leaves:s,basePos:e._basePos,fruit:random(1)<e.fruitProb,petalPalette:e.petalPalette};return 0==e.depth?[ep]:(r.push(ep),r)}function cupShape(e){var t=function(e,t,_){return sqrt(1-sq(map(e,t,_,-1,1)))};for(let _=0;_<e.x