0xc7d7852c…e9a1sent to0x0a1bbd57…3676·#19,261,267·view on Etherscan
=0;t<this.height/n;t++){let s={};s.i=e,s.j=t,s.polys=[],this.grid[e].push(s),this.allCells.push(s)}}this.allPolys=[]}add(e,t=void 0){if(null==t?this.allPolys.push(e):this.allPolys.push({p1:e,p2:t}),e.length)return void e.map((e=>this.add(e)));if(e.shape&&!t){for(let t=0;t<e.shape.length-1+e.closed;t++){let s=e.shape[t],a=e.shape[(t+1)%e.shape.length];this.getLineCells(s,a).map(((e,t)=>{e.polys.push({p1:s,p2:a})}))}return}let s=e;this.getLineCells(s,t).map(((e,a)=>{e.polys.push({p1:s,p2:t})}))}rayIntersect(e,t){(t=t.copy()).setMag(W+H),t=p5.Vector.add(e,t);let[s,a,n]=this.getLineCells(e,t,1),r=2,o=!1,i=[];for(let a of s){for(let s of a.polys){let n=this.rayToLineSegmentIntersection(e,t,s.p1,s.p2);n&&n.point.x>=a.i*this.gap&&n.point.x<=(a.i+1)*this.gap&&n.point.y>=a.j*this.gap&&n.point.y<=(a.j+1)*this.gap&&i.push(n)}if(i.length&&(o=!0),o&&--r<=0)break}i.sort(((e,t)=>e.t-t.t));let l=i[0];if(null!=l)return(e.x-l.point.x)**2+(e.y-l.point.y)**2>10*S&&i[0]}getLineCells(e,t,s=this.gap,a=this.gap,n=this.width,r=this.height){let o=0;1==s&&(o=1,s=this.gap);let i=e.x/s-.5,l=e.y/a-.5,p=t.x/s-.5,h=t.y/a-.5;const u=e=>Math.floor(e+.5);let g=[],d=Math.abs(h-l)>Math.abs(p-i);d&&([i,l]=[l,i],[p,h]=[h,p]),i>p&&([i,p]=[p,i],[l,h]=[h,l]);const m=p-i,c=0===m?1:(h-l)/m,f=(e,t)=>{d?g.push({x:t,y:e}):g.push({x:e,y:t})},y=u(i),x=l+c*(y-i),P=y,b=Math.floor(x);f(P,b),f(P,b+1);let v=x+c;const S=u(p),k=Math.floor(h+c*(S-p));for(let e=P+1;e<=S-1;e++)f(e,Math.floor(v)),f(e,Math.floor(v)+1),v+=c;f(S,k),f(S,k+1),e.x>=t.x&&g.reverse(),(d&&e.x>t.x&&e.y<t.y||d&&e.x<t.x&&e.y>t.y)&&g.reverse();let w=[];for(let e=0;e<g.length;e++){let t=g[e];t.x=Math.floor(t.x),t.y=Math.floor(t.y),t.x>=0&&t.y>=0&&t.x<this.grid.length&&t.y<this.grid[0].length&&w.push(this.grid[t.x][t.y])}return o?[w,e.x>t.x,d]:w}rayToLineSegmentIntersection(e,t,s,a){let n=t.x-e.x,r=t.y-e.y,o=a.x-s.x,i=a.y-s.y,l=i*n-o*r,p=o*(e.y-s.y)-i*(e.x-s.x),h=n*(e.y-s.y)-r*(e.x-s.x);if(0==l)return void 0;let u=p/l,g=h/l,d=1e-8;return u>=d&&g>=d&&g<=1-d?{point:createVector(e.x+u*n,e.y+u*r),t:u,dir:p5.Vector.sub(a,s)}:void 0}}function setupRandom(){R=new Random,randomSeed(R.random_int(0,1e16)),noiseSeed(R.random_int(0,1e16)),rnd=(e,t)=>e instanceof Array?R.random_choice(e):void 0===e?R.random_dec():void 0===t?R.random_num(0,e):R.random_num(e,t),rtri=(e,t,s)=>{let a=R.random_dec();return a<.5?map(a,0,.5,e,t):map(a,.5,1,t,s)},weightedPick=(e,t)=>{let s;for(s=0;s<t.length;s++)t[s]+=t[s-1]||0;var a=rnd()*t[t.length-1];for(s=0;s<t.length&&!(t[s]>=a);s++);return e[s]}}class Random{constructor(){this.useA=!1;let e=function(e){let t=parseInt(e.substr(0,8),16),s=parseInt(e.substr(8,8),16),a=parseInt(e.substr(16,8),16),n=parseInt(e.substr(24,8),16);return function(){t|=0,s|=0,a|=0,n|=0;let e=(t+s|0)+n|0;return n=n+1|0,t=s^s>>>9,s=a+(a<<3)|0,a=a<<21|a>>>11,a=a+e|0,(e>>>0)/4294967296}};if(""==tokenData.hash){let e=()=>{let e="0123456789abcdef",t="0x";for(let s=0;s<64;s++)t+=e[Math.floor(16*Math.random())];return t};tokenData.hash=e()}this.prngA=new e(tokenData.hash.substr(2,32)),this.prngB=new e(tokenData.hash.substr(34,32));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,t){return e+(t-e)*this.random_dec()}random_int(e,t){return Math.floor(this.random_num(e,t+1))}random_bool(e){return this.random_dec()<e}random_choice(e){return e[this.random_int(0,e.length-1)]}}function setupUseful(){setupRandom(),W=width,H=height,vec=createVector,rndvec=(e=0,t=W,s=0,a=H)=>vec(rnd(e,t),rnd(s,a))}function saveNamed(){save(`lightbreak-${parseInt(tokenData.tokenId)%1e6}.png`)}function distSq(e,t){return p5.Vector.sub(e,t).magSq()}p5.disableFriendlyErrors=!0;class Poly{constructor(e,t=0,s=0,a=1,n=0,r=!0,o=void 0,i=void 0){this.shape=e.map((e=>vec(t+e.x*a,s+e.y*a))),this.closed=r,this.c=o,this.sc=i}rayIntersect(e,t,s=1){let a=this.shape[this.shape.length-1],n=p5.Vector.add(a,t),r=[];if(e.map((e=>{for(let t=0;t<e.shape.length-1;t++){let s=e.shape[t],o=e.shape[(t+1)%e.shape.length],i=this.rayToLineSegmentIntersection(a,n,s,o);i&&r.push(i)}})),r.sort(((e,t)=>e.t-t.t)),r.length&&r[0].t>s)return r[0]}addPoint(e,t=!0){this.shape.push(e),t&&qt.add(this.shape[this.shape.length-2],this.shape[this.shape.length-1])}static rect(e,t,s,a){let n=1e-6,r=[vec(e-(s/=2),t-(a/=2)),vec(e+s,t-a),vec(e+s+n,t+a),vec(e-s-n,t+a)];return new Poly(r)}setColor(e=void 0,t=void 0){return this.c=e,this.sc=t,this}addToQT(){this.qt=new QT(new BB((this.bbl+this.bbr)/2,(this.bbb+this.bbt)/2,(this.bbr-this.bbl)/2,(this.bbb-this.bbt)/2),4),this.qt.show();for(let e=0;e<this.shape.length;e++){let t=(e+1+this.shape.length)%this.shape.length,s=this.shape[e],a=this.shape[t];this.qt.insert({x1:s.x,y1:s.y,x2:a.x,y2:a.y})}}reseed(e=5,t=!0){let s=[];for(let a=0;a<this.shape.length&&(t||a!=this.shape.length-1);a++){let t=(a+1)%this.shape.length,n=this.shape[a],r=this.shape[t],o=e/p5.Vector.dist(n,r);if(s.push(n),o<1)if(o>.5)s.push(p5.Vector.lerp(n,r,.5));else for(let e=o;e<1;e+=o)s.push(p5.Vector.lerp(n,r,e))}return this.shape=s,this}draw(e=!0,t=!1,s=!1){noFill(),this.sc&&stroke(this.sc),e&&(beginShape(),this.shape.map(((e,t)=>{s?curveVertex(e.x,e.y):vertex(e.x,e.y)})),this.closed?endShape(CLOSE):endShape())}}