let canvas,seed,R,S,featuresInt,featuresReadable;const ratio=.76,colVarParams={hMin:-2.5,hMax:2.5,sMin:-2.5,sMax:15,bMin:-10,bMax:5},bgVarParams={hMin:-5,hMax:5,sMin:-10,sMax:2.5,bMin:-2.5,bMax:5},thicknessDivFactorLowRangeMin=1.75,thicknessDivFactorLowRangeMax=2,thicknessDivFactorHiRangeMin=.5,thicknessDivFactorHiRangeMax=.75,textureSoftLightAlpha=8,textureOverlayAlpha=10,paths=[[{x:.7,y:.07},{x:.59,y:.04},{x:.22,y:.09},{x:.14,y:.16},{x:.23,y:.21},{x:.57,y:.18},{x:.51,y:.12},{x:.54,y:.05},{x:.64,y:.08},{x:.59,y:.18},{x:.7,y:.2},{x:.87,y:.3},{x:.9,y:.59},{x:.81,y:.7},{x:.89,y:.85},{x:.74,y:.66},{x:.8,y:.4},{x:.72,y:.24},{x:.58,y:.19},{x:.5,y:.27},{x:.6,y:.3},{x:.63,y:.24},{x:.61,y:.31},{x:.74,y:.33},{x:.61,y:.54},{x:.07,y:.61},{x:.16,y:.78},{x:.6,y:.81},{x:.92,y:.91},{x:.55,y:.65},{x:.38,y:.34},{x:.22,y:.29},{x:.16,y:.38},{x:.21,y:.66},{x:.27,y:.77},{x:.19,y:.86},],[{x:.71,y:.1},{x:.54,y:.03},{x:.27,y:.06},{x:.08,y:.09},{x:.07,y:.16},{x:.23,y:.23},{x:.64,y:.21},{x:.68,y:.14},{x:.55,y:.06},{x:.43,y:.09},{x:.47,y:.16},{x:.64,y:.2},{x:.8,y:.2},{x:.87,y:.34},{x:.89,y:.57},{x:.81,y:.83},{x:.9,y:.95},{x:.67,y:.78},{x:.79,y:.5},{x:.63,y:.22},{x:.48,y:.3},{x:.53,y:.38},{x:.6,y:.37},{x:.65,y:.3},{x:.6,y:.37},{x:.72,y:.41},{x:.65,y:.51},{x:.1,y:.65},{x:.07,y:.79},{x:.14,y:.88},{x:.5,y:.91},{x:.84,y:.94},{x:.59,y:.83},{x:.45,y:.6},{x:.32,y:.39},{x:.13,y:.29},{x:.1,y:.34},{x:.11,y:.43},{x:.16,y:.73},{x:.2,y:.9},{x:.12,y:.94},],[{x:.69,y:.09},{x:.56,y:.03},{x:.26,y:.07},{x:.16,y:.09},{x:.14,y:.16},{x:.26,y:.21},{x:.56,y:.21},{x:.67,y:.13},{x:.54,y:.06},{x:.43,y:.1},{x:.56,y:.21},{x:.76,y:.19},{x:.89,y:.29},{x:.91,y:.55},{x:.75,y:.82},{x:.89,y:.91},{x:.7,y:.82},{x:.77,y:.64},{x:.71,y:.55},{x:.76,y:.23},{x:.67,y:.21},{x:.64,y:.27},{x:.6,y:.22},{x:.51,y:.31},{x:.62,y:.34},{x:.67,y:.34},{x:.68,y:.44},{x:.64,y:.62},{x:.14,y:.63},{x:.07,y:.72},{x:.31,y:.78},{x:.67,y:.85},{x:.69,y:.73},{x:.69,y:.61},{x:.6,y:.56},{x:.39,y:.42},{x:.26,y:.29},{x:.16,y:.29},{x:.17,y:.43},{x:.25,y:.69},{x:.23,y:.82},{x:.12,y:.91},],[{x:.75,y:.04},{x:.63,y:.03},{x:.31,y:.07},{x:.32,y:.12},{x:.55,y:.14},{x:.77,y:.17},{x:.75,y:.12},{x:.78,y:.06},{x:.89,y:.04},{x:.95,y:.1},{x:.91,y:.17},{x:.79,y:.2},{x:.88,y:.27},{x:.85,y:.53},{x:.87,y:.71},{x:.83,y:.79},{x:.71,y:.78},{x:.65,y:.62},{x:.69,y:.43},{x:.79,y:.23},{x:.61,y:.21},{x:.56,y:.26},{x:.62,y:.31},{x:.69,y:.28},{x:.62,y:.34},{x:.62,y:.59},{x:.23,y:.64},{x:.12,y:.71},{x:.14,y:.79},{x:.51,y:.79},{x:.71,y:.71},{x:.6,y:.62},{x:.49,y:.45},{x:.32,y:.25},{x:.19,y:.23},{x:.16,y:.35},{x:.25,y:.76},{x:.21,y:.86},{x:.16,y:.88},],[{x:.61,y:.06},{x:.27,y:.07},{x:.11,y:.12},{x:.11,y:.17},{x:.24,y:.17},{x:.55,y:.19},{x:.67,y:.21},{x:.73,y:.16},{x:.59,y:.08},{x:.55,y:.19},{x:.67,y:.21},{x:.87,y:.27},{x:.88,y:.43},{x:.87,y:.71},{x:.7,y:.93},{x:.68,y:.64},{x:.79,y:.35},{x:.66,y:.26},{x:.51,y:.32},{x:.57,y:.37},{x:.64,y:.3},{x:.6,y:.37},{x:.72,y:.39},{x:.64,y:.49},{x:.33,y:.54},{x:.1,y:.63},{x:.1,y:.74},{x:.23,y:.86},{x:.8,y:.93},{x:.59,y:.82},{x:.48,y:.6},{x:.36,y:.38},{x:.19,y:.3},{x:.15,y:.38},{x:.1,y:.45},{x:.18,y:.73},{x:.2,y:.89},{x:.12,y:.93},],[{x:.76,y:.07},{x:.16,y:.07},{x:.16,y:.17},{x:.76,y:.17},{x:.76,y:.11},{x:.67,y:.11},{x:.67,y:.17},{x:.91,y:.17},{x:.91,y:.81},{x:.8,y:.81},{x:.8,y:.22},{x:.55,y:.22},{x:.56,y:.32},{x:.64,y:.32},{x:.64,y:.26},{x:.67,y:.26},{x:.67,y:.32},{x:.74,y:.32},{x:.74,y:.48},{x:.12,y:.48},{x:.12,y:.81},{x:.71,y:.81},{x:.71,y:.61},{x:.37,y:.61},{x:.37,y:.24},{x:.23,y:.24},{x:.23,y:.87},{x:.11,y:.87},],[{x:.42,y:.2},{x:.29,y:.15},{x:.16,y:.17},{x:.09,y:.23},{x:.15,y:.29},{x:.33,y:.31},{x:.43,y:.27},{x:.39,y:.22},{x:.33,y:.26},{x:.39,y:.31},{x:.42,y:.41},{x:.5,y:.58},{x:.52,y:.73},{x:.46,y:.84},{x:.15,y:.74},{x:.16,y:.61},{x:.28,y:.51},{x:.43,y:.38},{x:.5,y:.3},{x:.46,y:.29},{x:.55,y:.46},{x:.51,y:.42},{x:.54,y:.29},{x:.61,y:.26},{x:.66,y:.28},{x:.68,y:.33},{x:.66,y:.4},{x:.67,y:.35},{x:.76,y:.31},{x:.84,y:.35},{x:.84,y:.43},{x:.76,y:.62},{x:.81,y:.69},{x:.93,y:.71},],],blue="#0a4f9c",red="#de1215",green="#1aa588",black="#181617",paper="#FBF9EA",classicPalettes=[[green,red,blue],[red],[blue],],colorPalette=[blue,red,green,black,"#ede5d8","#ac1972","#ebca49","#e98110"];let points=[],colors=[];function calculateFeatures($){switch((featuresInt={}).style=[0,1,2][R.weighted_index([.5,.2,.3])],featuresInt.style){case 0:colors=classicPalettes[R.weighted_index([.1,.2,.7])],featuresInt.bg=getColorVariation(paper,bgVarParams);break;case 1:colors=[...colorPalette],featuresInt.bg=colors.splice(colors.indexOf(black),1),colors=R.random_bool(.8)?[paper]:colors.splice(R.random_int(0,colors.length-1),1);break;case 2:colors=[...colorPalette],featuresInt.bg=colors.splice(R.random_int(0,colors.length-1),1)}featuresInt.pathIndex=R.weighted_index([.1,.1,.1,.1,.1,.1,.02]),featuresInt.minSegmentSize=R.random_int(3,7),featuresInt.probSegment=R.random_num(0,.25),featuresInt.probSmooth=R.random_num(.5,1),featuresInt.erraticness=R.random_num(.1,.5),points=paths[featuresInt.pathIndex],featuresReadable={};let e;switch(featuresInt.style){case 0:e="Classic";break;case 1:e="Lino";break;case 2:e="Cut Color"}return featuresReadable.Style=e,featuresReadable.Line=featuresInt.pathIndex<6?numberToRoman(featuresInt.pathIndex+1):"GM",console.log("featuresReadable:",featuresReadable),featuresReadable}function setup(){init(),noLoop()}function draw(){render()}function init(){console.log(`tokenData.hash: ${tokenData.hash}`);let $,e;window.innerHeight<=window.innerWidth/.76?($=.76*Math.max(window.innerHeight,1),e=Math.max(window.innerHeight,1)):($=Math.max(window.innerWidth),e=Math.max(window.innerWidth,1)/.76),console.log(`Canvas w:${$} h:${e}`),createCanvas($,e),pixelDensity(2*displayDensity()),seed=parseInt(tokenData.hash.slice(0,16),16),R=new Random,S=new SimplexNoise(seed),calculateFeatures(tokenData)}function render(){background(featuresInt.bg);let $=segmentPath(points,featuresInt.probSegment,featuresInt.minSegmentSize),e=[];for(let n=0;n<$.length;n++){let r={points:$[n],thickness:R.random_num(.04,.06),erraticness:R.random_dec(),col:0==featuresInt.style?getColorVariation(R.random_choice(colors),colVarParams):R.random_choice(colors)};r.poly=getPolyFromStroke(r.points,r.thickness,r.erraticness),r.poly=smoothPoly(r.poly,3,!0,featuresInt.probSmooth),e.push(r),r.strokePoly=getPolyFromStroke(r.poly,.004,.1);let _=[];for(let t=0;t<R.random_int(5,15);t++){let o={};o.col=getColorVariation(R.random_choice(colors),colVarParams),o.highlightCol=getColorVariation(R.random_choice(["#ffffff","#000000"]),bgVarParams);let a=R.random_num(.1,.25),y=R.random_num(0,TAU),x=R.random_dec(),l=R.random_dec(),s=[];for(let i=y;i<TAU+y;i+=TAU/R.random_int(3,10)){let u=a*R.random_num(.5,1),m=x+u*Math.cos(i),d=l+u*Math.sin(i);s.push({x:m,y:d})}s=smoothPoly(s,3,!0,.75),o.poly=s,o.expandedPoly=scalePoly(s,R.random_num(.002,.004)),o.expandedPolyAlpha=R.random_num(90,120),_.push(o)}r.patches=_}featuresInt.segments=e,console.log("featuresInt:",featuresInt);for(let h=0;h<featuresInt.segments.length;h++){let c=featuresInt.segments[h],f=createGraphics(width,height),g=f.canvas.getContext("2d");for(let p of(g.clearRect(0,0,width,height),g.globalCompositeOperation="destination-over",f.beginShape(),f.fill(1!=featuresInt.style?featuresInt.bg:R.random_choice(colors)),f.noStroke(),c.strokePoly))f.vertex(p.x*width,p.y*height);if(f.endShape(CLOSE),1!=featuresInt.style){for(let b of(f.beginShape(),f.fill(c.col),f.noStroke(),c.poly))f.vertex(b.x*width,b.y*height);f.endShape(CLOSE),g.globalCompositeOperation="source-over",g.clip(),2!=featuresInt.style&&(drawPatches(f,c.patches),drawTexture(f))}image(f,0,0)}0==featuresInt.style&&drawGlobalDiscoloration(),drawGlobalNoiseGrain()}function segmentPath($,e,n){let r=[],_=[];for(let t=0;t<$.length;t++)_.push($[t]),_.length>=n&&t<$.length-n&&R.random_bool(e)&&(_.push($[t+1]),r.push([..._]),_.length=0);return r.push([..._]),r}function getPolyFromStroke($,e,n){let r=[];if($.length>1){for(let _=0;_<$.length-1;_++){let t={x:$[_].x+R.random_num(-.02,.02)*n,y:$[_].y+R.random_num(-.02,.02)*n},o={x:$[_+1].x+R.random_num(-.02,.02)*n,y:$[_+1].y+R.random_num(-.02,.02)*n};0==_&&r.push(getPerpendicularPoint(t,o,0,e/map(t.y,0,1,R.random_num(1.75,2),R.random_num(.5,.75)))),r.push(getPerpendicularPoint(t,o,R.random_num(.4,.6),e/map(t.y,0,1,R.random_num(1.75,2),R.random_num(.5,.75)))),r.push(getPerpendicularPoint(t,o,1,e/map(t.y,0,1,R.random_num(1.75,2),R.random_num(.5,.75))))}for(let a=$.length-1;a>0;a--){let y={x:$[a].x+R.random_num(-.02,.02)*n,y:$[a].y+R.random_num(-.02,.02)*n},x={x:$[a-1].x+R.random_num(-.02,.02)*n,y:$[a-1].y+R.random_num(-.02,.02)*n};r.push(getPerpendicularPoint(y,x,0,e/map(y.y,0,1,R.random_num(1.75,2),R.random_num(.5,.75)))),r.push(getPerpendicularPoint(y,x,R.random_num(.4,.6),e/map(y.y,0,1,R.random_num(1.75,2),R.random_num(.5,.75)))),a==$.length-2&&r.push(getPerpendicularPoint(y,x,1,e/map(y.y,0,1,R.random_num(1.75,2),R.random_num(.5,.75))))}}return r.push(r[0]),r}function getPerpendicularPoint($,e,n,r){let _=atan2(e.y-$.y,e.x-$.x),t=getMidPoint($,e,n);return{x:t.x+r*Math.cos(_-HALF_PI),y:t.y+r*Math.sin(_-HALF_PI)}}function getMidPoint($,e,n){return{x:$.x*(1-n)+e.x*n,y:$.y*(1-n)+e.y*n}}function smoothPoly($,e,n,r){let _=[],t=$.length-1;n&&(t+=2);for(let o=0;o<t;o++){let a=$[o%$.length],y=$[(o+1)%$.length];o!=$.length-1&&(R.random_bool(r)?(_.push({x:.75*a.x+.25*y.x,y:.75*a.y+.25*y.y}),_.push({x:.25*a.x+.75*y.x,y:.25*a.y+.75*y.y})):_.push(a)),o==t-1&&_.push(y)}for(let x=1;x<e;x++)_=smoothPoly([..._],1);return _}function scalePoly($,e){let n=getPolyCentroid($),r=[];for(let _ of $){let t=_,o={x:n.x,y:n.y};r.push({x:t.x*(1+e)+-(o.x*e),y:t.y*(1+e)+-(o.y*e)})}return r}function getPolyCentroid($){let e=0,n=0;for(let r=0;r<$.length;r++){let _=$[r],t=$[(r+1)%$.length],o=_.x*t.y-t.x*_.y;e+=(_.x+t.x)*o,n+=(_.y+t.y)*o}let a=calculatePolygonArea($),y=1/(6*a),x=y*e,l=y*n;return{x:x,y:l}}function calculatePolygonArea($){let e=0;for(let n=0;n<$.length;n++){let r=$[n],_=$[(n+1)%$.length];e+=r.x*_.y-_.x*r.y}return Math.abs(e/=2)}function drawTexture($){let e=R.random_int(0,99999),n=width/10,r=height/100;$.rectMode(CENTER);for(let _=0;_<2;_++)for(let t=-50;t<150;t++)for(let o=-5;o<15;o++){$.push(),$.translate(n*(o+.5),r*(t+.5));let a,y;0==_?(a=.4,y=.01):1==_&&(a=.005,y=.2);let x=map(S.noise3D(e,t*a,o*y),0,1,150,190),l;x>160?($.blendMode(SOFT_LIGHT),l=8):($.blendMode(OVERLAY),l=10),$.fill(x,l),$.noStroke();let s=map(S.noise3D(e,.001*t,.005*o),0,1,-5*r,5*r),i=map(S.noise3D(e,.005*t,.001*o),0,1,-2*n,2*n),u=R.random_num(0,TAU);$.beginShape();for(let m=u;m<TAU+u;m+=TAU/R.random_int(3,10)){let d=i+n*R.random_num(2,4)*Math.cos(m),h=s+r*R.random_num(2,4)*Math.sin(m);$.vertex(d,h)}$.endShape(CLOSE),$.pop()}}function drawPatches($,e){for(let n=0;n<e.length;n++){let r=e[n],_=color(r.highlightCol);for(let t of(_.setAlpha(r.expandedPolyAlpha),$.fill(_),$.beginShape(),r.expandedPoly))$.vertex(t.x*width,t.y*height);for(let o of($.endShape(CLOSE),(_=color(r.col)).setAlpha(255),$.beginShape(),$.fill(_),$.noStroke(),r.poly))$.vertex(o.x*width,o.y*height);$.endShape(CLOSE)}}function drawGlobalDiscoloration(){drawingContext.save();let $=drawingContext.createLinearGradient(width/2,height*R.random_num(-.1,-.2),width/2,1*height),e=drawingContext.createLinearGradient(width/2,height*R.random_num(1.1,1.2),width/2,0*height),n=drawingContext.createLinearGradient(width*R.random_num(-.1,-.2),height/2,1*width,height/2),r=drawingContext.createLinearGradient(width*R.random_num(1.1,1.2),height/2,0*width,height/2);for(let _ of(drawingContext.globalCompositeOperation="color-burn",[$,e,n,r]))_.addColorStop(0,"rgba(0,0,0,0.25)"),_.addColorStop(.5,"rgba(255,255,255,0.05)"),drawingContext.fillStyle=_,drawingContext.fillRect(0,0,width,height);drawingContext.restore()}function drawGlobalNoiseGrain(){drawingContext.save(),drawingContext.globalCompositeOperation="multiply";for(let $=0;$<5e4;$++){push();let e=R.random_dec()*width,n=R.random_dec()*height,r=1==featuresInt.style?color(255):color(R.random_bool(.9)?R.random_num(50,80):featuresInt.bg);r.setAlpha(R.random_bool(.999)?map(S.noise2D(.0025*e,.0025*n),0,1,20,40):R.random_num(80,120)),fill(r),noStroke();let _=width*(R.random_bool(.999)?R.random_num(.001,.003):R.random_num(.004,.006)),t=R.random_num(0,TAU);beginShape();for(let o=t;o<TAU+t;o+=TAU/R.random_int(3,10)){let a=e+(_/2+width*R.random_num(-.001,.001))*Math.cos(o),y=n+(_/2+width*R.random_num(-.001,.001))*.6*Math.sin(o);curveVertex(a,y)}endShape(CLOSE),pop()}drawingContext.restore()}function getColorVariation($,e){let n=color($);if(!R.random_bool(.8))return n.toString("#rrggbb");{let r=R.random_num(e.hMin,e.hMax),_=R.random_num(e.sMin,e.sMax),t=R.random_num(e.bMin,e.bMax),o=hexToHSB($);return o[0]=Math.round((o[0]+r)%360),o[1]=Math.max(Math.min(o[1]+_,100),0),o[2]=Math.max(Math.min(o[2]+t,100),0),color(`hsb(${o[0]}, ${o[1]}%, ${o[2]}%)`).toString("#rrggbb")}}function hexToHSB($){$=$.replace("#","");let e=parseInt($.substring(0,2),16)/255,n=parseInt($.substring(2,4),16)/255,r=parseInt($.substring(4,6),16)/255,_=Math.max(e,n,r),t=Math.min(e,n,r),o;return(o=Math.round(60*(o=_===t?0:_===e?(n-r)/(_-t)%6:_===n?(r-e)/(_-t)+2:(e-n)/(_-t)+4)))<0&&(o+=360),[o,0===_?0:Math.round((_-t)/_*100),Math.round(100*_)]}function numberToRoman($){let e="";for(let n of[{value:1e3,numeral:"M"},{value:900,numeral:"CM"},{value:500,numeral:"D"},{value:400,numeral:"CD"},{value:100,numeral:"C"},{value:90,numeral:"XC"},{value:50,numeral:"L"},{value:40,numeral:"XL"},{value:10,numeral:"X"},{value:9,numeral:"IX"},{value:5,numeral:"V"},{value:4,numeral:"IV"},{value:1,numeral:"I"}])for(;$>=n.value;)e+=n.numeral,$-=n.value;return e}class Random{constructor(){this.useA=!1;let $=function($){let e=parseInt($.substring(0,8),16),n=parseInt($.substring(8,16),16),r=parseInt($.substring(16,24),16),_=parseInt($.substring(24,32),16);return function(){r|=0;let $=((e|=0)+(n|=0)|0)+(_|=0)|0;return _=_+1|0,e=n^n>>>9,n=r+(r<<3)|0,r=(r=r<<21|r>>>11)+$|0,($>>>0)/4294967296}};this.prngA=new $(tokenData.hash.substring(2,34)),this.prngB=new $(tokenData.hash.substring(34,66));for(let e=0;e<1e6;e+=2)this.prngA(),this.prngB()}random_dec(){return this.useA=!this.useA,this.useA?this.prngA():this.prngB()}random_num($,e){return $+(e-$)*this.random_dec()}random_int($,e){return Math.floor(this.random_num($,e+1))}random_bool($){return this.random_dec()<$}random_choice($){return $[this.random_int(0,$.length-1)]}weighted_index($){let e=0;for(let n=0;n<$.length;n++)e+=$[n];let r=e*this.random_dec();for(let _=0;_<$.length;_++){if(r<$[_])return _;r-=$[_]}return $.length-1}}!function(){"use strict";var $=.5*(Math.sqrt(3)-1),e=(3-Math.sqrt(3))/6,n=1/3,r=1/6,_=(Math.sqrt(5)-1)/4,t=(5-Math.sqrt(5))/20;function o($){var e;e="function"==typeof $?$:$?function $(){var e,n=0,r=0,_=0,t=1,o=(e=4022871197,function($){$=$.toString();for(var n=0;n<$.length;n++){var r=.02519603282416938*(e+=$.charCodeAt(n));e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=4294967296*r}return(e>>>0)*23283064365386963e-26});n=o(" "),r=o(" "),_=o(" ");for(var a=0;a<arguments.length;a++)n-=o(arguments[a]),n<0&&(n+=1),r-=o(arguments[a]),r<0&&(r+=1),_-=o(arguments[a]),_<0&&(_+=1);return o=null,function(){var $=2091639*n+23283064365386963e-26*t;return n=r,r=_,_=$-(t=0|$)}}($):Math.random,this.p=a(e),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(var n=0;n<512;n++)this.perm[n]=this.p[255&n],this.permMod12[n]=this.perm[n]%12}function a($){var e,n=new Uint8Array(256);for(e=0;e<256;e++)n[e]=e;for(e=0;e<255;e++){var r=e+~~($()*(256-e)),_=n[e];n[e]=n[r],n[r]=_}return n}o.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]),grad4:new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]),noise2D:function(n,r){var _,t,o=this.permMod12,a=this.perm,y=this.grad3,x=0,l=0,s=0,i=(n+r)*$,u=Math.floor(n+i),m=Math.floor(r+i),d=(u+m)*e,h=n-(u-d),c=r-(m-d);h>c?(_=1,t=0):(_=0,t=1);var f=h-_+e,g=c-t+e,p=h-1+2*e,b=c-1+2*e,v=255&u,P=255&m,I=.5-h*h-c*c;if(I>=0){var M=3*o[v+a[P]];I*=I,x=I*I*(y[M]*h+y[M+1]*c)}var w=.5-f*f-g*g;if(w>=0){var C=3*o[v+_+a[P+t]];w*=w,l=w*w*(y[C]*f+y[C+1]*g)}var k=.5-p*p-b*b;if(k>=0){var A=3*o[v+1+a[P+1]];k*=k,s=k*k*(y[A]*p+y[A+1]*b)}return 70*(x+l+s)},noise3D:function($,e,_){var t,o,a,y,x,l,s,i,u,m,d=this.permMod12,h=this.perm,c=this.grad3,f=($+e+_)*n,g=Math.floor($+f),p=Math.floor(e+f),b=Math.floor(_+f),v=(g+p+b)*r,P=$-(g-v),I=e-(p-v),M=_-(b-v);P>=I?I>=M?(x=1,l=0,s=0,i=1,u=1,m=0):P>=M?(x=1,l=0,s=0,i=1,u=0,m=1):(x=0,l=0,s=1,i=1,u=0,m=1):I<M?(x=0,l=0,s=1,i=0,u=1,m=1):P<M?(x=0,l=1,s=0,i=0,u=1,m=1):(x=0,l=1,s=0,i=1,u=1,m=0);var w=P-x+r,C=I-l+r,k=M-s+r,A=P-i+2*r,D=I-u+2*r,V=M-m+2*r,F=P-1+3*r,G=I-1+3*r,L=M-1+3*r,H=255&g,T=255&p,B=255&b,O=.6-P*P-I*I-M*M;if(O<0)t=0;else{var q=3*d[H+h[T+h[B]]];O*=O,t=O*O*(c[q]*P+c[q+1]*I+c[q+2]*M)}var X=.6-w*w-C*C-k*k;if(X<0)o=0;else{var N=3*d[H+x+h[T+l+h[B+s]]];X*=X,o=X*X*(c[N]*w+c[N+1]*C+c[N+2]*k)}var W=.6-A*A-D*D-V*V;if(W<0)a=0;else{var z=3*d[H+i+h[T+u+h[B+m]]];W*=W,a=W*W*(c[z]*A+c[z+1]*D+c[z+2]*V)}var E=.6-F*F-G*G-L*L;if(E<0)y=0;else{var j=3*d[H+1+h[T+1+h[B+1]]];E*=E,y=E*E*(c[j]*F+c[j+1]*G+c[j+2]*L)}return 32*(t+o+a+y)},noise4D:function($,e,n,r){var o,a,y,x,l,s,i,u,m,d,h,c,f,g,p,b,v,P=this.perm,I=this.grad4,M=($+e+n+r)*_,w=Math.floor($+M),C=Math.floor(e+M),k=Math.floor(n+M),A=Math.floor(r+M),D=(w+C+k+A)*t,V=$-(w-D),F=e-(C-D),G=n-(k-D),L=r-(A-D),H=0,T=0,B=0,O=0;V>F?H++:T++,V>G?H++:B++,V>L?H++:O++,F>G?T++:B++,F>L?T++:O++,G>L?B++:O++,s=H>=3?1:0,i=T>=3?1:0,u=B>=3?1:0,m=O>=3?1:0,d=H>=2?1:0,h=T>=2?1:0,c=B>=2?1:0,f=O>=2?1:0,g=H>=1?1:0,p=T>=1?1:0,b=B>=1?1:0;var q=V-s+t,X=F-i+t,N=G-u+t,W=L-m+t,z=V-d+2*t,E=F-h+2*t,j=G-c+2*t,J=L-f+2*t,K=V-g+3*t,Q=F-p+3*t,U=G-b+3*t,Y=L-(v=O>=1?1:0)+3*t,Z=V-1+4*t,$$=F-1+4*t,$e=G-1+4*t,$n=L-1+4*t,$r=255&w,$_=255&C,$t=255&k,$o=255&A,$a=.6-V*V-F*F-G*G-L*L;if($a<0)o=0;else{var $y=P[$r+P[$_+P[$t+P[$o]]]]%32*4;$a*=$a,o=$a*$a*(I[$y]*V+I[$y+1]*F+I[$y+2]*G+I[$y+3]*L)}var $x=.6-q*q-X*X-N*N-W*W;if($x<0)a=0;else{var $l=P[$r+s+P[$_+i+P[$t+u+P[$o+m]]]]%32*4;$x*=$x,a=$x*$x*(I[$l]*q+I[$l+1]*X+I[$l+2]*N+I[$l+3]*W)}var $s=.6-z*z-E*E-j*j-J*J;if($s<0)y=0;else{var $0=P[$r+d+P[$_+h+P[$t+c+P[$o+f]]]]%32*4;$s*=$s,y=$s*$s*(I[$0]*z+I[$0+1]*E+I[$0+2]*j+I[$0+3]*J)}var $i=.6-K*K-Q*Q-U*U-Y*Y;if($i<0)x=0;else{var $u=P[$r+g+P[$_+p+P[$t+b+P[$o+v]]]]%32*4;$i*=$i,x=$i*$i*(I[$u]*K+I[$u+1]*Q+I[$u+2]*U+I[$u+3]*Y)}var $3=.6-Z*Z-$$*$$-$e*$e-$n*$n;if($3<0)l=0;else{var $m=P[$r+1+P[$_+1+P[$t+1+P[$o+1]]]]%32*4;$3*=$3,l=$3*$3*(I[$m]*Z+I[$m+1]*$$+I[$m+2]*$e+I[$m+3]*$n)}return 27*(o+a+y+x+l)}},o._buildPermutationTable=a,window.SimplexNoise=o}();
↓ show full (18,764 bytes)