PageSourceSearch

https://puzzlepave.com/_next/static/chunks/30ab628d.fa822716dae917ad.js

js puzzlepave.com collected 2026-10-04 10:09:10 UTC 109,301 bytes, 44 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[151],{54617:(e,t,s)=>{let i;s.d(t,{G:()=>Q,M:()=>es,R:()=>Z,T:()=>et,a:()=>R,b:()=>G,c:()=>Y,d:()=>z,e:()=>eh,f:()=>eg,g:()=>eo,h:()=>el,i:()=>B,j:()=>eu,k:()=>e_,l:()=>W,m:()=>K,n:()=>ee,o:()=>ea,p:()=>$,q:()=>er,r:()=>H,s:()=>en,t:()=>ei,u:()=>ed});var r=s(58905),a=s(45950),h=s(20498),n=s(28499),o=s(3694),l=s(58093),u=s(47689),d=s(51032),c=s(170),p=s(31586),f=s(64665),m=s(95115),g=s(45953),_=s(69689),y=s(82741),x=s(29777),w=s(79690),M=s(97679);s(81273);var C=s(39247),v=s(54964),b=s(43327),S=s(88124),T=s(13040),F=s(56247),V=s(70878),L=s(43140),E=s(65411),D=s(83301),A=s(29998),I=s(75386),P=s(75671),k=s(49570),U=s(96898);function B(e,t){t.createImage=function(t,s){return new e.Image(t,s)},t.saveCanvas=function(...e){let s,i,r,a,n;if(e[0]instanceof HTMLCanvasElement)s=e[0],e.shift();else if(e[0]instanceof h.H)s=e[0].elt,e.shift();else if(e[0]instanceof em){let t=e[0];(a=this.createGraphics(t.width,t.height)).pixelDensity(t.pixelDensity()),t.loadPixels(),a.loadPixels(),a.pixels.set(t.pixels),a.updatePixels(),s=a._renderer.canvas,e.shift()}else s=this._curElement&&this._curElement.elt;switch(e.length>=1&&(i=e[0]),e.length>=2&&(r=e[1]),r=r||t._checkFileExtension(i,r)[1]||"png"){default:n="image/png";break;case"webp":n="image/webp";break;case"jpeg":case"jpg":n="image/jpeg"}s.toBlob(e=>{t.downloadFile(e,i,r),a&&a.remove()},n)},t.encodeAndDownloadGif=function(e,s){let i=e.gifProperties,r=i.loopLimit;1===r?r=null:null===r&&(r=0);let a=new Uint8Array(e.width*e.height*i.numFrames),h=[],n={};for(let t=0;t<i.numFrames;t++){let s=new Set,r=i.frames[t].image.data,a=r.length,o=new Uint32Array(e.width*e.height);for(let e=0,t=0;e<a;e+=4,t++){let i=r[e+0],a=i<<16|r[e+1]<<8|(0|r[e+2]);s.add(a),o[t]=a}let l=[...s].sort().toString();void 0===n[l]?n[l]={freq:1,frames:[t]}:(n[l].freq+=1,n[l].frames.push(t)),h.push(o)}let o=[],l=Object.keys(n).sort(function(e,t){return n[t].freq-n[e].freq}),u=l[0].split(",").map(e=>parseInt(e));o=o.concat(n[u].frames);let d=new Set(u);for(let e=1;e<l.length;e++){let t=l[e].split(",").map(e=>parseInt(e)).filter(e=>!d.has(e));if(u.length+t.length<=256){for(let e=0;e<t.length;e++)u.push(t[e]),d.add(t[e]);o=o.concat(n[l[e]].frames)}}o=new Set(o);let c={};for(let e=0;e<u.length;e++)c[u[e]]||(c[u[e]]=e);let p=1;for(;p<u.length;)p<<=1;u.length=p;let m={loop:r,palette:new Uint32Array(u)},g=new f.e(a,e.width,e.height,m),_={};for(let t=0;t<i.numFrames;t++){let s=!o.has(t),r=s?[]:u,a=new Uint8Array(e.width*e.height),n={},l=new Set;h[t].forEach((e,i)=>{s?(void 0===n[e]&&(n[e]=r.length,r.push(e)),a[i]=n[e]):a[i]=c[e],t>0&&h[t-1][i]!==e&&l.add(e)});let d={},p=r.filter(e=>!l.has(e));if(p.length>0){let e=p[0],i=s?n[e]:c[e];if(t>0){for(let e=0;e<h[t].length;e++)h[t-1][e]===h[t][e]&&(a[e]=i);d.transparent=i,_.frameOpts.disposal=1}}if(d.delay=i.frames[t].delay/10,s){let e=1;for(;e<r.length;)e<<=1;r.length=e,d.palette=new Uint32Array(r)}t>0&&g.addFrame(0,0,e.width,e.height,_.pixelPaletteIndex,_.frameOpts),_={pixelPaletteIndex:a,frameOpts:d}}_.frameOpts.disposal=1,g.addFrame(0,0,e.width,e.height,_.pixelPaletteIndex,_.frameOpts);let y=new Blob([a.slice(0,g.end())],{type:"image/gif"});t.downloadFile(y,s,"gif")},t.saveFrames=function(e,s,i,r,a){let h=i||3;h=1e3*Math.max(Math.min(h,15),0);let n=r||15;n=Math.max(Math.min(n,22),0);let o=0,l=t._makeFrame,u=this._curElement.elt,d=[],c=setInterval(()=>{d.push(l(e+o,s,u)),o++},1e3/n);setTimeout(()=>{if(clearInterval(c),a)a(d);else for(let e of d)t.downloadFile(e.imageData,e.filename,e.ext);d=[]},h+.01)},t._makeFrame=function(e,t,s){let i,r;if(i=this?this._curElement.elt:s,t)switch(t.toLowerCase()){case"png":default:r="image/png";break;case"jpeg":case"jpg":r="image/jpeg"}else t="png",r="image/png";let a=i.toDataURL(r);a=a.replace(r,"image/octet-stream");let h={};return h.imageData=a,h.filename=e,h.ext=t,h}}"undefined"!=typeof p5&&B(p5,p5.prototype);class N extends Error{status;response;ok}async function R(e,t){try{let s=await fetch(e);if(s.ok){let e;switch(t){case"json":e=await s.json();break;case"text":e=await s.text();break;case"arrayBuffer":e=await s.arrayBuffer();break;case"blob":e=await s.blob();break;
1case"bytes":if(s.bytes)e=await s.bytes();else{let t=await s.arrayBuffer();e=new Uint8Array(t)}break;default:throw Error("Unsupported response type")}return{data:e,headers:s.headers}}{let e=new N(s.statusText);throw e.status=s.status,e.response=s,e.ok=!1,e}}catch(e){throw e instanceof TypeError?console.log("You may have encountered a CORS error"):e instanceof N?console.log("You have encountered a HTTP error"):e instanceof SyntaxError&&console.log("There is an error parsing the response to requested data structure"),e}}function z(e,t){function s(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}t.loadJSON=async function(t,s,i){try{let{data:e}=await R(t,"json"),i=()=>s?s(e):e;return this._internal?this._internal(i):i()}catch(s){if(e._friendlyFileLoadError(5,t),i)return i(s);throw s}},t.loadStrings=async function(t,s,i){try{let{data:e}=await R(t,"text"),i=()=>(e=e.split(/\r?\n/),s)?s(e):e;return this._internal?this._internal(i):i()}catch(s){if(e._friendlyFileLoadError(3,t),i)return i(s);throw s}},t.loadTable=async function(t,s,i,r,a){"function"==typeof arguments[arguments.length-1]&&("function"==typeof arguments[arguments.length-2]?(r=arguments[arguments.length-2],a=arguments[arguments.length-1]):r=arguments[arguments.length-1]),"string"!=typeof s&&(s=","),"function"==typeof i&&(i=!1);try{let{data:a}=await R(t,"text"),h=()=>{let t=new e.Table;return(a=(0,g.q)(a,{separator:s}),i?t.columns=a.shift():t.columns=Array(a[0].length).fill(null),a.forEach(s=>{let i=new e.TableRow(s);t.addRow(i)}),r)?r(t):t};return this._internal?this._internal(h):h()}catch(s){if(e._friendlyFileLoadError(2,t),a)return a(s);throw s}},t.loadXML=async function(t,s,i){try{let i=new DOMParser,{data:r}=await R(t,"text"),a=()=>{let t=i.parseFromString(r,"application/xml");return(r=new e.XML(t),s)?s(r):r};return this._internal?this._internal(a):a()}catch(s){if(e._friendlyFileLoadError(1,t),i)return i(s);throw s}},t.loadBytes=async function(t,s,i){try{let{data:e}=await R(t,"arrayBuffer"),i=()=>(e=new Uint8Array(e),s)?s(e):e;return this._internal?this._internal(i):i()}catch(s){if(e._friendlyFileLoadError(6,t),i)return i(s);throw s}},t.loadBlob=async function(e,t,s){try{let{data:s}=await R(e,"blob"),i=()=>t?t(s):s;return this._internal?this._internal(i):i()}catch(e){if(s)return s(e);throw e}},t.httpGet=async function(e,t="text",s,i){return"function"==typeof t&&(i=s,s=t,t="text"),this.httpDo(e,"GET",t,s,i)},t.httpPost=async function(t,s,i="text",r,a){"function"==typeof s?(r=s,a=i,s=void 0,i="text"):"function"==typeof i&&(a=r,r=i,i="text");let h=s,n="text/plain";s instanceof e.XML?(h=s.serialize(),n="application/xml"):s instanceof e.Image?(h=await s.toBlob(),n="image/png"):"object"==typeof s&&(h=JSON.stringify(s),n="application/json");let o={method:"POST",body:h,headers:{"Content-Type":n}};h&&(o.body=h);let l=new Request(t,o);return this.httpDo(l,"POST",i,r,a)},t.httpDo=async function(e,t,s,i,r){if("function"==typeof s&&(r=i,i=s,s=void 0),!s)switch("string"==typeof e?e.split(".").pop():e.url.split(".").pop()){case"json":s="json";break;case"jpg":case"jpeg":case"png":case"webp":case"gif":s="blob";break;default:s="text"}let a=new Request(e,{method:t});try{let{data:e}=await R(a,s);if(i)return i(e);return e}catch(e){if(r)return r(e);throw e}},t._pWriters=[],t.createWriter=function(s,i){let r;for(let a in t._pWriters)if(t._pWriters[a].name===s)return r=new e.PrintWriter(s+this.millis(),i),t._pWriters.push(r),r;return r=new e.PrintWriter(s,i),t._pWriters.push(r),r},e.PrintWriter=function(e,s){let i=this;this.name=e,this.content="",this.write=function(e){this.content+=e},this.print=function(e){this.content+=`${e}
2`},this.clear=function(){this.content=""},this.close=function(){let r=[];for(let i in r.push(this.content),t.writeFile(r,e,s),t._pWriters)t._pWriters[i].name===this.name&&t._pWriters.splice(i,1);i.clear(),i={}}},t.save=function(s,i,r){let a=arguments,h=this._curElement?this._curElement.elt:this.elt;if(0===a.length)return void t.saveCanvas(h);if(a[0]instanceof n.R||a[0]instanceof Q)return void t.saveCanvas(a[0].canvas,a[1],a[2]);if(1===a.length&&"string"==typeof a[0])t.saveCanvas(h,a[0]);
2else switch((0,_.N)(a[1],a[2])[1]){case"json":t.saveJSON(a[0],a[1],a[2]);return;case"txt":t.saveStrings(a[0],a[1],a[2]);return;default:a[0]instanceof Array?t.saveStrings(a[0],a[1],a[2]):a[0]instanceof e.Table?t.saveTable(a[0],a[1],a[2]):a[0]instanceof e.Image?t.saveCanvas(a[0].canvas,a[1]):a[0]instanceof e.SoundFile&&t.saveSound(a[0],a[1],a[2],a[3])}},t.saveJSON=function(e,t,s){let i;i=s?JSON.stringify(e):JSON.stringify(e,void 0,2),this.saveStrings(i.split("\n"),t,"json")},t.saveStrings=function(t,s,i,r){let a=new e.PrintWriter(s,i||"txt");for(let e of t)r?a.write(e+"\r\n"):a.write(e+"\n");a.close(),a.clear()},t.saveTable=function(e,t,i){let r;void 0===i?(r=t.substring(t.lastIndexOf(".")+1,t.length))===t&&(r="csv"):r=i;let a=this.createWriter(t,r),h=e.columns,n=",";if("tsv"===r&&(n="	"),"html"!==r){let t=e.toString(n);a.write(t)}else{a.print("<html>"),a.print("<head>");let t='  <meta http-equiv="content-type" content';if(t+='="text/html;charset=utf-8" />',a.print(t),a.print("</head>"),a.print("<body>"),a.print("  <table>"),"0"!==h[0]){a.print("    <tr>");for(let e=0;e<h.length;e++){let t=s(h[e]);a.print(`      <td>${t}`),a.print("      </td>")}a.print("    </tr>")}for(let t=0;t<e.rows.length;t++){a.print("    <tr>");for(let i=0;i<e.columns.length;i++){let r=s(e.rows[t].getString(i));a.print(`      <td>${r}`),a.print("      </td>")}a.print("    </tr>")}a.print("  </table>"),a.print("</body>"),a.print("</html>")}a.close(),a.clear()},t.writeFile=function(e,s,i){let r="application/octet-stream";t._isSafari()&&(r="text/plain");let a=new Blob(e,{type:r});t.downloadFile(a,s,i)},t.downloadFile=_.P,t._checkFileExtension=_.N,t._isSafari=function(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}}function G(e,t){async function s(t,s){let i=new f.u(t);s.width=s.canvas.width=i.width,s.height=s.canvas.height=i.height;let r=[],a=i.numFrames(),h=new Uint8ClampedArray(s.width*s.height*4),n=(t,i)=>{try{i.decodeAndBlitFrameRGBA(t,h)}catch(t){throw e._friendlyFileLoadError(8,s.src),t}};for(let e=0;e<a;e++){let t=i.frameInfo(e),a=s.drawingContext.getImageData(0,0,s.width,s.height);h=a.data.slice(),n(e,i);let o=new ImageData(h,s.width,s.height);s.drawingContext.putImageData(o,0,0);let l=t.delay;0===l&&(l=10),r.push({image:s.drawingContext.getImageData(0,0,s.width,s.height),delay:10*l}),2===t.disposal?s.drawingContext.clearRect(t.x,t.y,t.width,t.height):3===t.disposal&&s.drawingContext.putImageData(a,0,0,t.x,t.y,t.width,t.height)}let o=i.loopCount();return null===o?o=1:0===o&&(o=null),s.drawingContext.putImageData(r[0].image,0,0),r.length>1&&(s.gifProperties={displayIndex:0,loopLimit:o,loopCount:0,frames:r,numFrames:a,playing:!0,timeDisplayed:0,lastChangeTime:0}),s}function i(e,t){return e>0&&e<t?e:t}t.loadImage=async function(t,i,r){try{let r=new e.Image(1,1,this),a=new Request(t,{method:"GET",mode:"cors"}),{data:h,headers:n}=await R(a,"bytes"),o=n.get("content-type");if(null===o&&console.warn("The image you loaded does not have a Content-Type header. If you are using the online editor consider reuploading the asset."),o&&o.includes("image/gif"))await s(h,r);else{let e=new Blob([h]),t=await createImageBitmap(e);r.width=r.canvas.width=t.width,r.height=r.canvas.height=t.height,r.drawingContext.drawImage(t,0,0)}let l=()=>(r.modified=!0,i)?i(r):r;return this._internal?this._internal(l):l()}catch(s){if(e._friendlyFileLoadError(0,t),"function"==typeof r)return r(s);throw s}},t.saveGif=async function(s,i,r={delay:0,units:"seconds",silent:!1,notificationDuration:0,notificationID:"progressBar",reset:!0}){let a,h,n,o,l;if("string"!=typeof s)throw TypeError("fileName parameter must be a string");if("number"!=typeof i)throw TypeError("Duration parameter must be a number");let u=r&&r.delay||0,d=r&&r.units||"seconds",c=r&&r.silent||!1,p=r&&r.notificationDuration||0,f=r&&r.notificationID||"progressBar",m=!r||void 0===r.reset||r.reset;if("number"!=typeof u)throw TypeError("Delay parameter must be a number");if("seconds"!==d&&"frames"!==d)throw TypeError('Units parameter must be either "frames" or "seconds"');if("boolean"!=typeof c)throw TypeError("Silent parameter must be a boolean");if("number"!=typeof p)throw TypeError("Notification duration parameter must be a number");if("string"!=typeof f)throw TypeError("Notification ID parameter must be a string");this._recording=!0;let g=this._targetFrameRate;(g===1/0||void 0===g||0===g)&&(g=60);let _=1/g*1e3;_=_<20?20:_;let x="seconds"===d?i*g:i,w="seconds"===d?u*g:u;m?(a=w,this.frameCount=a,h=x+w):h=(a=this.frameCount+w)+x;let M=this._renderer._pixelDensity;this.pixelDensity(1);let C=[];for(null!==document.getElementById(f)&&document.getElementById(f).remove(),c||((n=this.createP("")).id(f),n.style("font-size","16px"),n.style("font-family","Montserrat"),n.style("background-color","#ffffffa0"),n.style("padding","8px"),n.style("border-radius","10px"),n.position(0,0)),this._renderer instanceof e.RendererGL&&
2(o=new Uint8Array((l=this.drawingContext).drawingBufferWidth*l.drawingBufferHeight*4)),this.noLoop(),await new Promise(requestAnimationFrame);a<h;){let t;this.redraw(),await new Promise(requestAnimationFrame),this._renderer instanceof e.RendererGL?(o=new Uint8Array(l.drawingBufferWidth*l.drawingBufferHeight*4),l.readPixels(0,0,l.drawingBufferWidth,l.drawingBufferHeight,l.RGBA,l.UNSIGNED_BYTE,o),t=function(e,t,s){let i=parseInt(s/2),r=4*t,a=new Uint8Array(4*t);for(let t=0;t<i;++t){let i=t*r,h=(s-t-1)*r;a.set(e.subarray(i,i+r)),e.copyWithin(i,h,h+r),e.set(a,h)}return e}(o,this.width,this.height)):t=this.drawingContext.getImageData(0,0,this.width,this.height).data,C.push(t),a++,c||n.html("Saved frame <b>"+C.length.toString()+"</b> out of "+x.toString()),await new Promise(e=>setTimeout(e,0))}c||n.html("Frames processed, generating color palette..."),this.loop(),this.pixelDensity(M);let v=(0,y.GIFEncoder)(),b=function(e){let t=new Uint8Array(e.length*e[0].length);for(let s=0;s<e.length;s++)t.set(e[s],s*e[0].length);let s=(0,y.quantize)(t,256,{format:"rgba4444",oneBitAlpha:!0});return 256===s.length?s[s.length-1]=[255*Math.random(),255*Math.random(),255*Math.random(),0]:s.push([255*Math.random(),255*Math.random(),255*Math.random(),0]),s}(C),S={},T=e=>{let t=e.length/4,s=new Uint8Array(t);for(let i=0;i<t;i++){let t=e[4*i]<<24|e[4*i+1]<<16|e[4*i+2]<<8|e[4*i+3];void 0===S[t]&&(S[t]=(0,y.nearestColorIndex)(b,e.slice(4*i,(i+1)*4))),s[i]=S[t]}return s},F=b.length-1,V=[];for(let e=0;e<C.length;e++){let t=T(C[e]),s=t.slice();if(0===e)v.writeFrame(t,this.width,this.height,{palette:b,delay:_,dispose:1});else{for(let e=0;e<t.length;e++)t[e]===V[e]&&(t[e]=F);v.writeFrame(t,this.width,this.height,{delay:_,transparent:!0,transparentIndex:F,dispose:1})}V=s,c||n.html("Rendered frame <b>"+e.toString()+"</b> out of "+x.toString()),await new Promise(e=>setTimeout(e,0))}v.finish();let L=new Blob([v.bytesView()],{type:"image/gif"});C=[],this._recording=!1,this.loop(),!c&&(n.html("Done. Downloading your gif!\uD83C\uDF38"),p>0&&setTimeout(()=>n.remove(),1e3*p)),t.downloadFile(L,s,"gif")},t.image=function(e,t,s,a,h,n,o,l,u,d,c,p){let f=e.width,g=e.height;p=p||r.v,c=c||r.v,e.elt&&(f=void 0!==f?f:e.elt.width,g=void 0!==g?g:e.elt.height),e.elt&&e.elt.videoWidth&&!e.canvas&&(f=void 0!==f?f:e.elt.videoWidth,g=void 0!==g?g:e.elt.videoHeight);let _=a||f,y=h||g,x=n||0,w=o||0,M=void 0!==l?l:f,C=void 0!==u?u:g;M=i(M,f),C=i(C,g);let v=1;e.elt&&!e.canvas&&e.elt.style.width&&(v=(e.elt.videoWidth&&!a?e.elt.videoWidth:e.elt.width)/parseInt(e.elt.style.width,10)),x*=v,w*=v,C*=v,M*=v;let b=m.A.modeAdjust(t,s,_,y,this._renderer.states.imageMode);b=function(e,t,s,i,a,h,n,o,l,u,d){if(e===r.aB){let{x:e,y:i,w:a,h:c}=function(e,t,s,i,a,h,n,o){let l=Math.max(s/n,i/o),[u,d]=[s/l,i/l],c=a,p=h;return e===r.v?c+=(n-u)/2:e===r.a9&&(c+=n-u),t===r.v?p+=(o-d)/2:t===r.aw&&(p+=o-d),{x:c,y:p,w:u,h:d}}(t,s,h,n,o,l,u,d);o=e,l=i,u=a,d=c}if(e===r.aC){let{x:e,y:o,w:l,h:c}=function(e,t,s,i,a,h,n,o){let l=Math.max(n/a,o/h),[u,d]=[n/l,o/l],c=s,p=i;return e===r.v?c+=(a-u)/2:e===r.a9&&(c+=a-u),t===r.v?p+=(h-d)/2:t===r.aw&&(p+=h-d),{x:c,y:p,w:u,h:d}}(t,s,i,a,h,n,u,d);i=e,a=o,h=l,n=c}return{sx:o,sy:l,sw:u,sh:d,dx:i,dy:a,dw:h,dh:n}}(d,c,p,b.x,b.y,b.w,b.h,x,w,M,C),this._renderer.image(e,b.sx,b.sy,b.sw,b.sh,b.dx,b.dy,b.dw,b.dh)},t.tint=function(...e){let t=this.color(...e);this._renderer.states.setValue("tint",t._getRGBA([255,255,255,255]))},t.noTint=function(){this._renderer.states.setValue("tint",null)},t.imageMode=function(e){(e===r.p||e===r.t||e===r.v)&&this._renderer.states.setValue("imageMode",e)}}"undefined"!=typeof p5&&z(p5,p5.prototype),"undefined"!=typeof p5&&G(p5,p5.prototype);class O{constructor(e){this._renderer=e,this.cameraType="default",this.useLinePerspective=!0,this.cameraMatrix=new b.uq(4),this.projMatrix=new b.uq(4),this.yScale=1}perspective(e,t,s,i){let r,a,h=this._renderer.zClipRange();this.cameraType=arguments.length>0?"custom":"default",void 0===e?(e=this.defaultCameraFOV,this.cameraFOV=e):this.cameraFOV=this._renderer._pInst._toRadians(e),void 0===t&&(t=this.defaultAspectRatio),void 0===s&&(s=this.defaultCameraNear),void 0===i&&(i=this.defaultCameraFar),s<=1e-4&&(s=.01,console.log("Avoid perspective near plane values close to or below 0. Setting value to 0.01.")),i<s&&console.log("Perspective far plane value is less than near plane value. Nothing will be shown."),this.aspectRatio=t,this.cameraNear=s,this.cameraFar=i,this.projMatrix=new b.uq(4);let n=1/Math.tan(this.cameraFOV/2),o=1/(this.cameraNear-this.cameraFar);
20===h[0]?(r=i/(s-i),a=i*s/(s-i)):(r=(i+s)*o,a=2*i*s*o),this.projMatrix.set(n/t,0,0,0,0,-n*this.yScale,0,0,0,0,r,-1,0,0,a,0),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.set(this.projMatrix))}ortho(e,t,s,i,r,a){let h=this.fbo||this._renderer;void 0===e&&(e=-h.width/2),void 0===t&&(t=h.width/2),void 0===s&&(s=-h.height/2),void 0===i&&(i=h.height/2),void 0===r&&(r=0),void 0===a&&(a=Math.max(h.width,h.height)+800),this.cameraNear=r,this.cameraFar=a;let n=t-e,o=i-s,l=a-r,u=2/o*this.yScale,d=-(t+e)/n,c=-(i+s)/o,p=-(a+r)/l;this.projMatrix=new b.uq(4),this.projMatrix.set(2/n,0,0,0,0,-u,0,0,0,0,-2/l,0,d,c,p,1),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.set(this.projMatrix)),this.cameraType="custom"}frustum(e,t,s,i,r,a){void 0===e&&(e=-(.05*this._renderer.width)),void 0===t&&(t=.05*this._renderer.width),void 0===s&&(s=.05*this._renderer.height),void 0===i&&(i=-(.05*this._renderer.height)),void 0===r&&(r=this.defaultCameraNear),void 0===a&&(a=this.defaultCameraFar),this.cameraNear=r,this.cameraFar=a;let h=t-e,n=i-s,o=a-r,l=2*r/h,u=2*r/n*this.yScale,d=-(2*a*r)/o,c=(t+e)/h,p=(i+s)/n,f=-(a+r)/o;this.projMatrix=new b.uq(4),this.projMatrix.set(l,0,0,0,0,-u,0,0,c,p,f,-1,0,0,d,0),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.set(this.projMatrix)),this.cameraType="custom"}_rotateView(e,t,s,i){let r=this.centerX,a=this.centerY,h=this.centerZ;r-=this.eyeX,a-=this.eyeY,h-=this.eyeZ;let n=new b.uq(4);n.rotate4x4(this._renderer._pInst._toRadians(e),t,s,i);let o=[r*n.mat4[0]+a*n.mat4[4]+h*n.mat4[8],r*n.mat4[1]+a*n.mat4[5]+h*n.mat4[9],r*n.mat4[2]+a*n.mat4[6]+h*n.mat4[10]];o[0]+=this.eyeX,o[1]+=this.eyeY,o[2]+=this.eyeZ,this.camera(this.eyeX,this.eyeY,this.eyeZ,o[0],o[1],o[2],this.upX,this.upY,this.upZ)}roll(e){let t=this._getLocalAxes(),s=v.k.fromAxisAngle(this._renderer._pInst._toRadians(e),t.z[0],t.z[1],t.z[2]).rotateVector(new C.M(this.upX,this.upY,this.upZ));this.camera(this.eyeX,this.eyeY,this.eyeZ,this.centerX,this.centerY,this.centerZ,s.x,s.y,s.z)}pan(e){let t=this._getLocalAxes();this._rotateView(e,t.y[0],t.y[1],t.y[2])}tilt(e){let t=this._getLocalAxes();this._rotateView(e,t.x[0],t.x[1],t.x[2])}lookAt(e,t,s){this.camera(this.eyeX,this.eyeY,this.eyeZ,e,t,s,this.upX,this.upY,this.upZ)}camera(e,t,s,i,r,a,h,n,o){void 0===e&&(e=this.defaultEyeX,t=this.defaultEyeY,s=this.defaultEyeZ,i=e,r=t,a=0,h=0,n=1,o=0),this.eyeX=e,this.eyeY=t,this.eyeZ=s,void 0!==i&&(this.centerX=i,this.centerY=r,this.centerZ=a),void 0!==h&&(this.upX=h,this.upY=n,this.upZ=o);let l=this._getLocalAxes();this.cameraMatrix.set(l.x[0],l.y[0],l.z[0],0,l.x[1],l.y[1],l.z[1],0,l.x[2],l.y[2],l.z[2],0,0,0,0,1);let u=-e,d=-t,c=-s;return this.cameraMatrix.translate([u,d,c]),this._isActive()&&(this._renderer.states.setValue("uViewMatrix",this._renderer.states.uViewMatrix.clone()),this._renderer.states.uViewMatrix.set(this.cameraMatrix)),this}move(e,t,s){let i=this._getLocalAxes(),r=[i.x[0]*e,i.x[1]*e,i.x[2]*e],a=[i.y[0]*t,i.y[1]*t,i.y[2]*t],h=[i.z[0]*s,i.z[1]*s,i.z[2]*s];this.camera(this.eyeX+r[0]+a[0]+h[0],this.eyeY+r[1]+a[1]+h[1],this.eyeZ+r[2]+a[2]+h[2],this.centerX+r[0]+a[0]+h[0],this.centerY+r[1]+a[1]+h[1],this.centerZ+r[2]+a[2]+h[2],this.upX,this.upY,this.upZ)}setPosition(e,t,s){let i=e-this.eyeX,r=t-this.eyeY,a=s-this.eyeZ;this.camera(e,t,s,this.centerX+i,this.centerY+r,this.centerZ+a,this.upX,this.upY,this.upZ)}set(e){for(let t of["eyeX","eyeY","eyeZ","centerX","centerY","centerZ","upX","upY","upZ","cameraFOV","aspectRatio","cameraNear","cameraFar","cameraType","yScale","useLinePerspective"])this[t]=e[t];this.cameraMatrix=e.cameraMatrix.copy(),this.projMatrix=e.projMatrix.copy(),this._isActive()&&(this._renderer.states.setValue("uModelMatrix",this._renderer.states.uModelMatrix.clone()),this._renderer.states.setValue("uViewMatrix",this._renderer.states.uViewMatrix.clone()),this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uModelMatrix.reset(),this._renderer.states.uViewM
2atrix.set(this.cameraMatrix),this._renderer.states.uPMatrix.set(this.projMatrix))}slerp(e,t,s){let i,r,a,h;if(0===s)return void this.set(e);if(1===s)return void this.set(t);0!==this.projMatrix.mat4[15]&&(this.projMatrix.setElement(0,e.projMatrix.mat4[0]*Math.pow(t.projMatrix.mat4[0]/e.projMatrix.mat4[0],s)),this.projMatrix.setElement(5,e.projMatrix.mat4[5]*Math.pow(t.projMatrix.mat4[5]/e.projMatrix.mat4[5],s)),this._isActive()&&this._renderer.states.setValue("uPMatrix",this.projMatrix.clone()));let n=new C.M(e.eyeX,e.eyeY,e.eyeZ),o=new C.M(t.eyeX,t.eyeY,t.eyeZ),l=new C.M(e.centerX,e.centerY,e.centerZ),u=new C.M(t.centerX,t.centerY,t.centerZ),d=C.M.dist(n,l),c=d*Math.pow(C.M.dist(o,u)/d,s),p=C.M.sub(n,o),f=n.copy().sub(o).sub(l).add(u),m=f.magSq(),g=1;m>1e-6&&(g=Math.max(0,Math.min(g=C.M.dot(p,f)/m,1)));let _=C.M.lerp(C.M.lerp(n,l,g),C.M.lerp(o,u,g),s),y=e.cameraMatrix.createSubMatrix3x3(),x=t.cameraMatrix.createSubMatrix3x3(),w=y.row(2),M=x.row(2),v=y.row(1),S=x.row(1),T=new C.M,F=new C.M,V=new C.M,L=new C.M,E=x.mult(y.copy().transpose()),D=E.diagonal(),A=.5*(D[0]+D[1]+D[2]-1);if(1-A<1e-7){T.set(C.M.lerp(w,M,s)).normalize(),V.set(T).mult(g*c).add(_),L.set(T).mult((g-1)*c).add(_),F.set(C.M.lerp(v,S,s)).normalize(),this.camera(V.x,V.y,V.z,L.x,L.y,L.z,F.x,F.y,F.z);return}let I=1/(1-A),P=Math.max(D[0],D[1],D[2]),k=E.mat3[1]+E.mat3[3],U=E.mat3[2]+E.mat3[6],B=E.mat3[5]+E.mat3[7];P===D[0]?(i=Math.sqrt((D[0]-A)*I),I/=i,r=.5*k*I,a=.5*U*I,h=.5*(E.mat3[7]-E.mat3[5])/i):P===D[1]?(r=Math.sqrt((D[1]-A)*I),I/=r,a=.5*B*I,i=.5*k*I,h=.5*(E.mat3[2]-E.mat3[6])/r):(a=Math.sqrt((D[2]-A)*I),I/=a,i=.5*U*I,r=.5*B*I,h=.5*(E.mat3[3]-E.mat3[1])/a);let N=s*Math.atan2(h,A),R=Math.cos(N),z=Math.sin(N),G=1-R,O=i*r,Y=r*a,X=a*i,j=new b.uq([R+G*i*i,G*O+z*a,G*X-z*r,G*O-z*a,R+G*r*r,G*Y+z*i,G*X+z*r,G*Y-z*i,R+G*a*a]);j.multiplyVec(w,T),V.set(T).mult(g*c).add(_),L.set(T).mult((g-1)*c).add(_),j.multiplyVec(v,F),this.camera(V.x,V.y,V.z,L.x,L.y,L.z,F.x,F.y,F.z)}_computeCameraDefaultSettings(){this.defaultAspectRatio=this._renderer.width/this._renderer.height,this.defaultEyeX=0,this.defaultEyeY=0,this.defaultEyeZ=800,this.defaultCameraFOV=2*Math.atan(this._renderer.height/2/this.defaultEyeZ),this.defaultCenterX=0,this.defaultCenterY=0,this.defaultCenterZ=0,this.defaultCameraNear=this.defaultEyeZ*this._renderer.defaultNearScale(),this.defaultCameraFar=this.defaultEyeZ*this._renderer.defaultFarScale()}_setDefaultCamera(){this.cameraFOV=this.defaultCameraFOV,this.aspectRatio=this.defaultAspectRatio,this.eyeX=this.defaultEyeX,this.eyeY=this.defaultEyeY,this.eyeZ=this.defaultEyeZ,this.centerX=this.defaultCenterX,this.centerY=this.defaultCenterY,this.centerZ=this.defaultCenterZ,this.upX=0,this.upY=1,this.upZ=0,this.cameraNear=this.defaultCameraNear,this.cameraFar=this.defaultCameraFar,this.perspective(),this.camera(),this.cameraType="default"}_resize(){"default"===this.cameraType&&(this._computeCameraDefaultSettings(),this.cameraFOV=this.defaultCameraFOV,this.aspectRatio=this.defaultAspectRatio,this.perspective())}copy(){let e=new O(this._renderer);return e.cameraFOV=this.cameraFOV,e.aspectRatio=this.aspectRatio,e.eyeX=this.eyeX,e.eyeY=this.eyeY,e.eyeZ=this.eyeZ,e.centerX=this.centerX,e.centerY=this.centerY,e.centerZ=this.centerZ,e.upX=this.upX,e.upY=this.upY,e.upZ=this.upZ,e.cameraNear=this.cameraNear,e.cameraFar=this.cameraFar,e.cameraType=this.cameraType,e.useLinePerspective=this.useLinePerspective,e.cameraMatrix=this.cameraMatrix.copy(),e.projMatrix=this.projMatrix.copy(),e.yScale=this.yScale,e.cameraType=this.cameraType,e.defaultAspectRatio=this.defaultAspectRatio,e.defaultEyeX=this.defaultEyeX,e.defaultEyeY=this.defaultEyeY,e.defaultEyeZ=this.defaultEyeZ,e.defaultCameraFOV=this.defaultCameraFOV,e.defaultCenterX=this.defaultCenterX,e.defaultCenterY=this.defaultCenterY,e.defaultCenterZ=this.defaultCenterZ,e.defaultCameraNear=this.defaultCameraNear,e.defaultCameraFar=this.defaultCameraFar,e}clone(){return this.copy()}_getLocalAxes(){let e=this.eyeX-this.centerX,t=this.eyeY-this.centerY,s=this.eyeZ-this.centerZ,i=Math.sqrt(e*e+t*t+s*s);0!==i&&(e/=i,t/=i,s/=i);let r=this.upX,a=this.upY,h=this.upZ,n=a*s-h*t,o=-r*s+h*e,l=r*t-a*e;r=t*l-s*o,a=-e*l+s*n,h=e*o-t*n;let u=Math.sqrt(n*n+o*o+l*l);0!==u&&(n/=u,o/=u,l/=u);let d=Math.sqrt(r*r+a*a+h*h);return 0!==d&&(r/=d,a/=d,h/=d),{x:[n,o,l],y:[r,a,h],z:[e,t,s]}}_orbit(e,t,s){let i=this.eyeX-this.centerX,r=this.eyeY-this.centerY,a=this.eyeZ-this.centerZ,h=Math.hypot(i,r,a),n=new C.M(i,r,a).normalize(),o=new C.M(this.upX,this.upY,this.upZ).normalize(),l=C.M.cross(o,n).normalize(),u=C.M.cross(l,o);(h*=Math.pow(10,s))<this.cameraNear&&(h=this.cameraNear),h>this.cameraFar&&(h=this.cameraFar);let d=Math.acos(Math.max(-1,Math.min(1,C.M.dot(n,o))))+t;(d<=0||d>=Math.PI)&&(this.upX*=-1,this.upY*=-1,this.upZ*=-1),o.mult(Math.cos(d)),u.mult(Math.cos(e)*Math.sin(d)),l.mult(Math.sin(e)*Math.sin(d)),n.set(o).add(u).add(l),this.eyeX=h*n.x+this.centerX,this.eyeY=h*n.y+this.centerY,this.eyeZ=h*n.z+this.centerZ,this.camera(this.eyeX,this.eyeY,this.eyeZ,this.centerX,this.centerY,this.centerZ,this.upX,this.upY,this.upZ)}
2_orbitFree(e,t,s){let i=this.eyeX-this.centerX,r=this.eyeY-this.centerY,a=this.eyeZ-this.centerZ,h=Math.hypot(i,r,a),n=new C.M(i,r,a).normalize(),o=new C.M(this.upX,this.upY,this.upZ),l=C.M.cross(o,n).normalize(),u=C.M.cross(n,l),d=Math.atan2(t,e);u.mult(Math.sin(d)),l.mult(Math.cos(d)).add(u);let c=Math.sqrt(e*e+t*t),p=C.M.cross(n,l);(h*=Math.pow(10,s))<this.cameraNear&&(h=this.cameraNear),h>this.cameraFar&&(h=this.cameraFar);let f=Math.cos(c),m=Math.sin(c),g=o.dot(n),_=o.dot(l),y=g*f+_*m,x=-g*m+_*f,w=o.dot(p);o.x=y*n.x+x*l.x+w*p.x,o.y=y*n.y+x*l.y+w*p.y,o.z=y*n.z+x*l.z+w*p.z,l.mult(-m),n.mult(f).add(l).mult(h),this.camera(n.x+this.centerX,n.y+this.centerY,n.z+this.centerZ,this.centerX,this.centerY,this.centerZ,o.x,o.y,o.z)}_isActive(){return this===this._renderer.states.curCamera}}function Y(e,t){t.camera=function(...e){return this._assert3d("camera"),this._renderer.camera(...e),this},t.perspective=function(...e){return this._assert3d("perspective"),this._renderer.perspective(...e),this},t.linePerspective=function(e){if(!(this._renderer instanceof Z))throw Error("linePerspective() must be called in WebGL mode.");return this._renderer.linePerspective(e)},t.ortho=function(...e){return this._assert3d("ortho"),this._renderer.ortho(...e),this},t.frustum=function(...e){return this._assert3d("frustum"),this._renderer.frustum(...e),this},t.createCamera=function(){return this._assert3d("createCamera"),this._renderer.createCamera()},t.setCamera=function(e){this._renderer.setCamera(e)},e.Camera=O,Z.prototype.camera=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.camera(...e)},Z.prototype.perspective=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.perspective(...e)},Z.prototype.linePerspective=function(e){if(void 0===e)return this.states.curCamera.useLinePerspective;this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.useLinePerspective=e},Z.prototype.ortho=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.ortho(...e)},Z.prototype.frustum=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.frustum(...e)},Z.prototype.createCamera=function(){let e=new O(this);return e._computeCameraDefaultSettings(),e._setDefaultCamera(),e},Z.prototype.setCamera=function(e){this.states.setValue("curCamera",e),this.states.setValue("uPMatrix",this.states.uPMatrix.clone()),this.states.uPMatrix.set(e.projMatrix),this.states.setValue("uViewMatrix",this.states.uViewMatrix.clone()),this.states.uViewMatrix.set(e.cameraMatrix)}}"undefined"!=typeof p5&&Y(p5,p5.prototype);let{STROKE_CAP_ENUM:X,STROKE_JOIN_ENUM:j}=(0,I.x)(()=>"");class Z extends n.R{constructor(e,t,s,i,a){for(let r of(super(e,t,s,i),this.canvas=this.elt=a||document.createElement("canvas"),this.contextReady=this.setupContext(),this._isMainCanvas?(this._pInst._curElement=this,this._pInst.canvas=this.canvas):this.canvas.style.display="none",this.elt.id="defaultCanvas0",this.elt.classList.add("p5Canvas"),this.wrappedElt=new h.H(this.elt,this._pInst),Object.getOwnPropertyNames(h.H.prototype)))"constructor"!==r&&"_"!==r[0]&&Object.defineProperty(this,r,{get(){return this.wrappedElt[r]}});let n=this._adjustDimensions(t,s);if(t=n.adjustedWidth,s=n.adjustedHeight,this.width=t,this.height=s,this.elt.width=t*this._pixelDensity,this.elt.height=s*this._pixelDensity,this.elt.style.width=`${t}px`,this.elt.style.height=`${s}px`,this._updateViewport(),this._pInst._userNode)this._pInst._userNode.appendChild(this.elt);else{if(0===document.getElementsByTagName("main").length){let e=document.createElement("main");document.body.appendChild(e)}document.getElementsByTagName("main")[0].appendChild(this.elt)}this.isP3D=!0,this.geometryBuilder=void 0,this.states.uModelMatrix=new b.uq(4),this.states.uViewMatrix=new b.uq(4),this.states.uPMatrix=new b.uq(4),this.mainCamera=new O(this),this.states.curCamera||(this.states.curCamera=this.mainCamera),this.states.uPMatrix.set(this.states.curCamera.projMatrix),this.states.uViewM
2atrix.set(this.states.curCamera.cameraMatrix),this.states.enableLighting=!1,this.states.ambientLightColors=[],this.states.specularColors=[1,1,1],this.states.directionalLightDirections=[],this.states.directionalLightDiffuseColors=[],this.states.directionalLightSpecularColors=[],this.states.pointLightPositions=[],this.states.pointLightDiffuseColors=[],this.states.pointLightSpecularColors=[],this.states.spotLightPositions=[],this.states.spotLightDirections=[],this.states.spotLightDiffuseColors=[],this.states.spotLightSpecularColors=[],this.states.spotLightAngle=[],this.states.spotLightConc=[],this.states.activeImageLight=null,this.states.curFillColor=[1,1,1,1],this.states.curAmbientColor=[1,1,1,1],this.states.curSpecularColor=[0,0,0,0],this.states.curEmissiveColor=[0,0,0,0],this.states.curStrokeColor=[0,0,0,1],this.states.curBlendMode=r.B,this.states._hasSetAmbient=!1,this.states._useSpecularMaterial=!1,this.states._useEmissiveMaterial=!1,this.states._useNormalMaterial=!1,this.states._useShininess=1,this.states._useMetalness=0,this.states.tint=[255,255,255,255],this.states.constantAttenuation=1,this.states.linearAttenuation=0,this.states.quadraticAttenuation=0,this.states._currentNormal=new C.M(0,0,1),this.states.drawMode=r.aD,this.states._tex=null,this.states.textureMode=r.ad,this.states.textureWrapX=r.C,this.states.textureWrapY=r.C,this._isErasing=!1,this._simpleLines=!1,this._clipDepths=[],this._isCl
2ipApplied=!1,this._stencilTestOn=!1,this.mixedAmbientLight=[],this.mixedSpecularColor=[],this.diffusedTextures=new Map,this.specularTextures=new Map,this.preEraseBlend=void 0,this._cachedFillStyle=[1,1,1,1],this._cachedStrokeStyle=[0,0,0,1],this._isBlending=!1,this._useLineColor=!1,this._useVertexColor=!1,this.registerEnabled=new Set,this.mainCamera._computeCameraDefaultSettings(),this.mainCamera._setDefaultCamera(),this.filterCamera=new O(this),this.filterCamera._computeCameraDefaultSettings(),this.filterCamera._setDefaultCamera(),this.prevTouches=[],this.zoomVelocity=0,this.rotateVelocity=new C.M(0,0),this.moveVelocity=new C.M(0,0),this.executeZoom=!1,this.executeRotateAndMove=!1,this._drawingFilter=!1,this._drawingImage=!1,this.specularShader=void 0,this.sphereMapping=void 0,this.diffusedShader=void 0,this._baseFilterShader=void 0,this._defaultLightShader=void 0,this._defaultImmediateModeShader=void 0,this._defaultNormalShader=void 0,this._defaultColorShader=void 0,this.states.userFillShader=void 0,this.states.userStrokeShader=void 0,this.states.userImageShader=void 0,this.states.curveDetail=1/4,this.shapeBuilder=new S.V(this),this.geometryBufferCache=new T.T(this),this.curStrokeCap=r.w,this.curStrokeJoin=r.w,this.textures=new Map,this.framebuffers=new Set,this.activeFramebuffers=[],this.states.filterShader=void 0,this.filterLayer=void 0,this.filterLayerTemp=void 0,this.defaultFilterShaders={},this.fontInfos={},this._curShader=void 0,this.drawShapeCount=1,this.scratchMat3=new b.uq(3),this._validateFaces=!1,this.buffers={fill:[new D.f(3,"vertices","vertexBuffer","aPosition",this,this._vToNArray),new D.f(3,"vertexNormals","normalBuffer","aNormal",this,this._vToNArray),new D.f(4,"vertexColors","colorBuffer","aVertexColor",this).default(e=>e.vertices.flatMap(()=>[-1,-1,-1,-1])),new D.f(3,"vertexAmbients","ambientBuffer","aAmbientColor",this),new D.f(2,"uvs","uvBuffer","aTexCoord",this,e=>e.flat())],stroke:[new D.f(4,"lineVertexColors","lineColorBuffer","aVertexColor",this).default(e=>e.lineVertices.flatMap(()=>[-1,-1,-1,-1])),new D.f(3,"lineVertices","lineVerticesBuffer","aPosition",this),new D.f(3,"lineTangentsIn","lineTangentsInBuffer","aTangentIn",this),new D.f(3,"lineTangentsOut","lineTangentsOutBuffer","aTangentOut",this),new D.f(1,"lineSides","lineSidesBuffer","aSide",this)],text:[new D.f(3,"vertices","vertexBuffer","aPosition",this,this._vToNArray),new D.f(2,"uvs","uvBuffer","aTexCoord",this,e=>e.flat())],user:[]}}async _resetContext(e,t,s=Z){let i=this.width,r=this.height,a=this.canvas.id,n=this._pInst instanceof Q,o={position:this.canvas.style.position,top:this.canvas.style.top,left:this.canvas.style.left};if(n){let e=this._pInst;e.canvas.parentNode.removeChild(e.canvas),e.canvas=document.createElement("canvas"),(e._pInst._userNode||document.body).appendChild(e.canvas),h.H.call(e,e.canvas,e._pInst),e.width=i,e.height=r}else{let e=this.canvas;e&&e.parentNode.removeChild(e),(e=document.createElement("canvas")).id=a,this._pInst._userNode?this._pInst._userNode.appendChild(e):document.body.appendChild(e),this._pInst.canvas=e,this.canvas=e,this.canvas.style.position=o.position,this.canvas.style.top=o.top,this.canvas.style.left=o.left}let l=new s(this._pInst,i,r,!n,this._pInst.canvas);this._pInst._renderer=l,l._applyDefaults(),l.contextReady&&await l.contextReady,"function"==typeof t&&setTimeout(()=>{t.apply(window._renderer,e)},0)}remove(){this.wrappedElt.remove(),this.wrappedElt=null,this.canvas=null,this.elt=null}beginGeometry(){if(this.geometryBuilder)throw Error("It looks like `beginGeometry()` is being called while another p5.Geometry is already being build.");this.geometryBuilder=new M.A(this),this.geometryBuilder.prevFillColor=this.states.fillColor,this.fill(new a.C([-1,-1,-1,-1]))}endGeometry(){if(!this.geometryBuilder)throw Error("Make sure you call beginGeometry() before endGeometry()!");let e=this.geometryBuilder.finish();return this.geometryBuilder.prevFillColor?this.fill(this.geometryBuilder.prevFillColor):this.noFill(),this.geometryBuilder=void 0,e}buildGeometry(e){return this.beginGeometry(),e(),this.endGeometry()}beginShape(...e){super.beginShape(...e)}curveDetail(e){if(void 0===e)return this.states.curveDetail;this.states.setValue("curveDetail",e)}drawShape(e){let t=new V.Om({curveDetail:this.states.curveDetail});e.accept(t),this.shapeBuilder.constructFromContours(e,t.contours),this.geometryBuilder?this.geometryBuilder.addImmediate(this.shapeBuilder.geometry,this.shapeBuilder.shapeMode,{validateFaces:this._val
2idateFaces}):(this.states.fillColor||this.states.strokeColor)&&this._drawGeometry(this.shapeBuilder.geometry,{mode:this.shapeBuilder.shapeMode,count:this.drawShapeCount}),this.drawShapeCount=1}endShape(e,t){this.drawShapeCount=t,super.endShape(e,t)}vertexProperty(...e){this.currentShape.vertexProperty(...e)}normal(e,t,s){e instanceof C.M?this.states.setValue("_currentNormal",e):this.states.setValue("_currentNormal",new C.M(e,t,s)),this.updateShapeVertexProperties()}model(e,t=1){e.vertices.length>0&&(this.geometryBuilder?this.geometryBuilder.addRetained(e):(this.geometryInHash(e.gid)||(e._edgesToVertices(),this._getOrMakeCachedBuffers(e)),this._drawGeometry(e,{count:t})))}_getOrMakeCachedBuffers(e){return this.geometryBufferCache.ensureCached(e)}_drawGeometry(e,{mode:t=r.c,count:s=1}={}){for(let t in e.userVertexProperties){let s=e.userVertexProperties[t];this.buffers.user.push(new D.f(s.getDataSize(),s.getSrcName(),s.getDstName(),s.getName(),this))}this.states.fillColor&&e.vertices.length>=3&&![r.Y,r.X].includes(t)&&this._drawFills(e,{mode:t,count:s}),this.states.strokeColor&&e.lineVertices.length>=1&&this._drawStrokes(e,{count:s}),this.buffers.user=[]}_drawFills(e,{count:t,mode:s}={}){this._useVertexColor=e.vertexColors.length>0&&!e.vertexColors.isDefault;let i=!this._drawingFilter&&this.states.userFillShader?this.states.userFillShader:this._getFillShader();for(let t of(i.bindShader("fill"),this._setGlobalUniforms(i),this._setFillUniforms(i),i.bindTextures(),this.buffers.fill))t._prepareBuffer(e,i);this._prepareUserAttributes(e,i),this._disableRemainingAttributes(i),this._applyColorBlend(this.states.curFillColor,e.hasFillTransparency()),this._drawBuffers(e,{mode:s,count:t}),i.unbindShader()}_drawStrokes(e,{count:t}={}){this._useLineColor=e.vertexStrokeColors.length>0;let s=this._getStrokeShader();for(let t of(s.bindShader("stroke"),this._setGlobalUniforms(s),this._setStrokeUniforms(s),s.bindTextures(),this.buffers.stroke))t._prepareBuffer(e,s);this._prepareUserAttributes(e,s),this._disableRemainingAttributes(s),this._applyColorBlend(this.states.curStrokeColor,e.hasStrokeTransparency()),this._drawBuffers(e,{count:t}),s.unbindShader()}_prepareUserAttributes(e,t){for(let s of this.buffers.user){if(!this._pInst.constructor.disableFriendleErrors){let t=e.userVertexProperties[s.attr];if(t){let s=t.getSrcArray().length/t.getDataSize();s>e.vertices.length?this._pInst.constructor._friendlyError(`One of the geometries has a custom vertex property '${t.getName()}' with more values than vertices. This is probably caused by directly using the Geometry.vertexProperty() method.`,"vertexProperty()"):s<e.vertices.length&&this._pInst.constructor._friendlyError(`One of the geometries has a custom vertex property '${t.getName()}' with fewer values than vertices. This is probably caused by directly using the Geometry.vertexProperty() method.`,"vertexProperty()")}}s._prepareBuffer(e,t)}}_drawGeometryScaled(e,t,s,i){let r=this.states.uModelMatrix;this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone());try{this.states.uModelMatrix.scale(t,s,i),this.geometryBuilder?this.geometryBuilder.addRetained(e):this._drawGeometry(e)}finally{this.states.setValue("uModelMatrix",r)}}_update(){this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.reset(),this.states.setValue("uViewMatrix",this.states.uViewMatrix.clone()),this.states.uViewMatrix.set(this.states.curCamera.cameraMatrix),this.states.setValue("ambientLightColors",[]),this.states.setValue("specularColors",[1,1,1]),this.states.setValue("directionalLightDirections",[]),this.states.setValue("directionalLightDiffuseColors",[]),this.states.setValue("directionalLightSpecularColors",[]),this.states.setValue("pointLightPositions",[]),this.states.setValue("pointLightDiffuseColors",[]),this.states.setValue("pointLightSpecularColors",[]),this.states.setValue("spotLightPositions",[]),this.states.setValue("spotLightDirections",[]),this.states.setValue("spotLightDiffuseColors",[]),this.states.setValue("spotLightSpecularColors",[]),this.states.setValue("spotLightAngle",[]),this.states.setValue("spotLightConc",[]),this.states.setValue("enableLighting",!1),this.states.setValue("tint",[25
25,255,255,255]),this._resetBuffersBeforeDraw()}background(...e){let t=e[0];if(null!=t&&"object"==typeof t&&"number"==typeof t.width&&"number"==typeof t.height&&(null!=t.canvas||null!=t.elt)){this._pInst.clear(),this._pInst.push(),this._pInst.resetMatrix(),this._pInst.imageMode(r.v),this._pInst.image(t,0,0,this._pInst.width,this._pInst.height),this._pInst.pop();return}let s=this._pInst.color(...e);this.clear(...s._getRGBA())}get uModelMatrix(){return this.states.uModelMatrix}get uViewMatrix(){return this.states.uViewMatrix}get uPMatrix(){return this.states.uPMatrix}get uMVMatrix(){let e=this.uModelMatrix.copy();return e.mult(this.uViewMatrix),e}getWorldToScreenMatrix(){let e=this.states.uModelMatrix,t=this.states.uViewMatrix,s=this.states.uPMatrix,i=new b.uq(4);return i.scale(this.width,this.height,1),i.translate([.5,.5,.5]),i.scale(.5,-.5,.5),e.copy().mult(t).mult(s).mult(i)}fill(...e){super.fill(...e);let t=this.states.fillColor;this.states.setValue("curFillColor",t._array),this.states.setValue("drawMode",r.aD),this.states.setValue("_useNormalMaterial",!1),this.states.setValue("_tex",null)}stroke(...e){super.stroke(...e),this.states.setValue("curStrokeColor",this.states.strokeColor._array)}getCommonVertexProperties(){return{...super.getCommonVertexProperties(),stroke:this.states.strokeColor,fill:this.states.fillColor,normal:this.states._currentNormal}}getSupportedIndividualVertexProperties(){return{textureCoordinates:!0}}strokeCap(e){this.curStrokeCap=e}strokeJoin(e){this.curStrokeJoin=e}getFilterLayer(){return this.filterLayer||(this.filterLayer=new em(this)),this.filterLayer}getFilterLayerTemp(){return this.filterLayerTemp||(this.filterLayerTemp=new em(this)),this.filterLayerTemp}matchSize(e,t){(e.width!==t.width||e.height!==t.height)&&e.resize(t.width,t.height),e.pixelDensity()!==t.pixelDensity()&&e.pixelDensity(t.pixelDensity())}filter(...e){let t,s,i=this.getFilterLayer();"string"==typeof e[0]?(t=(s=e[0])in F.k&&void 0===e[1]?F.k[s]:e[1],s in this.defaultFilterShaders||(this.defaultFilterShaders[s]=this._makeFilterShader(i.renderer,s)),this.states.setValue("filterShader",this.defaultFilterShaders[s])):this.states.setValue("filterShader",e[0]);let a=this.activeFramebuffer()||this;this.matchSize(i,a),i.draw(()=>this.clear());let h=[1/(a.width*a.pixelDensity()),1/(a.height*a.pixelDensity())];if(s===r.ab){let e=this.getFilterLayerTemp();this.matchSize(e,a),this.push(),this.states.setValue("strokeColor",null),this.blendMode(r.B),this.shader(this.states.filterShader),this.states.filterShader.setUniform("texelSize",h),this.states.filterShader.setUniform("canvasSize",[a.width,a.height]),this.states.filterShader.setUniform("radius",Math.max(1,t)),e.draw(()=>{this.states.filterShader.setUniform("direction",[1,0]),this.states.filterShader.setUniform("tex0",a),this.clear(),this.shader(this.states.filterShader),this.noLights(),this.plane(a.width,a.height)}),i.draw(()=>{this.states.filterShader.setUniform("direction",[0,1]),this.states.filterShader.setUniform("tex0",e),this.clear(),this.shader(this.states.filterShader),this.noLights(),this.plane(a.width,a.height)}),this.pop()}else i.draw(()=>{this.states.setValue("strokeColor",null),this.blendMode(r.B),this.shader(this.states.filterShader),this.states.filterShader.setUniform("tex0",a),this.states.filterShader.setUniform("texelSize",h),this.states.filterShader.setUniform("canvasSize",[a.width,a.height]),this.states.filterShader.setUniform("filterParameter",t),this.noLights(),this.plane(a.width,a.height)});this.push(),this.states.setValue("strokeColor",null),this.clear(),this.push(),this.states.setValue("imageMode",r.p),this.blendMode(r.B),a.filterCamera._resize(),this.setCamera(a.filterCamera),this.resetMatrix(),this._drawingFilter=!0,this.image(i,0,0,i.width,i.height,-a.width/2,-a.height/2,a.width,a.height),this._drawingFilter=!1,this.clearDepth(),this.pop(),this.pop()}pixelDensity(e){return e?this._pInst.pixelDensity(e):this._pInst.pixelDensity()}blendMode(e){e===r.D||e===r.L||e===r.A||e===r.B||e===r.S||e===r.a||e===r.E||e===r.R||e===r.M||e===r.b?this.states.setValue("curBlendM
2ode",e):(e===r.as||e===r.ao||e===r.ap||e===r.aq||e===r.ar)&&console.warn("BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only work for blendMode in 2D mode.")}erase(e,t){this._isErasing||(this.preEraseBlend=this.states.curBlendMode,this._isErasing=!0,this.blendMode(r.b),this._cachedFillStyle=this.states.curFillColor.slice(),this.states.setValue("curFillColor",[1,1,1,e/255]),this._cachedStrokeStyle=this.states.curStrokeColor.slice(),this.states.setValue("curStrokeColor",[1,1,1,t/255]))}noErase(){this._isErasing&&(this.states.setValue("curFillColor",this._cachedFillStyle.slice()),this.states.setValue("curStrokeColor",this._cachedStrokeStyle.slice()),this.states.setValue("curBlendMode",this.preEraseBlend),this.blendMode(this.preEraseBlend),this._isErasing=!1,this._applyBlendMode())}_applyBlendMode(){}drawTarget(){return this.activeFramebuffers[this.activeFramebuffers.length-1]||this}beginClip(e={}){super.beginClip(e),this.drawTarget()._isClipApplied=!0,this._applyClip(),this.push(),this.resetShader(),this.states.fillColor&&this.fill(0,0),this.states.strokeColor&&this.stroke(0,0)}endClip(){this.pop(),this._unapplyClip(),this._clipDepths.push(this._pushPopDepth),super.endClip()}_clearClip(){this._clearClipBuffer(),this._clipDepths.length>0&&this._clipDepths.pop(),this.drawTarget()._isClipApplied=!1}_getTempFramebuffer(){return this._tempFramebuffer||(this._tempFramebuffer=new em(this,{format:r.U,useDepth:this._pInst._glAttributes.depth,depthFormat:r.d,antialias:this._pInst._glAttributes.antialias})),this._tempFramebuffer}geometryInHash(e){return this.geometryBufferCache.isCached(e)}resize(e,t){super.resize(e,t);let s={};for(let e in this.drawingContext){let t=this.drawingContext[e];"object"!=typeof t&&"function"!=typeof t&&(s[e]=t)}let i=this._adjustDimensions(e,t);for(let s of(e=i.adjustedWidth,t=i.adjustedHeight,this.width=e,this.height=t,this.canvas.width=e*this._pixelDensity,this.canvas.height=t*this._pixelDensity,this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this._updateViewport(),this._updateSize(),this.mainCamera._resize(),this.states.curCamera!==this.mainCamera&&this.states.curCamera._resize(),void 0!==this.pixels&&this._createPixelsArray(),this.framebuffers))this.flushDraw?.(),s._canvasSizeChanged();for(let e in this.flushDraw?.(),s)try{this.drawingContext[e]=s[e]}catch(e){}}applyMatrix(e,t,s,i,r,a){this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),16==arguments.length?b.uq.prototype.apply.apply(this.states.uModelMatrix,arguments):this.states.uModelMatrix.apply([e,t,0,0,s,i,0,0,0,0,1,0,r,a,0,1])}translate(e,t,s){return e instanceof C.M&&(s=e.z,t=e.y,e=e.x),this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.translate([e,t,s]),this}scale(e,t,s){return this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.scale(e,t,s),this}rotate(e,t){return void 0===t?this.rotateZ(e):(this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),b.uq.prototype.rotate4x4.apply(this.states.uModelMatrix,arguments),this)}rotateX(e){return this.rotate(e,1,0,0),this}rotateY(e){return this.rotate(e,0,1,0),this}rotateZ(e){return this.rotate(e,0,0,1),this}pop(...e){this._clipDepths.length>0&&this._pushPopDepth===this._clipDepths[this._clipDepths.length-1]&&this._clearClip(),super.pop(...e),this._applyStencilTestIfClipping()}resetMatrix(){return this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.reset(),this.states.setValue("uViewMatrix",this.states.uViewMatrix.clone()),this.states.uViewMatrix.set(this.states.curCamera.cameraMatrix),this}_getStrokeShader(){let e=this.states.userStrokeShader;return e||this._getLineShader()}_getFillShader(){if(this._drawingImage)if(this.states.userImageShader&&!this._drawingFilter)return this.states.userImageShader;else return this._getLightShader();return this.states.userFillShader?this.states.userFillShader:this.states._useNormalMaterial?this._getNormalShader():this.states.enableLighting||this.states._tex?this._getLightShader():this._getColorShader()}baseMaterialShader(){return this._getLightShader()}baseNormalShader(){return this._getNormalShader()}baseColorShader(){return this._getColorShader()}baseStrokeShader(){return this._getLineShader()}activeFramebuffer(){return this.activeFramebuffers[this.activeFramebuffers.length-1]||null}createFramebuffer(e){return new em(this,e)}_setGlobalUniforms(e){let t=this.states.uModelMatrix,s=this.states.uViewM
2atrix,i=this.states.uPMatrix,r=t.copy().mult(s);if(e.setUniform("uPerspective",+!!this.states.curCamera.useLinePerspective),e.setUniform("uViewMatrix",s.mat4),e.setUniform("uProjectionMatrix",i.mat4),e.setUniform("uModelMatrix",t.mat4),e.setUniform("uModelViewMatrix",r.mat4),e.uniforms.uModelViewProjectionMatrix){let t=r.copy();t.mult(i),e.setUniform("uModelViewProjectionMatrix",t.mat4)}e.uniforms.uNormalMatrix&&(this.scratchMat3.inverseTranspose4x4(r),e.setUniform("uNormalMatrix",this.scratchMat3.mat3)),e.uniforms.uModelNormalMatrix&&(this.scratchMat3.inverseTranspose4x4(this.states.uModelMatrix),e.setUniform("uModelNormalMatrix",this.scratchMat3.mat3)),e.uniforms.uCameraNormalMatrix&&(this.scratchMat3.inverseTranspose4x4(this.states.uViewMatrix),e.setUniform("uCameraNormalMatrix",this.scratchMat3.mat3)),e.setUniform("uViewport",this._viewport)}_setStrokeUniforms(e){e.setUniform("uSimpleLines",this._simpleLines),e.setUniform("uUseLineColor",this._useLineColor),e.setUniform("uMaterialColor",this.states.curStrokeColor),e.setUniform("uStrokeWeight",this.states.strokeWeight),e.setUniform("uStrokeCap",X[this.curStrokeCap]),e.setUniform("uStrokeJoin",j[this.curStrokeJoin])}_setFillUniforms(e){this.mixedSpecularColor=[...this.states.curSpecularColor];let t=this._getEmptyTexture();this.states._useMetalness>0&&(this.mixedSpecularColor=this.mixedSpecularColor.map((e,t)=>this.states.curFillColor[t]*this.states._useMetalness+e*(1-this.states._useMetalness))),e.setUniform("uUseVertexColor",this._useVertexColor),e.setUniform("uMaterialColor",this.states.curFillColor),e.setUniform("isTexture",!!this.states._tex),e.setUniform("uSampler",this.states._tex||t),e.setUniform("uTint",this.states.tint),e.setUniform("uHasSetAmbient",this.states._hasSetAmbient),e.setUniform("uAmbientMatColor",this.states.curAmbientColor),e.setUniform("uSpecularMatColor",this.mixedSpecularColor),e.setUniform("uEmissiveMatColor",this.states.curEmissiveColor),e.setUniform("uSpecular",this.states._useSpecularMaterial),e.setUniform("uEmissive",this.states._useEmissiveMaterial),e.setUniform("uShininess",this.states._useShininess),e.setUniform("uMetallic",this.states._useMetalness),this._setImageLightUniforms(e),e.setUniform("uUseLighting",this.states.enableLighting);let s=this.states.pointLightDiffuseColors.length/3;e.setUniform("uPointLightCount",s),e.setUniform("uPointLightLocation",this.states.pointLightPositions),e.setUniform("uPointLightDiffuseColors",this.states.pointLightDiffuseColors),e.setUniform("uPointLightSpecularColors",this.states.pointLightSpecularColors);let i=this.states.directionalLightDiffuseColors.length/3;e.setUniform("uDirectionalLightCount",i),e.setUniform("uLightingDirection",this.states.directionalLightDirections),e.setUniform("uDirectionalDiffuseColors",this.states.directionalLightDiffuseColors),e.setUniform("uDirectionalSpecularColors",this.states.directionalLightSpecularColors);let r=[0,0,0];for(let e=0;e<this.states.ambientLightColors.length;e+=3)for(let t=0;t<3;t++)this.states._useMetalness>0?r[t]+=Math.max(0,this.states.ambientLightColors[e+t]-this.states._useMetalness):r[t]+=this.states.ambientLightColors[e+t];e.setUniform("uAmbientColor",r);let a=this.states.spotLightDiffuseColors.length/3;e.setUniform("uSpotLightCount",a),e.setUniform("uSpotLightAngle",this.states.spotLightAngle),e.setUniform("uSpotLightConc",this.states.spotLightConc),e.setUniform("uSpotLightDiffuseColors",this.states.spotLightDiffuseColors),e.setUniform("uSpotLightSpecularColors",this.states.spotLightSpecularColors),e.setUniform("uSpotLightLocation",this.states.spotLightPositions),e.setUniform("uSpotLightDirection",this.states.spotLightDirections),e.setUniform("uConstantAttenuation",this.states.constantAttenuation),e.setUniform("uLinearAttenuation",this.states.linearAttenuation),e.setUniform("uQuadraticAttenuation",this.states.quadraticAttenuation)}_setImageLightUniforms(e){if(e.setUniform("uUseImageLight",null!=this.states.activeImageLight),this.states.activeImageLight){let t=this.getDiffusedTexture(this.states.activeImageLight);e.setUniform("environmentMapDiffused",t);let s=this.getSpecularTexture(this.states.activeImageLight);e.setUniform("environmentMapSpecular",s)}else e.setUniform("environmentMapDiffused",this._getEmptyTexture()),e.setUniform("environmentMapSpecular",this._getEmptyTexture())}_getEmptyTexture(){if(!this._emptyTexture){let e=new n.I(1,1);e.set(0,0,255),this._emptyTexture=new et(this,e)}return this._emptyTexture}getTexture(e){let t=e;t instanceof em&&(t=t.color);let s=this.textures.get(t);if(s)return s;let i=new et(this,t);return this.textures.set(t,i),i}_normalizeBufferData(e,t=Float32Array){return e?e instanceof L.U?e.dataArray():e instanceof t?e:new t(e):null}_arraysEqual(e,t){return e.length===t.length&&e.every((e,s)=>e===t[s])}_isTypedArray(e){return[Float32Array,Float64Array,Int16Array,Uint16Array,Uint32Array].some(t=>e instanceof t)}_vToNArray(e){return e.flatMap(e=>[e.x,e.y,e.z])}_beforeDrawText(){}_afterDrawText(){}textCanvas(){return this._textCanvas||(this._textCanvas=document.createElement("canvas"),this._textCanvas.width=1,this._textCanvas.height=1,this._textCanvas.style.display="none",this.canvas.parentElement.insertBefore(this._textCanvas,this.canvas)),this._textCanvas}textDrawingContext(){if(!this._textDrawingContext){let e=this.textCanvas();this._textDrawingContext=e.getContext("2d")}return this._textDrawingContext}
2_positionLines(e,t,s,i,a){let{textLeading:h,textAlign:n}=this.states,o=a.map(e=>this._fontWidthSingle(e)),l,u=Array(a.length),d=void 0===s?Math.max(0,...o):s;for(let i=0;i<a.length;i++){switch(n){case E.wU.START:throw Error("textBounds: START not yet supported for textAlign");case r.av:l=e;break;case r.v:l=e+(d-o[i])/2-d/2+(s||0)/2;break;case r.a9:l=e+d-o[i]-d+(s||0);break;case E.wU.END:throw Error("textBounds: END not yet supported for textAlign");default:l=e}u[i]={text:a[i],x:l,y:t+i*h}}return this._yAlignOffset(u,void 0===i?0:i)}_verticalAlignFont=function(){let e=this.textDrawingContext().measureText("X");return-e.alphabeticBaseline||-e.fontBoundingBoxAscent+e.fontBoundingBoxDescent};_yAlignOffset(e,t){if(void 0===t)throw Error("_yAlignOffset: height is required");let{textLeading:s,textBaseline:i,textSize:a,textFont:h}=this.states,n=0,o=e.length,l=a*o+(s-a)*(o-1);switch(i){case r.ay:n=this._verticalAlignFont();break;case r.ax:break;case E.wU._CTX_MIDDLE:n=(-l+a+(t||0))/2+this._verticalAlignFont()+this._middleAlignOffset();break;case r.aw:n=-(l-a)+(t||0);break;default:console.warn(`${i} is not supported in WebGL mode.`)}return e.forEach(e=>e.y+=n),e}_makeFilterShader(e,t){let s=this._pInst;return(0,A.C)(this,t,s)}makeDiffusedTexture(e){let t;if(null!=this.diffusedTextures.get(e))return this.diffusedTextures.get(e);let s=Math.floor(200*(e.height/e.width));return t=new em(this,{width:200,height:s,density:1}),this.diffusedShader||(this.diffusedShader=this._createImageLightShader("diffused")),t.draw(()=>{this.shader(this.diffusedShader),this._setImageLightShaderUniforms(this.diffusedShader,e),this.states.setValue("strokeColor",null),this.noLights(),this.plane(200,s)}),this.diffusedTextures.set(e,t),t}getDiffusedTexture(e){return this.diffusedTextures.get(e)}makeSpecularTexture(e){let t;if(null!=this.specularTextures.get(e))return this.specularTextures.get(e);let s=Math.floor(Math.log2(512))+1;this.specularShader||(this.specularShader=this._createImageLightShader("specular"));let i=this._prepareMipmapData(512,s),r=new em(this,{width:512,height:512,density:1}),a=0;for(let t=512;t>=1;t/=2){r.resize(t,t);let h=1-Math.log(t)/Math.log(2)/s;r.draw(()=>{this.shader(this.specularShader),this.clear(),this._setImageLightShaderUniforms(this.specularShader,e,h),this.states.setValue("strokeColor",null),this.noLights(),this.plane(t,t)}),this._accumulateMipLevel(r,i,a,t,t),a++}return r.remove(),t=this._finalizeMipmapTexture(i),this.specularTextures.set(e,t),t}getSpecularTexture(e){return this.specularTextures.get(e)}_getSphereMapping(e){if(!this.sphereMapping){let e=this._pInst;this.sphereMapping=this.baseFilterShader().modify(({p5:e})=>{let t=e.uniformTexture("uEnvMap"),s=e.uniformFloat("uFovY"),i=e.uniformFloat("uAspect"),r=e.uniformVec3("uN1"),a=e.uniformVec3("uN2"),h=e.uniformVec3("uN3");e.getColor(n=>{let o=s*i,l=e.mix(s/2,-s/2,n.texCoord.y),u=e.mix(o/2,-o/2,n.texCoord.x),d=e.normalize([u,l,1]),c=(d=[e.dot(d,r),e.dot(d,a),e.dot(d,h)]).z;d.z=d.x,d.x=-c;let p=[e.atan(d.z,d.x)/(2*e.PI)+.5,.5+-(.5*d.y)];return e.getTexture(t,p)})},{p5:e})}this.scratchMat3.inverseTranspose4x4(this.states.uViewMatrix),this.scratchMat3.invert(this.scratchMat3),this.sphereMapping.setUniform("uFovY",this.states.curCamera.cameraFOV),this.sphereMapping.setUniform("uAspect",this.states.curCamera.aspectRatio);let t=this.scratchMat3.mat3;return this.sphereMapping.setUniform("uN1",[t[0],t[3],t[6]]),this.sphereMapping.setUniform("uN2",[t[1],t[4],t[7]]),this.sphereMapping.setUniform("uN3",[t[2],t[5],t[8]]),this.sphereMapping.setUniform("uEnvMap",e),this.sphereMapping}_createImageLightShader(e){throw Error("_createImageLightShader must be implemented by the renderer")}_setImageLightShaderUniforms(e,t,s){e.setUniform("environmentMap",t),void 0!==s&&e.setUniform("roughness",s)}_createMipmapTexture(e){throw Error("_createMipmapTexture must be implemented by the renderer")}_prepareMipmapData(e,t){throw Error("_prepareMipmapData must be implemented by the renderer")}_accumulateMipLevel(e,t,s,i,r){throw Error("_accumulateMipLevel must be implemented by the renderer")}_finalizeMipmapTexture(e){throw Error("_finalizeMipmapTexture must be implemented by the renderer")}remove(){this._textCanvas&&this._textCanvas.parentElement.removeChild(this._textCanvas),super.remove()}}function H(e,t){e.Renderer3D=Z}function $(e,t){t.strokeMode=function(e){if(void 0===e)return this._renderer._simpleLines?r.aE:r.aF;if(e===r.aE)this._renderer._simpleLines=!0;else if(e===r.aF)this._renderer._simpleLines=!1;else throw Error("no such parameter")},t.buildGeometry=function(e){return this._renderer.buildGeometry(e)},t.freeGeometry=function(e){this._renderer.geometryBufferCache.freeBuffers(e.gid)}
2,t.plane=function(e=50,t=e,s=1,i=1){return this._assert3d("plane"),this._renderer.plane(e,t,s,i),this},t.box=function(e,t,s,i,r){return this._assert3d("box"),this._renderer.box(e,t,s,i,r),this},t.sphere=function(e=50,t=24,s=16){return this._assert3d("sphere"),this._renderer.sphere(e,t,s),this},t.cylinder=function(e=50,t=e,s=24,i=1,r=!0,a=!0){return this._assert3d("cylinder"),this._renderer.cylinder(e,t,s,i,r,a),this},t.cone=function(e=50,t=e,s=24,i=1,r=!0){return this._assert3d("cone"),this._renderer.cone(e,t,s,i,r),this},t.ellipsoid=function(e=50,t=e,s=e,i=24,r=16){return this._assert3d("ellipsoid"),this._renderer.ellipsoid(e,t,s,i,r),this},t.torus=function(e,t,s,i){return this._assert3d("torus"),this._renderer.torus(e,t,s,i),this},Z.prototype.point=function(e,t,s=0){return this.beginShape(r.X),this.vertex(e,t,s),this.endShape(),this},Z.prototype.triangle=function(e){let t=e[0],s=e[1],i=e[2],r=e[3],a=e[4],h=e[5];if(!this.geometryInHash("tri")){let e=new P.V(1,1,function(){let e=[];e.push(new C.M(0,0,0)),e.push(new C.M(1,0,0)),e.push(new C.M(0,1,0)),this.edges=[[0,1],[1,2],[2,0]],this.vertices=e,this.faces=[[0,1,2]],this.uvs=[0,0,1,0,1,1]},this);e._edgesToVertices(),e.computeNormals(),e.gid="tri",this.geometryBufferCache.ensureCached(e)}let n=this.states.uModelMatrix.copy();try{let e=Math.sign(t*r-i*s+i*h-a*r+a*s-t*h),n=new b.uq([i-t,r-s,0,0,a-t,h-s,0,0,0,0,e,0,t,s,0,1]).mult(this.states.uModelMatrix);this.states.setValue("uModelMatrix",n),this.model(this.geometryBufferCache.getGeometryByID("tri"))}finally{this.states.setValue("uModelMatrix",n)}return this},Z.prototype.ellipse=function(e){this.arc(e[0],e[1],e[2],e[3],0,r.q,r.Q,e[4])},Z.prototype.arc=function(...e){let t,s,i=e[0],a=e[1],h=e[2],n=e[3],o=e[4],l=e[5],u=e[6],d=e[7]||25;if(Math.abs(l-o)>=r.q?(t="ellipse",s=`${t}|${d}|`):(t="arc",s=`${t}|${o}|${l}|${u}|${d}|`),!this.geometryInHash(s)){let e=new P.V(d,1,function(){if(o.toFixed(10)!==l.toFixed(10)){(u===r.at||void 0===u)&&(this.vertices.push(new C.M(.5,.5,0)),this.uvs.push([.5,.5]));for(let e=0;e<=d;e++){let t=e/d*(l-o)+o,s=.5+Math.cos(t)/2,i=.5+Math.sin(t)/2;this.vertices.push(new C.M(s,i,0)),this.uvs.push([s,i]),e<d-1&&(this.faces.push([0,e+1,e+2]),this.edges.push([e+1,e+2]))}switch(u){case r.at:this.faces.push([0,this.vertices.length-2,this.vertices.length-1]),this.edges.push([0,1]),this.edges.push([this.vertices.length-2,this.vertices.length-1]),this.edges.push([0,this.vertices.length-1]);break;case r.au:this.edges.push([0,1]),this.edges.push([0,this.vertices.length-1]);break;case r.Q:this.edges.push([0,1]);break;default:this.faces.push([0,this.vertices.length-2,this.vertices.length-1]),this.edges.push([this.vertices.length-2,this.vertices.length-1])}}},this);e.computeNormals(),d<=50?e._edgesToVertices(e):this.states.strokeColor&&console.log(`Cannot apply a stroke to an ${t} with more than 50 detail`),e.gid=s,this.geometryBufferCache.ensureCached(e)}let c=this.states.uModelMatrix;this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone());try{this.states.uModelMatrix.translate([i,a,0]),this.states.uModelMatrix.scale(h,n,1),this.model(this.geometryBufferCache.getGeometryByID(s))}finally{this.states.setValue("uModelMatrix",c)}return this},Z.prototype.rect=function(e){let t=e[0],s=e[1],i=e[2],a=e[3];if(void 0===e[4]){let r=this._pInst._glAttributes?.perPixelLighting??!0,h=e[4]||(r?1:24),n=e[5]||(r?1:16),o=`rect|${h}|${n}`;if(!this.geometryInHash(o)){let e=new P.V(h,n,function(){for(let e=0;e<=this.detailY;e++){let t=e/this.detailY;for(let e=0;e<=this.detailX;e++){let s=e/this.detailX,i=new C.M(s,t,0);this.vertices.push(i),this.uvs.push(s,t)}}h>0&&n>0&&(this.edges=[[0,h],[h,(h+1)*(n+1)-1],[(h+1)*(n+1)-1,(h+1)*n],[(h+1)*n,0]])},this);e.computeFaces().computeNormals()._edgesToVertices(),e.gid=o,this.geometryBufferCache.ensureCached(e)}let l=this.states.uModelMatrix;this.states.setValue("uModelMatrix",this.states.uModelMatrix.copy());try{this.states.uModelMatrix.translate([t,s,0]),this.states.uModelMatrix.scale(i,a,1),this.model(this.geometryBufferCache.getGeometryByID(o))}finally{this.states.setValue("uModelMatrix",l)}}else{let h=e[4],n=void 0===e[5]?h:e[5],o=void 0===e[6]?n:e[6],l=void 0===e[7]?o:e[7],u=t,d=s,c=i,p=a;if(c+=u,p+=d,u>c){let e=u;u=c,c=e}if(d>p){let e=d;d=p,p=e}let f=Math.min((c-u)/2,(p-d)/2);h>f&&(h=f),n>f&&(n=f),o>f&&(o=f),l>f&&(l=f);let m=u,g=d,_=c,y=p,x=this.states.textureMode;this.states.setValue("textureMode",r.a2);let w=this.bezierOrder();this.bezierOrder(2),this.beginShape();let M=(e,t)=>[e,t,0,(e-m)/i,(t-g)/a];0!==n?(this.vertex(...M(_-n,g)),this.bezierVertex(...M(_,g)),this.bezierVertex(...M(_,g+n))):this.vertex(...M(_,g)),0!==o?(this.vertex(...M(_,y-o)),this.bezierVertex(...M(_,y)),this.bezierVertex(...M(_-o,y))):this.vertex(...M(_,y)),0!==l?(this.vertex(...M(m+l,y)),this.bezierVertex(...M(m,y)),this.bezierVertex(...M(m,y-l))):this.vertex(...M(m,y)),0!==h?(this.vertex(...M(m,g+h)),this.bezierVertex(...M(m,g)),this.bezierVertex(...M(m+h,g))):this.vertex(...M(m,g)),this.endShape(r.V),this.states.setValue("textureMode",x),this.bezierOrder(w)}return this},Z.prototype.quad=function(e,t,s,i,r,a,h,n,o,l,u,d,c=2,p=2){let f=`quad|${e}|${t}|${s}|${i}|${r}|${a}|${h}|${n}|${o}|${l}|${u}|${d}|${c}|${p}`;if(!this.geometryInHash(f)){let m=new P.V(c,p,function(){let c=1/(this.detailX-1),p=1/(this.detailY-1);for(let f=0;f<this.detailY;f++)for(let m=0;m<this.detailX;m++){let g=m*c,_=f*p,y=(1-_)*e+_*l,x=(1-_)*t+_*u,w=(1-_)*s+_*d,M=(1-g)*y+g*((1-_)*i+_*h),v=(1-g)*x+g*((1-_)*r+_*n),b=(1-g)*w+g*((1-_)*a+_*o);this.vertices.push(new C.M(M,v,b)),this.uvs.push([g,_])}},this);m.faces=[];for(let e=0;e<p-1;e++)for(let t=0;t<c-1;t++){let s=t+e*c,i=t+1+e*c,r=t+1+(e+1)*c,a=t+(e+1)*c;m.faces.push([s,i,r]),m.faces.push([s,r,a])}m.computeNormals(),m.edges.length=0;let g=[0,2,3,1];for(let e=0;e<g.length;e++){let t=g[e],s=g[(e+1)%g.length];m.edges.push([t,s])}m._edgesToVertices(),m.gid=f,this.geometryBufferCache.ensureCached(m)}return this.model(this.geometryBufferCache.getGeometryByID(f)),this},Z.prototype.bezier=function(e,t,s,i,r,a,h,n,o,l,u,d){8==arguments.length&&(u=n,l=h,n=a,h=r,r=i,i=s,s=a=o=d=0),this.bezierOrder(),this.bezierOrder(3),this.beginShape(),this.vertex(e,t,s),this.bezierVertex(i,r,a),this.bezierVertex(h,n,o),this.bezierVertex(l,u,d),this.endShape()},Z.prototype.curve=function(e,t,s,i,r,a,h,n,o,l,u,d){8==arguments.length&&(l=h,u=n,h=r,n=i,r=i=s,s=a=o=d=0),this.beginShape(),this.splineVertex(e,t,s),this.splineVertex(i,r,a),this.splineVertex(h,n,o),this.splineVertex(l,u,d),this.endShape()},Z.prototype.line=function(...e){return 6===e.length?(this.beginShape(r.Y),this.vertex(e[0],e[1],e[2]),this.vertex(e[3],e[4],e[5]),this.endShape()):4===e.length&&(this.beginShape(r.Y),this.vertex(e[0],e[1],0),this.vertex(e[2],e[3],0),this.endShape()),this},Z.prototype.image=function(e,t,s,i,a,h,n,o,l){this._isErasing&&this.blendMode(this._cachedBlendMode),this.push(),this.noLights(),this.states.setValue("strokeColor",null),this.texture(e),this.states.setValue("textureMode",r.a2);let u=0;t<=e.width&&(u=t/e.width);let d=1;t+i<=e.width&&(d=(t+i)/e.width);let c=0;s<=e.height&&(c=s/e.height);let p=1;s+a<=e.height&&(p=(s+a)/e.height),this._drawingImage=!0,this.beginShape(),this.vertex(h,n,0,u,c),this.vertex(h+o,n,0,d,c),this.vertex(h+o,n+l,0,d,p),this.vertex(h,n+l,0,u,p),this.endShape(r.V),this._drawingImage=!1,this.pop(),this._isErasing&&this.blendMode(r.b)};let s=function(e,t,s,i,r,a,h){let n,o,l;e=e<=0?1:e,t=t<0?0:t,s=s<=0?e:s,i=i<3?3:i;let u=(a=void 0===a||a)?-2:0,d=(r=r<1?1:r)+2*!!(h=void 0===h?0!==t:h),c=Math.atan2(e-t,s),p=Math.sin(c),f=Math.cos(c);for(n=u;n<=d;++n){let a,h=n/r,l=s*h;for(n<0?(l=0,h=0,a=e):n>r?(l=s,h=1,a=t):a=e+(t-e)*h,(-2===n||n===r+2)&&(a=0),l-=s/2,o=0;o<i;++o){let e,s=o/(i-1),u=2*Math.PI*s,d=Math.sin(u),c=Math.cos(u);this.vertices.push(new C.M(d*a,l,c*a)),e=n<0?new C.M(0,-1,0):n>r&&t?new C.M(0,1,0):new C.M(d*f,p,c*f),this.vertexNormals.push(e),this.uvs.push(s,h)}}let m=0;if(a){for(l=0;l<i;++l){let e=(l+1)%i;this.faces.push([m+l,m+i+e,m+i+l])}m+=2*i}for(n=0;n<r;++n){for(o=0;o<i;++o){let e=(o+1)%i;this.faces.push([m+o,m+e,m+i+e]),this.faces.push([m+o,m+i+e,m+i+o])}m+=i}if(h)for(m+=i,o=0;o<i;++o)this.faces.push([m+o,m+(o+1)%i,m+i])};
2Z.prototype.plane=function(e=50,t=e,s=1,i=1){let r=`plane|${s}|${i}`;if(!this.geometryInHash(r)){let e=new P.V(s,i,function(){let e,t,s;for(let i=0;i<=this.detailY;i++){t=i/this.detailY;for(let i=0;i<=this.detailX;i++)e=i/this.detailX,s=new C.M(e-.5,t-.5,0),this.vertices.push(s),this.uvs.push(e,t)}},this);e.computeFaces().computeNormals(),s<=1&&i<=1?e._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on plane objects with more than 1 detailX or 1 detailY"),e.gid=r,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(r),e,t,1)},Z.prototype.box=function(e=50,t=e,s=t,i,r){let a=this.attributes&&this.attributes.perPixelLighting;void 0===i&&(i=a?1:4),void 0===r&&(r=a?1:4);let h=`box|${i}|${r}`;if(!this.geometryInHash(h)){let e=new P.V(i,r,function(){this.edges=[[0,1],[1,3],[3,2],[6,7],[8,9],[9,11],[14,15],[16,17],[17,19],[18,19],[20,21],[22,23]],[[0,4,2,6],[1,3,5,7],[0,1,4,5],[2,6,3,7],[0,2,1,3],[4,5,6,7]].forEach((e,t)=>{let s=4*t;for(let t=0;t<4;t++){let s=e[t],i=new C.M(((1&s)*2-1)/2,((2&s)-1)/2,((4&s)/2-1)/2);this.vertices.push(i),this.uvs.push(1&t,(2&t)/2)}this.faces.push([s,s+1,s+2]),this.faces.push([s+2,s+1,s+3])})},this);e.computeNormals(),i<=4&&r<=4?e._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on box objects with more than 4 detailX or 4 detailY"),e.gid=h,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(h),e,t,s)},Z.prototype.sphere=function(e=50,t=24,s=16){this.ellipsoid(e,e,e,t,s)},Z.prototype.ellipsoid=function(t=50,s=t,i=t,r=24,a=16){let h=`ellipsoid|${r}|${a}`;if(!this.geometryInHash(h)){let t=new P.V(r,a,function(){for(let t=0;t<=this.detailY;t++){let s=t/this.detailY,i=Math.PI*s-Math.PI/2,r=Math.cos(i),a=Math.sin(i);for(let t=0;t<=this.detailX;t++){let i=t/this.detailX,h=2*Math.PI*i,n=Math.cos(h),o=Math.sin(h),l=new e.Vector(r*o,a,r*n);this.vertices.push(l),this.vertexNormals.push(l),this.uvs.push(i,s)}}},this);t.computeFaces(),r<=24&&a<=24?t._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on ellipsoids with more than 24 detailX or 24 detailY"),t.gid=h,this.geometryBufferCache.ensureCached(t)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(h),t,s,i)},Z.prototype.cylinder=function(t=50,i=t,r=24,a=1,h=!0,n=!0){let o=`cylinder|${r}|${a}|${h}|${n}`;if(!this.geometryInHash(o)){let t=new e.Geometry(r,a,function(){s.call(this,1,1,1,r,a,h,n)},this);r<=24&&a<=16?t._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on cylinder objects with more than 24 detailX or 16 detailY"),t.gid=o,this.geometryBufferCache.ensureCached(t)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(o),t,i,t)},Z.prototype.cone=function(e=50,t=e,i=24,r=1,a=!0){let h=`cone|${i}|${r}|${a}`;if(!this.geometryInHash(h)){let e=new P.V(i,r,function(){s.call(this,1,0,1,i,r,a,!1)},this);i<=24&&r<=16?e._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on cone objects with more than 24 detailX or 16 detailY"),e.gid=h,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(h),e,t,e)},Z.prototype.torus=function(e=50,t=10,s=24,i=16){if(0===e||0===t)return;let r=(t/e).toPrecision(4),a=`torus|${r}|${s}|${i}`;if(!this.geometryInHash(a)){let e=new P.V(s,i,function(){for(let e=0;e<=this.detailY;e++){let t=e/this.detailY,s=2*Math.PI*t,i=Math.cos(s),a=Math.sin(s),h=1+r*i;for(let e=0;e<=this.detailX;e++){let s=e/this.detailX,n=2*Math.PI*s,o=Math.cos(n),l=Math.sin(n),u=new C.M(h*o,h*l,r*a),d=new C.M(i*o,i*l,a);this.vertices.push(u),this.vertexNormals.push(d),this.uvs.push(s,t)}}},this);e.computeFaces(),s<=24&&i<=16?e._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw strokes on torus object with more than 24 detailX or 16 detailY"),e.gid=a,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(a),e,e,e)},t.curveDetail=function(e){if(!(this._renderer instanceof Z))throw Error("curveDetail() only w
2orks in WebGL mode. Did you mean to call createCanvas(width, height, WEBGL)?");return this._renderer.curveDetail(e)}}function W(e,t){t.ambientLight=function(e,t,s,i){return this._assert3d("ambientLight"),this._renderer.ambientLight(...arguments),this},t.specularColor=function(e,t,s){return this._assert3d("specularColor"),this._renderer.specularColor(...arguments),this},t.directionalLight=function(e,t,s,i,r,a){return this._assert3d("directionalLight"),this._renderer.directionalLight(...arguments),this},t.pointLight=function(e,t,s,i,r,a){return this._assert3d("pointLight"),this._renderer.pointLight(...arguments),this},t.imageLight=function(e){this._renderer.imageLight(e)},t.panorama=function(e){this.filter(this._renderer._getSphereMapping(e))},t.lights=function(){return this._assert3d("lights"),this._renderer.lights(),this},t.lightFalloff=function(e,t,s){return this._assert3d("lightFalloff"),this._renderer.lightFalloff(e,t,s),this},t.spotLight=function(e,t,s,i,r,a,h,n,o,l,u){return this._assert3d("spotLight"),this._renderer.spotLight(...arguments),this},t.noLights=function(){return this._assert3d("noLights"),this._renderer.noLights(),this},Z.prototype.ambientLight=function(e,t,s,i){let r=this._pInst.color(...arguments);this.states.setValue("ambientLightColors",[...this.states.ambientLightColors]),this.states.ambientLightColors.push(r._array[0],r._array[1],r._array[2]),this.states.setValue("enableLighting",!0)},Z.prototype.specularColor=function(e,t,s){let i=this._pInst.color(...arguments);this.states.setValue("specularColors",[i._array[0],i._array[1],i._array[2]])},Z.prototype.directionalLight=function(e,t,s,i,r,h){let n,o,l,u;n=e instanceof a.C?e:this._pInst.color(e,t,s);let d=arguments[arguments.length-1];"number"==typeof d?(o=arguments[arguments.length-3],l=arguments[arguments.length-2],u=arguments[arguments.length-1]):(o=d.x,l=d.y,u=d.z);let c=Math.sqrt(o*o+l*l+u*u);this.states.setValue("directionalLightDirections",[...this.states.directionalLightDirections]),this.states.directionalLightDirections.push(o/c,l/c,u/c),this.states.setValue("directionalLightDiffuseColors",[...this.states.directionalLightDiffuseColors]),this.states.directionalLightDiffuseColors.push(n._array[0],n._array[1],n._array[2]),this.states.setValue("directionalLightSpecularColors",[...this.states.directionalLightSpecularColors]),Array.prototype.push.apply(this.states.directionalLightSpecularColors,this.states.specularColors),this.states.setValue("enableLighting",!0)},Z.prototype.pointLight=function(e,t,s,i,r,h){let n,o,l,u;n=e instanceof a.C?e:this._pInst.color(e,t,s);let d=arguments[arguments.length-1];"number"==typeof d?(o=arguments[arguments.length-3],l=arguments[arguments.length-2],u=arguments[arguments.length-1]):(o=d.x,l=d.y,u=d.z),this.states.setValue("pointLightPositions",[...this.states.pointLightPositions]),this.states.pointLightPositions.push(o,l,u),this.states.setValue("pointLightDiffuseColors",[...this.states.pointLightDiffuseColors]),this.states.pointLightDiffuseColors.push(n._array[0],n._array[1],n._array[2]),this.states.setValue("pointLightSpecularColors",[...this.states.pointLightSpecularColors]),Array.prototype.push.apply(this.states.pointLightSpecularColors,this.states.specularColors),this.states.setValue("enableLighting",!0)},Z.prototype.imageLight=function(e){this.states.setValue("activeImageLight",e),this.states.setValue("enableLighting",!0),this.makeDiffusedTexture(e),this.makeSpecularTexture(e)},Z.prototype.lights=function(){let e=this._pInst.color("rgb(128,128,128)");this.ambientLight(e),this.directionalLight(e,0,0,-1)},Z.prototype.lightFalloff=function(e,t,s){e<0&&(e=0,console.warn("Value of constant argument in lightFalloff() should be never be negative. Set to 0.")),t<0&&(t=0,console.warn("Value of linear argument in lightFalloff() should be never be negative. Set to 0.")),s<0&&(s=0,console.warn("Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.")),0===e&&0===t&&0===s&&(e=1,console.warn("Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.")),this.states.setValue("constantAttenuation",e),this.states.setValue("linearAttenuation",t),this.states.setValue("quadraticAttenuation",s)},Z.prototype.spotLight=function(e,t,s,i,r,h,n,o,l,u,d){let c,p,f;if(this.states.spotLightDiffuseColors.length/3>=4)return;let m=arguments.length;switch(m){case 11:case 10:c=this._pInst.color(e,t,s),p=new C.M(i,r,h),f=new C.M(n,o,l);break;case 9:e instanceof a.C?(c=e,p=new C.M(t,s,i),f=new C.M(r,h,n),u=o,d=l):i instanceof C.M?(c=this._pInst.color(e,t,s),p=i,f=new C.M(r,h,n),u=o,d=l):n instanceof C.M?(c=this._pInst.color(e,t,s),p=new C.M(i,r,h),f=n,u=o,d=l):(c=this._pInst.color(e,t,s),p=new C.M(i,r,h),f=new C.M(n,o,l));break;case 8:e instanceof a.C?(c=e,p=new C.M(t,s,i),f=new C.M(r,h,n)):i instanceof C.M?(c=this._pInst.color(e,t,s),p=i,f=new C.M(r,h,n)):(c=this._pInst.color(e,t,s),p=new C.M(i,r,h),f=n),u=o;break;case 7:e instanceof a.C&&t instanceof C.M?(c=e,p=t,f=new C.M(s,i,r),u=h,d=n):e instanceof a.C&&r instanceof C.M?(c=e,p=new C.M(t,s,i),f=r,u=h,d=n):i instanceof C.M&&r instanceof C.M?(c=this._pInst.color(e,t,s),p=i,f=r,u=h,d=n):e instanceof a.C?(c=e,p=new C.M(t,s,i),f=new C.M(r,h,n)):i instanceof C.M?(c=this._pInst.color(e,t,s),p=i,f=new C.M(r,h,n)):(c=this._pInst.color(e,t,s),p=new C.M(i,r,h),f=n);break;case 6:i instanceof C.M&&r instanceof C.M?(c=this._pInst.color(e,t,s),p=i,f=r,u=h):e instanceof a.C&&r instanceof C.M?(c=e,p=new C.M(t,s,i),f=r,u=h):e instanceof a.C&&t instanceof C.M&&(c=e,p=t,f=new C.M(s,i,r),u=h);break;case 5:e instanceof a.C&&t instanceof C.M&&s instanceof C.M?(c=e,p=t,f=s,u=i,d=r):i instanceof C.M&&r instanceof C.M?(c=this._pInst.color(e,t,s),p=i,f=r):e instanceof a.C&&r instanceof C.M?(c=e,p=new C.M(t,s,i),f=r):e instanceof a.C&&t instanceof C.M&&(c=e,p=t,f=new C.M(s,i,r));break;case 4:c=e,p=t,f=s,u=i;break;case 3:c=e,p=t,f=s;break;default:console.warn(`Sorry, input for spotlight() is not in prescribed format. Too ${m<3?"few":"many"} arguments were provided`);return}this.states.setValue("spotLightDiffuseColors",[...this.states.spotLightDiffuseColors,c._array[0],c._array[1],c._array[2]]),this.states.setValue("spotLightSpecularColors",[...this.states.spotLightSpecularColors,...this.states.specularColors]),this.states.setValue("spotLightPositions",[...this.states.spotLightPositions,p.x,p.y,p.z]),f.normalize(),this.states.setValue("spotLightDirections",[...this.states.spotLightDirections,f.x,f.y,f.z]),void 0===u&&(u=Math.PI/3),void 0!==d&&d<1?(d=1,console.warn("Value of concentration needs to be greater than 1. Setting it to 1")):void 0===d&&(d=100),u=this._pInst._toRadians(u),this.states.setValue("spotLightAngle",[...this.states.spotLightAngle,Math.cos(u)]),this.states.setValue("spotLightConc",[...this.states.spotLightConc,d]),this.states.setValue("enableLighting",!0)},Z.prototype.noLights=function(){this.states.setValue("activeImageLight",null),this.states.setValue("enableLighting",!1),this.states.setValue("ambientLightColors",[]),this.states.setValue("specularColors",[1,1,1]),this.states.setValue("directionalLightDirections",[]),this.states.setValue("directionalLightDiffuseColors",[]),this.states.setValue("directionalLightSpecularColors",[]),this.states.setValue("pointLightPositions",[]),this.states.setValue("pointLightDiffuseColors",[]),this.states.setValue("pointLightSpecularColors",[]),this.states.setValue("spotLightPositions",[]),this.states.setValue("spotLightDirections",[]),this.states.setValue("spotLightDiffuseColors",[]),this.states.setValue("spotLightSpecularColors",[]),this.states.setValue("spotLightAngle",[]),this.states.setValue("spotLightConc",[]),this.states.setValue("constantAttenuation",1),this.states.setValue("linearAttenuation",0),this.states.setValue("quadraticAttenuation",0),this.states.setValue("_useShininess",1),this.states.setValue("_useMetalness",0)}}async function q(e){return Function(await fetch(e).then(e=>e.text()))}function J(e,t){let s=e._runStrandsInGlobalMode;e._runStrandsInGlobalMode=!0;try{return t()}finally{e._runStrandsInGlobalMode=s}}function K(e,t){t.loadShader=async function(e,t,s,i){let r=new k.M;try{if(r._vertSrc=(await R(e,"text")).data,r._fragSrc=(await R(t,"text")).data,s)return s(r)||r;return r}catch(e){if(i)return i(e);throw e}},t.createShader=function(e,t,s){return new k.M(this._renderer,e,t,s)},t.loadFilterShader=async function(e,t,s){try{let s,i=await this.loadStrings(e),r=await i.join("\n");return s=/void\s+main/.exec(r)?this._internal(()=>this.createFilterShader(r,!0)):this._internal(()=>J(this,()=>this.baseFilterShader().modify(Function(r)))),t&&(s=t(s)||s),s}catch(e){s?s(e):console.error(e)}},t.buildFilterShader=function(e,t){return this.baseFilterShader().modify(e,t)},t.createFilterShader=function(e,t=!1){let s=`
3      uniform mat4 uModelViewMatrix;
4      uniform mat4 uProjectionMatrix;
5
6      attribute vec3 aPosition;
7      // texcoords only come from p5 to vertex shader
8      // so pass texcoords on to the fragment shader in a varying variable
9      attribute vec2 aTexCoord;
10      varying vec2 vTexCoord;
11
12      void main() {
13        // transferring texcoords for the frag shader
14        vTexCoord = aTexCoord;
15
16        // copy position with a fourth coordinate for projection (1.0 is normal)
17        vec4 positionVec4 = vec4(aPosition, 1.0);
18
19        // project to 3D space
20        gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
21      }
22    `,i=`#version 300 es
23      uniform mat4 uModelViewMatrix;
24      uniform mat4 uProjectionMatrix;
25
26      in vec3 aPosition;
27      in vec2 aTexCoord;
28      out vec2 vTexCoord;
29
30      void main() {
31        // transferring texcoords for the frag shader
32        vTexCoord = aTexCoord;
33
34        // copy position with a fourth coordinate for projection (1.0 is normal)
35        vec4 positionVec4 = vec4(aPosition, 1.0);
36
37        // project to 3D space
38        gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
39      }
40    `,r=e.includes("#version 300 es")?i:s,a=new k.M(this._renderer,r,e);return t||(this._renderer.GL?a.ensureCompiledOnContext(this._renderer):a.ensureCompiledOnContext(this)),a},t.shader=function(e){return this._assert3d("shader"),this._renderer.shader(e),this},t.strokeShader=function(e){return this._assert3d("strokeShader"),this._renderer.strokeShader(e),this},t.imageShader=function(e){return this._assert3d("imageShader"),this._renderer.imageShader(e),this},t.buildMaterialShader=function(e,t){return this.baseMaterialShader().modify(e,t)},t.loadMaterialShader=async function(e,t,s){try{let s=await q(e),i=this._internal(()=>J(this,()=>this.buildMaterialShader(s)));return t&&(i=t(i)||i),i}catch(e){console.error(e),s&&s(e)}},t.baseMaterialShader=function(){return this._assert3d("baseMaterialShader"),this._renderer.baseMaterialShader()},t.baseFilterShader=function(){return(this._renderer.filterRenderer||this._renderer).baseFilterShader()},t.buildNormalShader=function(e,t){return this.baseNormalShader().modify(e,t)},t.loadNormalShader=async function(e,t,s){try{let s=await q(e),i=this._internal(()=>this.withGlobalStrands(this,()=>this.buildNormalShader(s)));return t&&(i=t(i)||i),i}catch(e){console.error(e),s&&s(e)}},t.baseNormalShader=function(){return this._assert3d("baseNormalShader"),this._renderer.baseNormalShader()},t.buildColorShader=function(e,t){return this.baseColorShader().modify(e,t)},t.loadColorShader=async function(e,t,s){try{let s=await q(e),i=this._internal(()=>J(this,()=>this.buildColorShader(s)));return t&&(i=t(i)||i),i}catch(e){console.error(e),s&&s(e)}},t.baseColorShader=function(){return this._assert3d("baseColorShader"),this._renderer.baseColorShader()},t.buildStrokeShader=function(e,t){return this.baseStrokeShader().modify(e,t)},t.loadStrokeShader=async function(e,t,s){try{let s=await q(e),i=this._internal(()=>J(this,()=>this.buildStrokeShader(s)));return t&&(i=t(i)||i),i}catch(e){console.error(e),s&&s(e)}},t.baseStrokeShader=function(){return this._assert3d("baseStrokeShader"),this._renderer.baseStrokeShader()},t.resetShader=function(){return this._renderer.resetShader(),this},t.texture=function(e){return this._assert3d("texture"),e.gifProperties&&e._animateGif(this),this._renderer.texture(e),this},t.textureMode=function(e){e!==r.ad&&e!==r.a2?console.warn(`You tried to set ${e} textureMode only supports IMAGE & NORMAL `):this._renderer.states.setValue("textureMode",e)},t.textureWrap=function(e,t=e){for(let s of(this._renderer.states.setValue("textureWrapX",e),this._renderer.states.setValue("textureWrapY",t),this._renderer.textures.values()))s.setWrapMode(e,t)},t.normalMaterial=function(...e){return this._assert3d("normalMaterial"),this._renderer.normalMaterial(...e),this},t.ambientMaterial=function(e,s,i){this._assert3d("ambientMaterial");let r=t.color.apply(this,arguments);return this._renderer.states.setValue("_hasSetAmbient",!0),this._renderer.states.setValue("curAmbientColor",r._array),this._renderer.states.setValue("_useNormalMaterial",!1),this._renderer.states.setValue("enableLighting",!0),this._renderer.states.fillColor||this._renderer.states.setValue("fillColor",new a.C([1,1,1])),this},t.emissiveMaterial=function(e,s,i,r){this._assert3d("emissiveMaterial");let a=t.color.apply(this,arguments);return this._renderer.states.setValue("curEmissiveColor",a._array),this._renderer.states.setValue("_useEmissiveMaterial",!0),this._renderer.states.setValue("_useNormalMaterial",!1),this._renderer.states.setValue("enableLighting",!0),this},t.specularMaterial=function(e,s,i,r){this._assert3d("specularMaterial");let a=t.color.apply(this,arguments);return this._renderer.states.setValue("curSpecularColor",a._array),this._renderer.states.setValue("_useSpecularMaterial",!0),this._renderer.states.setValue("_useNormalMaterial",!1),this._renderer.states.setValue("enableLighting",!0),this},t.shininess=function(e){return this._assert3d("shininess"),this._renderer.shininess(e),this},t.metalness=function(e){return this._assert3d("metalness"),this._renderer.metalness(e),this},Z.prototype.shader=function(e){this.states.setValue("userFillShader",e),this.states.setValue("_useNormalMaterial",!1),e.ensureCompiledOnContext(this),e.setDefaultUniforms()},Z.prototype.strokeShader=function(e){this.states.setValue("userStrokeShader",e),e.ensureCompiledOnContext(this),e.setDefaultUniforms()},Z.prototype.imageShader=function(e){this.states.setValue("userImageShader",e),e.ensureCompiledOnContext(this),e.setDefaultUniforms()},Z.prototype.resetShader=function(){this.states.setValue("userFillShader",null),this.states.setValue("userStrokeShader",null),this.states.setValue("userImageShader",null)},Z.prototype.texture=function(e){this.states.setValue("drawMode",r.h),this.states.setValue("_useNormalMaterial",!1),this.states.setValue("_tex",e),this.states.setValue("fillColor",new a.C([1,1,1]))},Z.prototype.normalMaterial=function(){this.states.setValue("drawMode",r.aD),this.states.setValue("_useSpecularMaterial",!1),this.states.setValue("_useEmissiveMaterial",!1),this.states.setValue("_useNormalMaterial",!0),this.states.setValue("curFillColor",[1,1,1,1]),this.states.setValue("fillColor",new a.C([1,1,1])),this.states.setValue("strokeColor",null)},Z.prototype.shininess=function(e){e<1&&(e=1),this.states.setValue("_useShininess",e)},Z.prototype.metalness=function(e){let t=1-Math.exp(-e/100);this.states.setValue("_useMetalness",t)}}"undefined"!=typeof p5&&H(p5,p5.prototype),"undefined"!=typeof p5&&$(p5,p5.prototype),"undefined"!=typeof p5&&W(p5,p5.prototype),"undefined"!=typeof p5&&loading(p5,p5.prototype);class Q{constructor(e,t,s,a,h){let n=s||r.P;return this._pInst=a,this._renderer=new i[n](this,e,t,!1,h),this._initializeInstanceVariables(this),this._renderer._applyDefaults(),this}get elt(){return this.canvas}get deltaTime(){return this._pInst.deltaTime}get canvas(){return this._renderer?.canvas}get drawingContext(){return this._renderer.drawingContext}get width(){return this._renderer?.width}get height(){return this._renderer?.height}get pixels(){return this._renderer?.pixels}pixelDensity(e){let t;return"number"==typeof e?(e!==this._renderer._pixelDensity&&(this._renderer._pixelDensity=e),t=this,this.resizeCanvas(this.width,this.height,!0)):t=this._renderer._pixelDensity,t}resizeCanvas(e,t){this._renderer.resize(e,t)}reset(){this._renderer.resetMatrix(),this._renderer.isP3D&&this._renderer._update()}remove(){this._renderer.remove(),this._renderer=void 0}createFramebuffer(e){return new em(this._renderer,e)}_assert3d(e){if(!this._renderer.isP3D)throw Error(`${e}() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see  https://p5js.org/examples/form-3d-primitives.html for more information.`)}_initializeInstanceVariables(){this._accessibleOutputs={text:!1,grid:!1,textLabel:!1,gridLabel:!1},this._styles=[],this._downKeys={}}}function ee(e,t){e.Graphics=Q,(0,l.A)(e,e.Graphics.prototype),(0,u.A)(e,e.Graphics.prototype),(0,d.A)(e,e.Graphics.prototype),(0,c.A)(e,e.Graphics.prototype),(0,V.Ay)(e,e.Graphics.prototype),(0,p.A)(e,e.Graphics.prototype),G(e,e.Graphics.prototype),B(e,e.Graphics.prototype),(0,x.A)(e,e.Graphics.prototype),(0,w.A)(e,e.Graphics.prototype),$(e,e.Graphics.prototype),W(e,e.Graphics.prototype),K(e,e.Graphics.prototype),(0,a.c)(e,e.Graphics.prototype),(0,U.A)(e,e.Graphics.prototype)}class et{constructor(e,t,s={}){this._renderer=e,this.src=t,this.format=s.format||"rgba8unorm",this.minFilter=s.minFilter||r.g,this.magFilter=s.magFilter||r.g,this.wrapS=s.wrapS||e.states.textureWrapX,this.wrapT=s.wrapT||e.states.textureWrapY,this.dataType=s.dataType||"uint8",this.textureHandle=null,this._detectSourceType();let i=this._getTextureDataFromSource();this.width=i.width,this.height=i.height,this.init(i)}_detectSourceType(){let e=this.src;this.isFramebufferTexture=e instanceof ef,this.isSrcP5Image=e instanceof n.I,this.isSrcP5Graphics=e instanceof Q,this.isSrcP5Renderer=e instanceof n.R,this.isImageData="undefined"!=typeof ImageData&&e instanceof ImageData,this.isSrcMediaElement=void 0!==o.z&&e instanceof o.z,this.isSrcHTMLElement=void 0!==h.H&&e instanceof h.H&&!this.isSrcMediaElement&&!this.isSrcP5Graphics&&!this.isSrcP5Renderer}remove(){this.textureHandle&&(this._renderer.deleteTexture(this.textureHandle),this.textureHandle=null)}_getTextureDataFromSource(){let e;return this.isFramebufferTexture?e=this.src.rawTexture():this.isSrcP5Image?e=this.src.canvas:this.isSrcMediaElement||this.isSrcHTMLElement?this.isSrcMediaElement&&this.src.flipped?(this.src._ensureCanvas(),e=this.src.canvas):(this.src._checkIfTextureNeedsUpdate&&this.src._checkIfTextureNeedsUpdate(),e=this.src.elt):this.isSrcP5Graphics||this.isSrcP5Renderer?e=this.src.canvas:this.isImageData&&(e=this.src),e}init(e){this.isFramebufferTexture?this.textureHandle=this._renderer.createFramebufferTextureHandle(this.src):this.textureHandle=this._renderer.createTexture({format:this.format,dataType:this.dataType,width:e.width,height:e.height}
40),this._renderer.setTextureParams(this,{minFilter:this.minFilter,magFilter:this.magFilter,wrapS:this.wrapS,wrapT:this.wrapT}),this.bindTexture(),this._shouldDeferUpload()?this._renderer.uploadTextureFromData(this.textureHandle,new Uint8Array(1,1,1,1),1,1):this.isFramebufferTexture||this._renderer.uploadTextureFromSource(this.textureHandle,e),this.unbindTexture()}_shouldDeferUpload(){return 0===this.width||0===this.height||this.isSrcMediaElement&&!this.src.loadedmetadata}update(){let e=this._getTextureDataFromSource();if(!e)return!1;let t=!1;return this._shouldUpdate(e)&&(this.bindTexture(),this._renderer.uploadTextureFromSource(this.textureHandle,e),t=!0),t}_shouldUpdate(e){let t=this.src;if(0===t.width||0===t.height)return!1;if(this.isFramebufferTexture)return this.src.update(),!1;let s=!1;return e.width!==this.width||e.height!==this.height?(s=!0,this.width=e.width||t.width,this.height=e.height||t.height,this.isSrcP5Image?t.setModified(!1):(this.isSrcMediaElement||this.isSrcHTMLElement)&&t.setModified&&t.setModified(!0)):this.isSrcP5Image?(t.gifProperties&&t._animateGif(this._renderer._pInst),t.isModified()&&(s=!0,t.setModified(!1))):this.isSrcMediaElement?t.isModified()?(s=!0,t.setModified(!1)):t.loadedmetadata&&this._videoPrevUpdateTime!==t.time()&&(this._videoPrevUpdateTime=t.time(),s=!0):this.isImageData?t._dirty&&(t._dirty=!1,s=!0):s=!0,s}bindTexture(){return this._renderer.bindTexture(this),this}unbindTexture(){this._renderer.unbindTexture()}getTexture(){return this.isFramebufferTexture?this.src.rawTexture():this.textureHandle}getSampler(){return this._renderer.getSampler(this)}setInterpolation(e,t){this.minFilter=e,this.magFilter=t,this._renderer.setTextureParams(this)}setWrapMode(e,t){this.wrapS=e,this.wrapT=t,this._renderer.setTextureParams(this)}}class es extends et{constructor(e,t,s={}){super(e,t,{minFilter:r.g,magFilter:r.g,...s}),this.levels=t}_getTextureDataFromSource(){return this.src}init(e){if(Array.isArray(e)){let t=e[0];this.width=t.width,this.height=t.height,this.textureHandle=this._renderer.createMipmapTextureHandle({levels:e,format:this.format,dataType:this.dataType,width:this.width,height:this.height})}else this.width=e.size,this.height=e.size,this.textureHandle=this._renderer.createMipmapTextureHandle({gpuTexture:e.gpuTexture,format:e.format,dataType:"uint8",width:this.width,height:this.height});this._renderer.setTextureParams(this,{minFilter:this.minFilter,magFilter:this.magFilter,wrapS:this.wrapS,wrapT:this.wrapT})}update(){}}function ei(e,t){e.Texture=et,e.MipmapTexture=es}function er(e,t,s,i,r,a,h,n,o,l){let u=t.getParameter(t.FRAMEBUFFER_BINDING);t.bindFramebuffer(t.FRAMEBUFFER,s);let d=n===t.RGBA?4:3,c=a*h*d,p=o===t.UNSIGNED_BYTE?Uint8Array:Float32Array;if(e instanceof p&&e.length===c||(e=new p(c)),t.readPixels(i,l?l-r-h:r,a,h,n,o,e),t.bindFramebuffer(t.FRAMEBUFFER,u),l){let t=Math.floor(h/2),s=new p(a*d);for(let i=0;i<t;i++){let t=i*a*4,r=(h-i-1)*a*4;s.set(e.subarray(t,t+4*a)),e.copyWithin(t,r,r+4*a),e.set(s,r)}}return e}function ea(e,t,s,i,r,a,h){let n=e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.FRAMEBUFFER,t);let o=r===e.RGBA?4:3,l=new(a===e.UNSIGNED_BYTE?Uint8Array:Float32Array)(o);return e.readPixels(s,h?h-i-1:i,1,1,r,a,l),e.bindFramebuffer(e.FRAMEBUFFER,n),Array.from(l)}function eh(e,t,s){let i,a,h,n;e.bindTexture();let o=e.minFilter===r.N?t.NEAREST:e.minFilter===r.aG?t.LINEAR_MIPMAP_LINEAR:t.LINEAR,l=e.magFilter===r.N?t.NEAREST:t.LINEAR,u=e=>(e&e-1)==0,d=e._getTextureDataFromSource();d.naturalWidth&&d.naturalHeight?(i=d.naturalWidth,a=d.naturalHeight):(i=e.width,a=e.height);let c=u(i),p=u(a);e.wrapS===r.f?s===r.aa||c&&p?h=t.REPEAT:(console.warn("You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead"),h=t.CLAMP_TO_EDGE):e.wrapS===r.e?s===r.aa||c&&p?h=t.MIRRORED_REPEAT:(console.warn("You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead"),h=t.CLAMP_TO_EDGE):h=t.CLAMP_TO_EDGE,e.wrapT===r.f?s===r.aa||c&&p?n=t.REPEAT:(console.warn("You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead"),n=t.CLAMP_TO_EDGE):e.wrapT===r.e?s===r.aa||c&&p?n=t.MIRRORED_REPEAT:(console.warn("You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead"),n=t.CLAMP_TO_EDGE):n=t.CLAMP_TO_EDGE,t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,l),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,h),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,n),e.unbindTexture()}function en(e,t,s,i,r){let a=t.location;switch(e.useProgram(),t.type){case r.BOOL:!0===s?r.uniform1i(a,1):r.uniform1i(a,0);break;case r.INT:t.size>1?s.length&&r.uniform1iv(a,s):r.uniform1i(a,s);break;case r.FLOAT:t.size>1?s.length&&r.uniform1fv(a,s):r.uniform1f(a,s);break;case r.FLOAT_MAT3:r.uniformMatrix3fv(a,!1,s);break;case r.FLOAT_MAT4:r.uniformMatrix4fv(a,!1,s);break;case r.FLOAT_VEC2:t.size>1?s.length&&r.uniform2fv(a,s):r.uniform2f(a,s[0],s[1]);break;case r.FLOAT_VEC3:t.size>1?s.length&&r.uniform3fv(a,s):r.uniform3f(a,s[0],s[1],s[2]);break;case r.FLOAT_VEC4:t.size>1?s.length&&r.uniform4fv(a,s):r.uniform4f(a,s[0],s[1],s[2],s[3]);break;case r.INT_VEC2:t.size>1?s.length&&r.uniform2iv(a,s):r.uniform2i(a,s[0],s[1]);break;case r.INT_VEC3:t.size>1?s.length&&r.uniform3iv(a,s):r.uniform3i(a,s[0],s[1],s[2]);break;case r.INT_VEC4:t.size>1?s.length&&r.uniform4iv(a,s):r.uniform4i(a,s[0],s[1],s[2],s[3]);break;case r.SAMPLER_2D:if("number"==typeof s){if(s<r.TEXTURE0||s>r.TEXTURE31||s!==Math.ceil(s))return void console.log("\uD83C\uDF38 p5.js says: You're trying to use a number as the data for a texture.Please use a texture.");r.activeTexture(s),r.uniform1i(a,s)}else r.activeTexture(r.TEXTURE0+t.samplerIndex),t.texture=s instanceof et?s:i(s),r.uniform1i(a,t.samplerIndex);break;case r.SAMPLER_CUBE:case r.SAMPLER_3D:case r.SAMPLER_2D_SHADOW:case r.SAMPLER_2D_ARRAY:case r.SAMPLER_2D_ARRAY_SHADOW:case r.SAMPLER_CUBE_SHADOW:case r.INT_SAMPLER_2D:case r.INT_SAMPLER_3D:case r.INT_SAMPLER_CUBE:case r.INT_SAMPLER_2D_ARRAY:case r.UNSIGNED_INT_SAMPLER_2D:case r.UNSIGNED_INT_SAMPLER_3D:case r.UNSIGNED_INT_SAMPLER_CUBE:case r.UNSIGNED_INT_SAMPLER_2D_ARRAY:if("number"!=typeof s)break;if(s<r.TEXTURE0||s>r.TEXTURE31||s!==Math.ceil(s)){console.log("\uD83C\uDF38 p5.js says: You're trying to use a number as the data for a texture.Please use a texture.");break}r.activeTexture(s),r.uniform1i(a,s)}}function eo(e,t){let s=e._glProgram,i=t.getProgramParameter(s,t.ACTIVE_UNIFORMS),r=[],a=0;for(let e=0;e<i;++e){let i=t.getActiveUniform(s,e),h={};h.location=t.getUniformLocation(s,i.name),h.size=i.size;let n=i.name;i.size>1&&(n=n.substring(0,n.indexOf("[0]"))),h.name=n,h.type=i.type,h._cachedData=void 0,h.type===t.SAMPLER_2D&&(h.isSampler=!0,h.samplerIndex=a,a++),h.isArray=i.size>
401||h.type===t.FLOAT_MAT3||h.type===t.FLOAT_MAT4||h.type===t.FLOAT_VEC2||h.type===t.FLOAT_VEC3||h.type===t.FLOAT_VEC4||h.type===t.INT_VEC2||h.type===t.INT_VEC4||h.type===t.INT_VEC3,r.push(h)}return r}function el(e,t){let s={},i=t.getProgramParameter(e._glProgram,t.ACTIVE_ATTRIBUTES);for(let r=0;r<i;++r){let i=t.getActiveAttrib(e._glProgram,r),a=i.name,h=t.getAttribLocation(e._glProgram,a),n={};n.name=a,n.location=h,n.index=r,n.type=i.type,n.size=i.size,s[a]=n}return s}function eu(e,t,s){let i="void main";if(!t.includes(i))return t;let[r,a]=t.split(i),h="",n="";for(let t in e.hooks.uniforms)h+=`uniform ${t};
41`;if(e.hooks.declarations&&(h+=e.hooks.declarations+"\n"),e.hooks[s].declarations&&(h+=e.hooks[s].declarations+"\n"),e.hooks.varyingVariables&&e.hooks.varyingVariables.length>0)for(let t of e.hooks.varyingVariables)"vertex"===s?h+=`OUT ${t};
42`:"fragment"===s&&(h+=`IN ${t};
43`);for(let t in e.hooks.helpers)h+=`${t}${e.hooks.helpers[t]}
44`;for(let t in e.hooks[s]){if("declarations"===t)continue;let[i,r]=t.split(" ");(e.hooks.modified.vertex[t]||e.hooks.modified.fragment[t])&&(n+="#define AUGMENTED_HOOK_"+r+"\n"),h+=i+" HOOK_"+r+e.hooks[s][t]+"\n"}return -1!==r.indexOf("#define HOOK_DEFINES")&&(r=r.replace("#define HOOK_DEFINES","\n"+n+"\n"),n=""),r+"\n"+n+h+i+a}function ed({GL:e,webglVersion:t}){let s=t===r.aa?e.getExtension("EXT_color_buffer_float")&&e.getExtension("EXT_float_blend"):e.getExtension("OES_texture_float"),i=s&&e.getExtension("OES_texture_float_linear"),a=t===r.aa?e.getExtension("EXT_color_buffer_float"):e.getExtension("OES_texture_half_float"),h=a&&e.getExtension("OES_texture_half_float_linear");return{float:s,floatLinear:i,halfFloat:a,halfFloatLinear:h}}"undefined"!=typeof p5&&ei(p5,p5.prototype);let ec=(e,t,s)=>Math.max(Math.min(e,s),t);class ep extends O{constructor(e){super(e.renderer),this.fbo=e,this.yScale=e.renderer.framebufferYScale()}_computeCameraDefaultSettings(){super._computeCameraDefaultSettings(),this.defaultAspectRatio=this.fbo.width/this.fbo.height,this.defaultCameraFOV=2*Math.atan(this.fbo.height/2/this.defaultEyeZ)}copy(){let e=super.copy();return e.fbo=this.fbo,e}}class ef{constructor(e,t){this.framebuffer=e,this.property=t}get width(){return this.framebuffer.width*this.framebuffer.density}get height(){return this.framebuffer.height*this.framebuffer.density}update(){this.framebuffer._update(this.property)}rawTexture(){return{texture:this.framebuffer[this.property]}}}class em{constructor(e,t={}){if(this.renderer=e,this.renderer.framebuffers.add(this),this._isClipApplied=!1,this._useCanvasFormat=t._useCanvasFormat||!1,this.dirty={colorTexture:!1,depthTexture:!1},this.pixels=[],this.format=t.format||r.U,this.channels=t.channels||(this.renderer.defaultFramebufferAlpha()?a.h:a.R),this.useDepth=void 0===t.depth||t.depth,this.depthFormat=t.depthFormat||r.F,this.textureFiltering=t.textureFiltering||r.g,void 0===t.antialias?this.antialiasSamples=2*!!this.renderer.defaultFramebufferAntialias():"number"==typeof t.antialias?this.antialiasSamples=t.antialias:this.antialiasSamples=2*!!t.antialias,this.antialias=this.antialiasSamples>0,this.antialias&&!this.renderer.supportsFramebufferAntialias()&&(console.warn("Framebuffer antialiasing is unsupported in this context"),this.antialias=!1),this.density=t.density||this.renderer._pixelDensity,t.width&&t.height){let e=this.renderer._adjustDimensions(t.width,t.height);this.width=e.adjustedWidth,this.height=e.adjustedHeight,this._autoSized=!1}else void 0===t.width!=(void 0===t.height)&&console.warn("Please supply both width and height for a framebuffer to give it a size. Only one was given, so the framebuffer will match the size of its canvas."),this.width=this.renderer.width,this.height=this.renderer.height,this._autoSized=!0;this.renderer.validateFramebufferFormats(this),t.stencil&&!this.useDepth&&console.warn("A stencil buffer can only be used if also using depth. Since the framebuffer has no depth buffer, the stencil buffer will be ignored."),this.useStencil=this.useDepth&&(void 0===t.stencil||t.stencil),this.renderer.createFramebufferResources(this),this._recreateTextures(),this.defaultCamera=this.createCamera(),this.filterCamera=this.createCamera(),this.draw(()=>this.renderer.clear())}resize(e,t){this._autoSized=!1;let s=this.renderer._adjustDimensions(e,t);e=s.adjustedWidth,t=s.adjustedHeight,this.width=e,this.height=t,this._handleResize()}pixelDensity(e){if(!e)return this.density;this._autoSized=!1,this.density=e,this._handleResize()}autoSized(e){if(void 0===e)return this._autoSized;this._autoSized=e,this._handleResize()}_checkIfFormatsAvailable(){let e=this.gl;this.useDepth&&this.renderer.webglVersion===r.ac&&!e.getExtension("WEBGL_depth_texture")&&(console.warn("Unable to create depth textures in this environment. Falling back to a framebuffer without depth."),this.useDepth=!1),this.useDepth&&this.renderer.webglVersion===r.ac&&this.depthFormat===r.F&&(console.warn("FLOAT depth format is unavailable in WebGL 1. Defaulting to UNSIGNED_INT."),this.depthFormat=r.d),[r.U,r.F,r.H].includes(this.format)||(console.warn("Unknown Framebuffer format. Please use UNSIGNED_BYTE, FLOAT, or HALF_FLOAT. Defaulting to UNSIGNED_BYTE."),this.format=r.U),this.useDepth&&![r.d,r.F].includes(this.depthFormat)&&(console.warn("Unknown Framebuffer depth format. Please use UNSIGNED_INT or FLOAT. Defaulting to FLOAT."),this.depthFormat=r.F);let t=ed(this.renderer);t.float||this.format!==r.F||(console.warn("This environment does not support FLOAT textures. Falling back to UNSIGNED_BYTE."),this.format=r.U),this.useDepth&&!t.float&&this.depthFormat===r.F&&(console.warn("This environment does not support FLOAT depth textures. Falling back to UNSIGNED_INT."),this.depthFormat=r.d),t.halfFloat||this.format!==r.H||(console.warn("This environment does not support HALF_FLOAT textures. Falling back to UNSIGNED_BYTE."),this.format=r.U),this.channels===a.R&&[r.F,r.H].includes(this.format)&&(console.warn("FLOAT and HALF_FLOAT formats do not work cross-platform with only RGB channels. Falling back to RGBA."),this.channels=a.h)}_deleteTextures(){this.renderer.deleteFramebufferTextures(this)}_recreateTextures(){if(this._updateSize(),this.renderer.recreateFramebufferTextures(this),this.useDepth){this.depth=new ef(this,"depthTexture");let e=r.N;this.depthP5Texture=new et(this.renderer,this.depth,{minFilter:e,magFilter:e}),this.renderer.textures.set(this.depth,this.depthP5Texture)}this.color=new ef(this,"colorTexture");let e=this.textureFiltering===r.g?r.g:r.N;this.colorP5Texture=new et(this.renderer,this.color,{minFilter:e,magFilter:e}),this.renderer.textures.set(this.color,this.colorP5Texture)}_updateSize(){this._autoSized&&(this.width=this.renderer.width,this.height=this.renderer.height,this.density=this.renderer._pixelDensity)}_canvasSizeChanged(){this._autoSized&&this._handleResize()}_handleResize(){this._deleteTextures(),this._recreateTextures(),this.defaultCamera._resize()}createCamera(){let e=new ep(this);return e._computeCameraDefaultSettings(),e._setDefaultCamera(),e}remove(){this._deleteTextures(),this.renderer.deleteFramebufferResources(this),this.renderer.framebuffers.delete(this)}begin(){this.prevFramebuffer=this.renderer.activeFramebuffer(),this.prevFramebuffer&&this.prevFramebuffer._beforeEnd(),this.renderer.activeFramebuffers.push(this),this._beforeBegin(),this.renderer.push(),this.renderer.states.setValue("curCamera",this.defaultCamera),this.renderer.states.setValue("uPMatrix",this.renderer.states.uPMatrix.clone()),this.renderer.states.uPMatrix.set(this.defaultCamera.projMatrix),this.renderer.states.setValue("uViewMatrix",this.renderer.states.uViewM
44atrix.clone()),this.renderer.states.uViewMatrix.set(this.defaultCamera.cameraMatrix),this.renderer.resetMatrix(),this.renderer.states.uViewMatrix.set(this.renderer.states.curCamera.cameraMatrix),this.renderer.states.uModelMatrix.reset(),this.renderer._applyStencilTestIfClipping()}_framebufferToBind(){return this.renderer.getFramebufferToBind(this)}_update(e){this.dirty[e]&&(this.renderer.updateFramebufferTexture(this,e),this.dirty[e]=!1)}_beforeBegin(){this.renderer.bindFramebuffer(this),this.renderer.viewport(this.width*this.density,this.height*this.density),this.renderer.flushDraw&&this.renderer.flushDraw()}_beforeEnd(){this.antialias&&(this.dirty={colorTexture:!0,depthTexture:!0}),this.renderer.flushDraw&&this.renderer.flushDraw()}end(){if(this.renderer.pop(),this.renderer.activeFramebuffers.pop()!==this)throw Error("It looks like you've called end() while another Framebuffer is active.");this._beforeEnd(),this.prevFramebuffer?this.prevFramebuffer._beforeBegin():(this.renderer.bindFramebuffer(null),this.renderer.viewport(this.renderer._origViewport.width,this.renderer._origViewport.height)),this.renderer._applyStencilTestIfClipping()}draw(e){this.begin(),e(),this.end()}loadPixels(){this._update("colorTexture");let e=this.renderer.readFramebufferPixels(this);return e&&"function"==typeof e.then?e.then(e=>(this.pixels=e,e)):(this.pixels=e,e)}get(e,t,s,i){if(this._update("colorTexture"),void 0===e&&void 0===t)e=0,t=0,s=this.width,i=this.height;else if(void 0===s&&void 0===i)return(e<0||t<0||e>=this.width||t>=this.height)&&(console.warn("The x and y values passed to p5.Framebuffer.get are outside of its range and will be clamped."),e=ec(e,0,this.width-1),t=ec(t,0,this.height-1)),this.renderer.readFramebufferPixel(this,e*this.density,t*this.density);return e=ec(e,0,this.width-1),t=ec(t,0,this.height-1),s=ec(s,1,this.width-e),i=ec(i,1,this.height-t),this.renderer.readFramebufferRegion(this,e,t,s,i)}updatePixels(){this.renderer.updateFramebufferPixels(this)}}function eg(e,t){e.FramebufferCamera=ep,e.FramebufferTexture=ef,e.Framebuffer=em}function e_(e,t){e.renderers||(e.renderers={}),i=e.renderers,t.createCanvas=function(e,t,s,...a){let h=r.P;return(Reflect.ownKeys(i).includes(s)?h=s:a.unshift(s),this._renderer&&this._renderer.remove(),this._renderer=new i[h](this,e,t,!0,...a),this._defaultGraphicsCreated=!0,this._elements.push(this._renderer),this._renderer._applyDefaults(),Object.hasOwn(this,"pixels")||Object.defineProperty(this,"pixels",{get(){return this._renderer?.pixels}}),this._renderer.contextReady)?this._renderer.contextReady.then(()=>this._renderer):this._renderer},t.resizeCanvas=function(e,t,s){this._renderer&&(this._renderer.resize(e,t),s||this.redraw()),this._addAccsOutput()&&this._updateAccsOutput()},t.noCanvas=function(){this.canvas&&this.canvas.parentNode.removeChild(this.canvas)},t.createGraphics=function(t,s,...i){return i[0]instanceof HTMLCanvasElement&&(i[1]=i[0],i[0]=r.P),new e.Graphics(t,s,i[0],this,i[1])},t.createFramebuffer=function(e){return new em(this._renderer,e)},t.clearDepth=function(e){this._assert3d("clearDepth"),this._renderer.clearDepth(e)}}"undefined"!=typeof p5&&eg(p5,p5.prototype),"undefined"!=typeof p5&&e_(p5,p5.prototype)}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.