bridgy-fed/static/q5.min.js

8 wiersze
41 KiB
JavaScript

/**
* q5.js
* @version 1.8
* @author quinton-ashley and LingDong-
* @license GPL-3.0-only
*/
function Q5(e,t){let a=0;if(void 0===e&&(e="global",a++,setTimeout((()=>a--),32)),"auto"==e){if(void 0===window.setup)return;e="global"}1==arguments.length&&"string"!=typeof e&&"function"!=typeof e&&(t=arguments[0],e=null),"global"==e&&(Q5._hasGlobal=!0);let n=this;n.canvas=document.createElement("canvas");let o=n._ctx=n.canvas.getContext("2d");if(n.canvas.classList.add("p5Canvas","q5Canvas"),n.canvas.id="defaultCanvas"+Q5._instanceCount++,n.width=100,n.height=100,n.canvas.width=n.width,n.canvas.height=n.height,n._windowResizedFn=()=>{},"graphics"!=e&&"image"!=e){function i(){t??=document.getElementsByTagName("main")[0],t||(t=document.createElement("main"),document.body.append(t)),n.canvas.parent(t)}n._setupDone=!1,n._resize=()=>{n.frameCount>1&&(n._shouldResize=!0)},n.canvas.parent=e=>{"string"==typeof e&&(e=document.getElementById(e)),e.append(n.canvas),"undefined"!=typeof ResizeObserver?(n._ro&&n._ro.disconnect(),n._ro=new ResizeObserver(n._resize),n._ro.observe(t)):0==n.frameCount&&addEventListener("resize",n._resize)},document.body?i():window.addEventListener("load",i)}M(),n.MAGIC=161533525,n.pixels=[];let r=null;n.createCanvas=function(t,a){if(n.width=t,n.height=a,n.canvas.width=t,n.canvas.height=a,M(),"image"!=e){let t=n.displayDensity();"graphics"==e&&(t=this._pixelDensity),n.pixelDensity(Math.ceil(t))}else this._pixelDensity=1;return n.canvas},n._createCanvas=n.createCanvas,n.loadPixels=()=>{r=o.getImageData(0,0,n.canvas.width,n.canvas.height),n.pixels=r.data},n.updatePixels=()=>{null!=r&&o.putImageData(r,0,0)};let s={};function l(e,t){null==p&&(p=document.createElement("canvas").getContext("2d")),t??=e||o.canvas.height,e??=o.canvas.width,p.canvas.width==e&&p.canvas.height==t||(p.canvas.width=e,p.canvas.height=t)}function h(){let e=o.canvas.width*o.canvas.height*4;v&&e==v.length||(v=new Uint8ClampedArray(e))}function c(e){p.clearRect(0,0,p.canvas.width,p.canvas.height),p.filter=e,p.drawImage(o.canvas,0,0),o.save(),o.resetTransform(),o.clearRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(p.canvas,0,0),o.restore()}s[n.THRESHOLD]=(e,t)=>{void 0===t?t=127.5:t*=255;for(let a=0;a<e.length;a+=4){const n=.2126*e[a]+.7152*e[a+1]+.0722*e[a+2];e[a]=e[a+1]=e[a+2]=n>=t?255:0}},s[n.GRAY]=e=>{for(let t=0;t<e.length;t+=4){const a=.2126*e[t]+.7152*e[t+1]+.0722*e[t+2];e[t]=e[t+1]=e[t+2]=a}},s[n.OPAQUE]=e=>{for(let t=0;t<e.length;t+=4)e[t+3]=255},s[n.INVERT]=e=>{for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},s[n.POSTERIZE]=(e,t)=>{let a=t-1;for(let n=0;n<e.length;n+=4)e[n]=255*(e[n]*t>>8)/a,e[n+1]=255*(e[n+1]*t>>8)/a,e[n+2]=255*(e[n+2]*t>>8)/a},s[n.DILATE]=e=>{h(),v.set(e);let[t,a]=[o.canvas.width,o.canvas.height];for(let n=0;n<a;n++)for(let o=0;o<t;o++){let i=4*Math.max(o-1,0),r=4*Math.min(o+1,t-1),s=4*Math.max(n-1,0)*t,l=4*Math.min(n+1,a-1)*t,h=4*n*t,c=4*o;for(let t=0;t<4;t++){let a=t+s,n=t+l,o=t+h;e[h+c+t]=Math.max(v[a+c],v[o+i],v[o+c],v[o+r],v[n+c])}}},s[n.ERODE]=e=>{h(),v.set(e);let[t,a]=[o.canvas.width,o.canvas.height];for(let n=0;n<a;n++)for(let o=0;o<t;o++){let i=4*Math.max(o-1,0),r=4*Math.min(o+1,t-1),s=4*Math.max(n-1,0)*t,l=4*Math.min(n+1,a-1)*t,h=4*n*t,c=4*o;for(let t=0;t<4;t++){let a=t+s,n=t+l,o=t+h;e[h+c+t]=Math.min(v[a+c],v[o+i],v[o+c],v[o+r],v[n+c])}}},s[n.BLUR]=(e,t)=>{t=t||1,t=Math.floor(t*n._pixelDensity),h(),v.set(e);let a=2*t+1;let i=function(e){let a=new Float32Array(e),n=.3*t+.8,o=n*n*2;for(let t=0;t<e;t++){let i=t-e/2,r=Math.exp(-i*i/o)/(2.5066282746*n);a[t]=r}return a}(a),[r,s]=[o.canvas.width,o.canvas.height];for(let n=0;n<s;n++)for(let o=0;o<r;o++){let s=0,l=0,h=0,c=0;for(let e=0;e<a;e++){let a=4*(n*r+Math.min(Math.max(o-t+e,0),r-1));s+=v[a]*i[e],l+=v[a+1]*i[e],h+=v[a+2]*i[e],c+=v[a+3]*i[e]}let d=4*(n*r+o);e[d]=s,e[d+1]=l,e[d+2]=h,e[d+3]=c}v.set(e);for(let n=0;n<s;n++)for(let o=0;o<r;o++){let l=0,h=0,c=0,d=0;for(let e=0;e<a;e++){let a=4*(Math.min(Math.max(n-t+e,0),s-1)*r+o);l+=v[a]*i[e],h+=v[a+1]*i[e],c+=v[a+2]*i[e],d+=v[a+3]*i[e]}let u=4*(n*r+o);e[u]=l,e[u+1]=h,e[u+2]=c,e[u+3]=d}},n.filter=(e,t)=>{if(n.HARDWARE_FILTERS&&null!=o.filter)if(l(),e==n.THRESHOLD){t??=.5,t=Math.max(t,1e-5),c(`saturate(0%) brightness(${Math.floor(.5/t*100)}%) contrast(1000000%)`)}else if(e==n.GRAY)c("saturate(0%)");else if(e==n.OPAQUE)p.fillStyle="black",p.fillRect(0,0,p.canvas.width,p.canvas.height),p.drawImage(o.canvas,0,0),o.save(),o.resetTransform(),o.drawImage(p.canvas,0,0),o.restore();else if(e==n.INVERT)c("invert(100%)");else if(e==n.BLUR)c(`blur(${Math.ceil(t*n._pixelDensity/1)||1}px)`);else{let a=o.getImageData(0,0,o.canvas.width,o.canvas.height);s[e](a.data,t),o.putImageData(a,0,0)}else{let a=o.getImageData(0,0,o.canvas.width,o.canvas.height);s[e](a.data,t),o.putImageData(a,0,0)}},n.resize=(e,t)=>{l(),p.drawImage(o.canvas,0,0),n.width=e,n.height=t,o.canvas.width=e*n._pixelDensity,o.canvas.height=t*n._pixelDensity,o.save(),o.resetTransform(),o.clearRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(p.canvas,0,0,o.canvas.width,o.canvas.height),o.restore()},n.get=(e,t,a,i)=>{let r=n._pixelDensity||1;if(void 0!==e&&void 0===a){let a=o.getImageData(e*r,t*r,1,1).data;return new Q5.Color(a[0],a[1],a[2],a[3]/255)}e=(e||0)*r,t=(t||0)*r,a=(a||n.width)*r,i=(i||n.height)*r;let s=n.createImage(a,i),l=o.getImageData(e,t,a,i);return s.canvas.getContext("2d").putImageData(l,0,0),s},n.set=(e,t,a)=>{if(a.MAGIC==n.MAGIC){let o=n._tint;return n._tint=null,n.image(a,e,t),void(n._tint=o)}let i=n._pixelDensity||1;for(let r=0;r<i;r++)for(let s=0;s<i;s++){let l=4*((t*i+r)*o.canvas.width+e*i+s);n.pixels[l]=a._r,n.pixels[l+1]=a._g,n.pixels[l+2]=a._b,n.pixels[l+3]=255*a._a}},n.tinted=function(e){let t=e._a;e._a=1,l(),p.clearRect(0,0,p.canvas.width,p.canvas.height),p.fillStyle=e,p.fillRect(0,0,p.canvas.width,p.canvas.height),p.globalCompositeOperation="multiply",p.drawImage(o.canvas,0,0),p.globalCompositeOperation="source-over",o.save(),o.resetTransform();let a=o.globalCompositeOperation;o.globalCompositeOperation="source-in",o.drawImage(p.canvas,0,0),o.globalCompositeOperation=a,o.restore(),p.globalAlpha=t,p.clearRect(0,0,p.canvas.width,p.canvas.height),p.drawImage(o.canvas,0,0),p.globalAlpha=1,o.save(),o.resetTransform(),o.clearRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(p.canvas,0,0),o.restore()},n.tint=function(){n._tint=n.color(...Array.from(arguments))},n.noTint=()=>n._tint=null,n.mask=e=>{o.save(),o.resetTransform();let t=o.globalCompositeOperation;o.globalCompositeOperation="destination-in",o.drawImage(e.canvas,0,0),o.globalCompositeOperation=t,o.restore()},n._save=(e,t,a)=>{if(t=t||"untitled","jpg"==(a=a||"png")||"png"==a)e=e.toDataURL();else{let t="text/plain";"json"==a&&("string"!=typeof e&&(e=JSON.stringify(e)),t="text/json"),e=new Blob([e],{type:t}),e=URL.createObjectURL(e)}let n=document.createElement("a");n.href=e,n.download=t+"."+a,document.body.append(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(n.href)},n.save=(e,t,a)=>{if((!e||"string"==typeof e&&(!t||!a&&t.length<5))&&(a=t,t=e,e=o.canvas),a)return n._save(e,t,a);t?(t=t.split("."),n._save(e,t[0],t.at(-1))):n._save(e)},n.canvas.save=n.save,n.saveCanvas=n.save;let d=null,u=!0,_=[],g={},m=0,p=null,f=null,v=null;if("image"==e)return;function x(){let e={};for(let t in o)"function"!=typeof o[t]&&(e[t]=o[t]);return delete e.canvas,e}n.remove=()=>{n.noLoop(),n.canvas.remove()},n.RGB=0,n.HSV=1,n.HSB=1,n.CHORD=0,n.PIE=1,n.OPEN=2,n.RADIUS="radius",n.CORNER="corner",n.CORNERS="corners",n.ROUND="round",n.SQUARE="butt",n.PROJECT="square",n.MITER="miter",n.BEVEL="bevel",n.CLOSE=1,n.BLEND="source-over",n.REMOVE="destination-out",n.ADD="lighter",n.DARKEST="darken",n.LIGHTEST="lighten",n.DIFFERENCE="difference",n.SUBTRACT="subtract",n.EXCLUSION="exclusion",n.MULTIPLY="multiply",n.SCREEN="screen",n.REPLACE="copy",n.OVERLAY="overlay",n.HARD_LIGHT="hard-light",n.SOFT_LIGHT="soft-light",n.DODGE="color-dodge",n.BURN="color-burn",n.NORMAL="normal",n.ITALIC="italic",n.BOLD="bold",n.BOLDITALIC="italic bold",n.CENTER="center",n.LEFT="left",n.RIGHT="right",n.TOP="top",n.BOTTOM="bottom",n.BASELINE="alphabetic",n.LANDSCAPE="landscape",n.PORTRAIT="portrait",n.ALT=18,n.BACKSPACE=8,n.CONTROL=17,n.DELETE=46,n.DOWN_ARROW=40,n.ENTER=13,n.ESCAPE=27,n.LEFT_ARROW=37,n.OPTION=18,n.RETURN=13,n.RIGHT_ARROW=39,n.SHIFT=16,n.TAB=9,n.UP_ARROW=38,n.DEGREES="degrees",n.RADIANS="radians",n.HALF_PI=Math.PI/2,n.PI=Math.PI,n.QUARTER_PI=Math.PI/4,n.TAU=2*Math.PI,n.TWO_PI=2*Math.PI,n.THRESHOLD=1,n.GRAY=2,n.OPAQUE=3,n.INVERT=4,n.POSTERIZE=5,n.DILATE=6,n.ERODE=7,n.BLUR=8,n.ARROW="default",n.CROSS="crosshair",n.HAND="pointer",n.MOVE="move",n.TEXT="text",n.VIDEO={video:!0,audio:!1},n.AUDIO={video:!1,audio:!0},n.SHR3=1,n.LCG=2,n.HARDWARE_FILTERS=!0,n.hint=(e,t)=>{n[e]=t},n.frameCount=0,n.deltaTime=16,n.mouseX=0,n.mouseY=0,n.mouseButton=null,n.keyIsPressed=!1,n.mouseIsPressed=!1,n.key=null,n.keyCode=null,n.accelerationX=0,n.accelerationY=0,n.accelerationZ=0,n.rotationX=0,n.rotationY=0,n.rotationZ=0,n.relRotationX=0,n.relRotationY=0,n.relRotationZ=0,n.pmouseX=0,n.pmouseY=0,n.pAccelerationX=0,n.pAccelerationY=0,n.pAccelerationZ=0,n.pRotationX=0,n.pRotationY=0,n.pRotationZ=0,n.pRelRotationX=0,n.pRelRotationY=0,n.pRelRotationZ=0,n.touches=[],n._colorMode=n.RGB,n._doStroke=!0,n._doFill=!0,n._strokeSet=!1,n._fillSet=!1,n._ellipseMode=n.CENTER,n._rectMode=n.CORNER,n._curveDetail=20,n._curveAlpha=0,n._loop=!0,n._textFont="sans-serif",n._textSize=12,n._textLeading=15,n._textLeadDiff=3,n._textStyle="normal",n._pixelDensity=1,n._lastFrameTime=0,n._targetFrameRate=null,n._frameRate=n._fps=60,n._tint=null,Object.defineProperty(n,"deviceOrientation",{get:()=>window.screen?.orientation?.type}),Object.defineProperty(n,"windowWidth",{get:()=>window.innerWidth}),Object.defineProperty(n,"windowHeight",{get:()=>window.innerHeight}),Object.defineProperty(n,"drawingContext",{get:()=>o}),n.resizeCanvas=(t,a)=>{n.width=t,n.height=a;let i=x();n.canvas.width=t*n._pixelDensity,n.canvas.height=a*n._pixelDensity,o=n._ctx=n.canvas.getContext("2d");for(let e in i)n._ctx[e]=i[e];"image"!=e&&n.pixelDensity(n._pixelDensity)},n.createGraphics=function(e,t){let a=new Q5("graphics");return a._createCanvas.call(n,e,t),a},n.createImage=(e,t)=>new Q5.Image(e,t),n.displayDensity=()=>window.devicePixelRatio,n.pixelDensity=e=>{if(void 0===e)return n._pixelDensity;n._pixelDensity=e;let t=x();n.canvas.width=Math.ceil(n.width*e),n.canvas.height=Math.ceil(n.height*e),n.canvas.style.width=n.width+"px",n.canvas.style.height=n.height+"px",o=n._ctx=n.canvas.getContext("2d");for(let e in t)n._ctx[e]=t[e];return o.scale(n._pixelDensity,n._pixelDensity),n._pixelDensity},n.map=(e,t,a,n,o,i)=>{let r=n+1*(e-t)/(a-t)*(o-n);return i?n<o?Math.min(Math.max(r,n),o):Math.min(Math.max(r,o),n):r},n.lerp=(e,t,a)=>e*(1-a)+t*a,n.constrain=(e,t,a)=>Math.min(Math.max(e,t),a),n.dist=function(){return 4==arguments.length?Math.hypot(arguments[0]-arguments[2],arguments[1]-arguments[3]):Math.hypot(arguments[0]-arguments[3],arguments[1]-arguments[4],arguments[2]-arguments[5])},n.norm=(e,t,a)=>n.map(e,t,a,0,1),n.sq=e=>e*e,n.fract=e=>e-Math.floor(e),n.angleMode=e=>n._angleMode=e,n._DEGTORAD=Math.PI/180,n._RADTODEG=180/Math.PI,n.degrees=e=>e*n._RADTODEG,n.radians=e=>e*n._DEGTORAD,n.abs=Math.abs,n.ceil=Math.ceil,n.exp=Math.exp,n.floor=Math.floor,n.log=Math.log,n.mag=Math.hypot,n.max=Math.max,n.min=Math.min,n.round=Math.round,n.pow=Math.pow,n.sqrt=Math.sqrt,n.sin=e=>("degrees"==n._angleMode&&(e=n.radians(e)),Math.sin(e)),n.cos=e=>("degrees"==n._angleMode&&(e=n.radians(e)),Math.cos(e)),n.tan=e=>("degrees"==n._angleMode&&(e=n.radians(e)),Math.tan(e)),n.asin=e=>{let t=Math.asin(e);return"degrees"==n._angleMode&&(t=n.degrees(t)),t},n.acos=e=>{let t=Math.acos(e);return"degrees"==n._angleMode&&(t=n.degrees(t)),t},n.atan=e=>{let t=Math.atan(e);return"degrees"==n._angleMode&&(t=n.degrees(t)),t},n.atan2=(e,t)=>{let a=Math.atan2(e,t);return"degrees"==n._angleMode&&(a=n.degrees(a)),a},n.nf=(e,t,a)=>{let n=e<0,o=e.toString();return n&&(o=o.slice(1)),o=o.padStart(t,"0"),a>0&&(-1==o.indexOf(".")&&(o+="."),o=o.padEnd(t+1+a,"0")),n&&(o="-"+o),o},n.createVector=(e,t,a)=>new Q5.Vector(e,t,a,n),n.curvePoint=(e,t,a,n,o)=>{const i=o*o*o,r=o*o;return e*(-.5*i+r-.5*o)+t*(1.5*i-2.5*r+1)+a*(-1.5*i+2*r+.5*o)+n*(.5*i-.5*r)},n.bezierPoint=(e,t,a,n,o)=>{const i=1-o;return Math.pow(i,3)*e+3*Math.pow(i,2)*o*t+3*i*Math.pow(o,2)*a+Math.pow(o,3)*n},n.curveTangent=(e,t,a,n,o)=>{const i=o*o;return e*(-3*i/2+2*o-.5)+t*(9*i/2-5*o)+a*(-9*i/2+4*o+.5)+n*(3*i/2-o)},n.bezierTangent=(e,t,a,n,o)=>{const i=1-o;return 3*n*Math.pow(o,2)-3*a*Math.pow(o,2)+6*a*i*o-6*t*i*o+3*t*Math.pow(i,2)-3*e*Math.pow(i,2)},n.Color=Q5.Color,n.colorMode=e=>{n._colorMode=e};let y={aqua:[0,255,255],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],crimson:[220,20,60],darkviolet:[148,0,211],gold:[255,215,0],green:[0,128,0],gray:[128,128,128],grey:[128,128,128],hotpink:[255,105,180],indigo:[75,0,130],khaki:[240,230,140],lightgreen:[144,238,144],lime:[0,255,0],magenta:[255,0,255],navy:[0,0,128],orange:[255,165,0],olive:[128,128,0],peachpuff:[255,218,185],pink:[255,192,203],purple:[128,0,128],red:[255,0,0],skyblue:[135,206,235],tan:[210,180,140],turquoise:[64,224,208],transparent:[0,0,0,0],white:[255,255,255],violet:[238,130,238],yellow:[255,255,0]};function M(){o.fillStyle="white",o.strokeStyle="black",o.lineCap="round",o.lineJoin="miter",o.textAlign="left"}function w(e){let t=n._angleMode==n.DEGREES?180:Math.PI,a=2*t;if(0<=e&&e<=a)return e;for(;e<0;)e+=a;for(;e>=t;)e-=a;return e}function R(e,t,a,i,r,s,l,h){if(!n._doFill&&!n._doStroke)return;let c=w(r),d=w(s);if(c>d&&([c,d]=[d,c]),0==c){if(0==d)return;if(n._angleMode==n.DEGREES&&360==d||d==n.TAU)return n.ellipse(e,t,a,i)}o.beginPath();for(let r=0;r<h+1;r++){let s=r/h,l=n.lerp(c,d,s),u=n.cos(l)*a/2,_=n.sin(l)*i/2;o[r?"lineTo":"moveTo"](e+u,t+_)}l==n.CHORD?o.closePath():l==n.PIE&&(o.lineTo(e,t),o.closePath()),n._doFill&&o.fill(),n._doStroke&&o.stroke()}function S(e,t,a,i){(n._doFill||n._doStroke)&&(o.beginPath(),o.ellipse(e,t,a/2,i/2,0,0,n.TAU),n._doFill&&o.fill(),n._doStroke&&o.stroke())}function C(e,t,a,i,r,s,l,h){if(!n._doFill&&!n._doStroke)return;if(void 0===r)return function(e,t,a,i){n._doFill&&o.fillRect(e,t,a,i),n._doStroke&&o.strokeRect(e,t,a,i)}(e,t,a,i);if(void 0===s)return C(e,t,a,i,r,r,r,r);const c=Math.min(Math.abs(i),Math.abs(a))/2;r=Math.min(c,r),s=Math.min(c,s),h=Math.min(c,h),l=Math.min(c,l),o.beginPath(),o.moveTo(e+r,t),o.arcTo(e+a,t,e+a,t+i,s),o.arcTo(e+a,t+i,e,t+i,l),o.arcTo(e,t+i,e,t,h),o.arcTo(e,t,e+a,t,r),o.closePath(),n._doFill&&o.fill(),n._doStroke&&o.stroke()}function I(){_=[]}function E(e,t,a){return e.slice(0,200)+n._textStyle+n._textSize+n._textFont+(n._doFill?o.fillStyle:"")+"_"+(n._doStroke&&n._strokeSet?o.lineWidth+o.strokeStyle+"_":"")+(t||"")+(a?"x"+a:"")}n.color=function(){let e=arguments;if(1==e.length){if("string"==typeof e[0])return"#"==e[0][0]?new Q5.Color(parseInt(e[0].slice(1,3),16),parseInt(e[0].slice(3,5),16),parseInt(e[0].slice(5,7),16),1):y[e[0]]?new Q5.Color(...y[e[0]],1):new Q5.Color(0,0,0,1);if("number"!=typeof e[0]&&786698==e[0].MAGIC)return e[0]}if(n._colorMode==n.RGB){if(1==e.length)return new Q5.Color(e[0],e[0],e[0],1);if(2==e.length)return new Q5.Color(e[0],e[0],e[0],e[1]/255);if(3==e.length)return new Q5.Color(e[0],e[1],e[2],1);if(4==e.length)return new Q5.Color(e[0],e[1],e[2],e[3]/255)}else{if(1==e.length)return new Q5.Color(...Q5.Color._hsv2rgb(0,0,e[0]/100),1);if(2==e.length)return new Q5.Color(...Q5.Color._hsv2rgb(0,0,e[0]/100),e[1]/255);if(3==e.length)return new Q5.Color(...Q5.Color._hsv2rgb(e[0],e[1]/100,e[2]/100),1);if(4==e.length)return new Q5.Color(...Q5.Color._hsv2rgb(e[0],e[1]/100,e[2]/100),e[3])}return null},n.red=e=>e._r,n.green=e=>e._g,n.blue=e=>e._b,n.alpha=e=>255*e._a,n.hue=e=>(e._inferHSV(),e._h),n.saturation=e=>(e._inferHSV(),e._s),n.brightness=e=>(e._inferHSV(),e._v),n.lightness=e=>100*(.2126*e._r+.7152*e._g+.0722*e._b)/255,n.lerpColor=(e,t,a)=>n._colorMode==n.RGB?new Q5.Color(n.constrain(n.lerp(e._r,t._r,a),0,255),n.constrain(n.lerp(e._g,t._g,a),0,255),n.constrain(n.lerp(e._b,t._b,a),0,255),n.constrain(n.lerp(e._a,t._a,a),0,1)):(e._inferHSV(),t._inferHSV(),new Q5.Color(n.constrain(function(e,t,a){var o=[[Math.abs(t-e),n.map(a,0,1,e,t)],[Math.abs(t+360-e),n.map(a,0,1,e,t+360)],[Math.abs(t-360-e),n.map(a,0,1,e,t-360)]];return o.sort(((e,t)=>e[0]-t[0])),(o[0][1]+720)%360}(e._h,t._h,a),0,360),n.constrain(n.lerp(e._s,t._s,a),0,100),n.constrain(n.lerp(e._v,t._v,a),0,100),n.constrain(n.lerp(e._a,t._a,a),0,1))),n.strokeWeight=e=>{e||(n._doStroke=!1),o.lineWidth=e||1e-4},n.stroke=function(){if(n._doStroke=!0,n._strokeSet=!0,"string"==typeof arguments[0])return void(o.strokeStyle=arguments[0]);let e=n.color(...arguments);e._a<=0?n._doStroke=!1:o.strokeStyle=e},n.noStroke=()=>n._doStroke=!1,n.fill=function(){if(n._doFill=!0,n._fillSet=!0,"string"==typeof arguments[0])return void(o.fillStyle=arguments[0]);let e=n.color(...arguments);e._a<=0?n._doFill=!1:o.fillStyle=e},n.noFill=()=>n._doFill=!1,n.smooth=()=>n._smooth=!0,n.noSmooth=()=>n._smooth=!1,n.blendMode=e=>o.globalCompositeOperation=e,n.strokeCap=e=>o.lineCap=e,n.strokeJoin=e=>o.lineJoin=e,n.ellipseMode=e=>n._ellipseMode=e,n.rectMode=e=>n._rectMode=e,n.curveDetail=e=>n._curveDetail=e,n.curveAlpha=e=>n._curveAlpha=e,n.curveTightness=e=>n._curveAlpha=e,n.clear=()=>{o.clearRect(0,0,n.canvas.width,n.canvas.height)},n.background=function(){if(arguments[0]&&arguments[0].MAGIC==n.MAGIC)return n.image(arguments[0],0,0,n.width,n.height);o.save(),o.resetTransform(),o.fillStyle="string"==typeof arguments[0]?arguments[0]:n.color(...Array.from(arguments)),o.fillRect(0,0,n.canvas.width,n.canvas.height),o.restore()},n.line=(e,t,a,i)=>{n._doStroke&&(o.beginPath(),o.moveTo(e,t),o.lineTo(a,i),o.stroke())},n.arc=(e,t,a,o,i,r,s,l)=>{if(i==r)return n.ellipse(e,t,a,o);l??=25,s??=n.PIE,n._ellipseMode==n.CENTER?R(e,t,a,o,i,r,s,l):n._ellipseMode==n.RADIUS?R(e,t,2*a,2*o,i,r,s,l):n._ellipseMode==n.CORNER?R(e+a/2,t+o/2,a,o,i,r,s,l):n._ellipseMode==n.CORNERS&&R((e+a)/2,(t+o)/2,a-e,o-t,i,r,s,l)},n.ellipse=(e,t,a,o)=>{o??=a,n._ellipseMode==n.CENTER?S(e,t,a,o):n._ellipseMode==n.RADIUS?S(e,t,2*a,2*o):n._ellipseMode==n.CORNER?S(e+a/2,t+o/2,a,o):n._ellipseMode==n.CORNERS&&S((e+a)/2,(t+o)/2,a-e,o-t)},n.circle=(e,t,a)=>n.ellipse(e,t,a,a),n.point=(e,t)=>{e.x&&(t=e.y,e=e.x),o.beginPath(),o.ellipse(e,t,.4,.4,0,0,n.TAU),o.stroke()},n.rect=(e,t,a,o,i,r,s,l)=>{n._rectMode==n.CENTER?C(e-a/2,t-o/2,a,o,i,r,s,l):n._rectMode==n.RADIUS?C(e-a,t-o,2*a,2*o,i,r,s,l):n._rectMode==n.CORNER?C(e,t,a,o,i,r,s,l):n._rectMode==n.CORNERS&&C(e,t,a-e,o-t,i,r,s,l)},n.square=(e,t,a,o,i,r,s)=>n.rect(e,t,a,a,o,i,r,s),n.beginShape=()=>{I(),o.beginPath(),u=!0},n.beginContour=()=>{o.closePath(),I(),u=!0},n.endContour=()=>{I(),u=!0},n.vertex=(e,t)=>{I(),u?o.moveTo(e,t):o.lineTo(e,t),u=!1},n.bezierVertex=(e,t,a,n,i,r)=>{I(),o.bezierCurveTo(e,t,a,n,i,r)},n.quadraticVertex=(e,t,a,n)=>{I(),o.quadraticCurveTo(e,t,a,n)},n.bezier=(e,t,a,o,i,r,s,l)=>{n.beginShape(),n.vertex(e,t),n.bezierVertex(a,o,i,r,s,l),n.endShape()},n.triangle=(e,t,a,o,i,r)=>{n.beginShape(),n.vertex(e,t),n.vertex(a,o),n.vertex(i,r),n.endShape(n.CLOSE)},n.quad=(e,t,a,o,i,r,s,l)=>{n.beginShape(),n.vertex(e,t),n.vertex(a,o),n.vertex(i,r),n.vertex(s,l),n.endShape(n.CLOSE)},n.endShape=e=>{I(),e&&o.closePath(),n._doFill&&o.fill(),n._doStroke&&o.stroke(),n._doFill||n._doStroke||(o.save(),o.fillStyle="none",o.fill(),o.restore())},n.curveVertex=(e,t)=>{if(_.push([e,t]),_.length<4)return;let a=function(e,t,a,n,o,i,r,s,l,h){function c(e,t,a,n,o,i){let r=Math.pow(n-t,2)+Math.pow(o-a,2);return Math.pow(r,.5*i)+e}let d=[],u=c(0,e,t,a,n,h),_=c(u,a,n,o,i,h),g=c(_,o,i,r,s,h);for(let h=0;h<l;h++){let c=u+h/(l-1)*(_-u),m=[(u-c)/(u-0),(c-0)/(u-0),(_-c)/(_-u),(c-u)/(_-u),(g-c)/(g-_),(c-_)/(g-_),(_-c)/(_-0),(c-0)/(_-0),(g-c)/(g-u),(c-u)/(g-u)];for(let e=0;e<m.length;e+=2)isNaN(m[e])&&(m[e]=1,m[e+1]=0),isFinite(m[e])||(m[e]>0?(m[e]=1,m[e+1]=0):(m[e]=0,m[e+1]=1));let p=e*m[0]+a*m[1],f=t*m[0]+n*m[1],v=a*m[2]+o*m[3],x=n*m[2]+i*m[3],y=o*m[4]+r*m[5],M=i*m[4]+s*m[5],w=p*m[6]+v*m[7],R=f*m[6]+x*m[7],S=v*m[8]+y*m[9],C=x*m[8]+M*m[9],I=w*m[2]+S*m[3],E=R*m[2]+C*m[3];d.push([I,E])}return d}(..._[_.length-4],..._[_.length-3],..._[_.length-2],..._[_.length-1],n._curveDetail,n._curveAlpha);for(let e=0;e<a.length;e++)u?o.moveTo(...a[e]):o.lineTo(...a[e]),u=!1},n.curve=(e,t,a,o,i,r,s,l)=>{n.beginShape(),n.curveVertex(e,t),n.curveVertex(a,o),n.curveVertex(i,r),n.curveVertex(s,l),n.endShape()},n.translate=(e,t)=>o.translate(e,t),n.rotate=e=>{"degrees"==n._angleMode&&(e=n.radians(e)),o.rotate(e)},n.scale=(e,t)=>{t??=e,o.scale(e,t)},n.applyMatrix=(e,t,a,n,i,r)=>{o.transform(e,t,a,n,i,r)},n.shearX=e=>{o.transform(1,0,n.tan(e),1,0,0)},n.shearY=e=>{o.transform(1,n.tan(e),0,1,0,0)},n.resetMatrix=()=>{o.resetTransform(),o.scale(n._pixelDensity,n._pixelDensity)},n._styleNames=["_doStroke","_doFill","_strokeSet","_fillSet","_tint","_imageMode","_rectMode","_ellipseMode","_textFont","_textLeading","_leadingSet","_textSize","_textAlign","_textBaseline","_textStyle","_textWrap"],n._ctxStyleNames=["strokeStyle","fillStyle","lineWidth","lineCap","lineJoin"],n._styles=[],n._ctxStyles=[],n.pushMatrix=n.push=()=>{o.save();let e={};for(let t of n._styleNames)e[t]=n[t];n._styles.push(e);let t={};for(let e of n._ctxStyleNames)t[e]=o[e];n._ctxStyles.push(t)},n.popMatrix=n.pop=()=>{o.restore();let e=n._styles.pop();for(let t of n._styleNames)n[t]=e[t];let t=n._ctxStyles.pop();for(let e of n._ctxStyleNames)o[e]=t[e]},n.imageMode=e=>n._imageMode=e,n.image=(e,t,a,i,r,s,l,h,c)=>{let d=e.MAGIC==n.MAGIC?e.canvas:e;var u,_;e.MAGIC==n.MAGIC&&null!=n._tint&&(u=e.canvas.width,_=e.canvas.height,null==f&&(f=document.createElement("canvas").getContext("2d")),_??=u||o.canvas.height,u??=o.canvas.width,f.canvas.width==u&&f.canvas.height==_||(f.canvas.width=u,f.canvas.height=_),f.drawImage(e.canvas,0,0),e.tinted(n._tint)),i||(e.MAGIC==n.MAGIC||e.width?(i=e.width,r=e.height):(i=e.videoWidth,r=e.videoHeight)),"center"==n._imageMode&&(t-=.5*i,a-=.5*r);let g=e._pixelDensity;s??=0,l??=0,h?h*=g:h=d.width,c?c*=g:c=d.height,o.drawImage(d,s*g,l*g,h,c,t,a,i,r),function(){if(e.MAGIC!=n.MAGIC||!n._tint)return;let t=e.canvas.getContext("2d");t.save(),t.resetTransform(),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.drawImage(f.canvas,0,0),t.restore()}()},n._incrementPreload=()=>a++,n._decrementPreload=()=>a--,n.loadImage=(e,t)=>{a++;let o=n.createImage(1,1),i=o.canvas.getContext("2d"),r=new window.Image;return r.src=e,r.crossOrigin="Anonymous",r._pixelDensity=1,r.onload=()=>{o.width=i.canvas.width=r.naturalWidth,o.height=i.canvas.height=r.naturalHeight,i.drawImage(r,0,0),a--,t&&t(o)},r.onerror=e=>{throw a--,e},o},n._clearTemporaryBuffers=()=>{p=null,f=null,v=null},n.loadFont=(e,t)=>{a++;let n=e.split("/"),o=n[n.length-1].split(".")[0].replace(" ",""),i=new FontFace(o,"url("+e+")");return document.fonts.add(i),i.load().then((()=>{a--,t&&t(o)})),o},n.textFont=e=>n._textFont=e,n.textSize=e=>{if(void 0===e)return n._textSize;n._textSize=e,n._leadingSet||(n._textLeading=1.25*e,n._textLeadDiff=n._textLeading-e)},n.textLeading=e=>{if(void 0===e)return n._textLeading;n._textLeading=e,n._textLeadDiff=e-n._textSize,n._leadingSet=!0},n.textStyle=e=>n._textStyle=e,n.textAlign=(e,t)=>{o.textAlign=e,t&&(o.textBaseline=t==n.CENTER?"middle":t)},n.textWidth=e=>(o.font=`${n._textStyle} ${n._textSize}px ${n._textFont}`,o.measureText(e).width),n.textAscent=e=>(o.font=`${n._textStyle} ${n._textSize}px ${n._textFont}`,o.measureText(e).actualBoundingBoxAscent),n.textDescent=e=>(o.font=`${n._textStyle} ${n._textSize}px ${n._textFont}`,o.measureText(e).actualBoundingBoxDescent),n._textCache=!0,n._TimedCache=class extends Map{constructor(){super(),this.maxSize=500}set(e,t){t.lastAccessed=Date.now(),super.set(e,t),this.size>this.maxSize&&this.gc()}get(e){const t=super.get(e);return t&&(t.lastAccessed=Date.now()),t}gc(){let e,t=1/0,a=0;for(const[n,o]of this.entries())o.lastAccessed<t&&(t=o.lastAccessed,e=a),a++;a=e;for(const t of this.keys()){if(0==a){e=t;break}a--}this.delete(e)}},n._tic=new n._TimedCache,n.textCache=(e,t)=>(t&&(n._tic.maxSize=t),void 0!==e&&(n._textCache=e),n._textCache),n.createTextImage=(e,t,a)=>{let o=n._textCache;n._textCache=!0,n._useCache=!0,n.text(e,0,0,t,a),n._useCache=!1;let i=E(e,t,a);return n._textCache=o,n._tic.get(i)},n.text=(e,t,a,i,r)=>{if(void 0===e)return;if(e=e.toString(),!n._doFill&&!n._doStroke)return;let s,l,h,c,d,u,_,g,m=1,p=o.getTransform(),f=n._useCache||n._textCache&&(0!=p.b||0!=p.c);if(f){if(c=E(e,i,r),l=n._tic.get(c),l)return void n.textImage(l,t,a);h=n.createGraphics.call(n,1,1),s=h._ctx,m=n._pixelDensity}else s=o,d=t,u=a;s.font=`${n._textStyle} ${n._textSize}px ${n._textFont}`;let v=e.split("\n");if(f){d=0,u=n._textLeading*v.length;let t=s.measureText(" ");_=t.fontBoundingBoxAscent,g=t.fontBoundingBoxDescent,r??=u+g,h.resizeCanvas(Math.ceil(s.measureText(e).width),Math.ceil(r)),s.fillStyle=o.fillStyle,s.strokeStyle=o.strokeStyle,s.lineWidth=o.lineWidth}let x=s.fillStyle;n._fillSet||(s.fillStyle="black");for(let e=0;e<v.length&&(n._doStroke&&n._strokeSet&&s.strokeText(v[e],d,u),n._doFill&&s.fillText(v[e],d,u),u+=n._textLeading,!(u>r));e++);n._fillSet||(s.fillStyle=x),f&&(l=h.get(),l._pixelDensity=m,l.width/=m,l.height/=m,l._ascent=_,l._descent=g,n._tic.set(c,l),n.textImage(l,t,a))},n.textImage=(e,t,a)=>{let i=n._imageMode;n._imageMode="corner","center"==o.textAlign?t-=.5*e.width:"right"==o.textAlign&&(t-=e.width),"alphabetic"==o.textBaseline&&(a-=n._textLeading),"middle"==o.textBaseline?a-=e._descent+.5*e._ascent+n._textLeadDiff:"bottom"==o.textBaseline?a-=e._ascent+e._descent+n._textLeadDiff:"top"==o.textBaseline&&(a-=e._descent+n._textLeadDiff),n.image(e,t,a),n._imageMode=i};var b,D=4095,A=4,T=.5,k=e=>.5*(1-Math.cos(e*Math.PI));n.noise=(e,t,a)=>{if(t??=0,a??=0,null==b){b=new Array(4096);for(var n=0;n<4096;n++)b[n]=Math.random()}e<0&&(e=-e),t<0&&(t=-t),a<0&&(a=-a);for(var o,i,r,s,l,h=Math.floor(e),c=Math.floor(t),d=Math.floor(a),u=e-h,_=t-c,g=a-d,m=0,p=.5,f=0;f<A;f++){var v=h+(c<<4)+(d<<8);o=k(u),i=k(_),r=b[v&D],r+=o*(b[v+1&D]-r),s=b[v+16&D],r+=i*((s+=o*(b[v+16+1&D]-s))-r),s=b[(v+=256)&D],s+=o*(b[v+1&D]-s),l=b[v+16&D],s+=i*((l+=o*(b[v+16+1&D]-l))-s),m+=(r+=k(g)*(s-r))*p,p*=T,h<<=1,c<<=1,d<<=1,(u*=2)>=1&&(h++,u--),(_*=2)>=1&&(c++,_--),(g*=2)>=1&&(d++,g--)}return m},n.noiseDetail=(e,t)=>{e>0&&(A=e),t>0&&(T=t)};const P=()=>{let e,t,a=4294967295;return{setSeed(n){e=t=(null==n?Math.random()*a:n)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/a)}};let O=P();O.setSeed(),n.noiseSeed=e=>{let t=void 0===e?4294967295*Math.random():e;b||(b=new Float32Array(4096));for(var a=0;a<4096;a++)t^=t<<17,t^=t>>13,t^=t<<5,b[a]=(t>>>0)/4294967295},n.randomSeed=e=>O.setSeed(e),n.random=(e,t)=>void 0===e?O.rand():"number"==typeof e?void 0!==t?O.rand()*(t-e)+e:O.rand()*e:e[~~(e.length*O.rand())],n.randomGenerator=e=>{e==n.LCG?O=(()=>{const e=4294967296;let t,a;return{setSeed(n){a=t=(null==n?Math.random()*e:n)>>>0},getSeed:()=>t,rand:()=>(a=(1664525*a+1013904223)%e,a/e)}})():e==n.SHR3&&(O=P()),O.setSeed()};var z=new function(){var e,t,a,n=new Array(128),o=new Array(256),i=new Array(128),r=new Array(128),s=new Array(256),l=new Array(256),h=()=>4294967296*O.rand()-2147483648,c=()=>.5+2.328306e-10*(h()<<0),d=()=>{for(var t,o,s,l,d=3.44262;;){if(t=a*i[e],0==e){do{s=c(),l=c(),t=.2904764*-Math.log(s),o=-Math.log(l)}while(o+o<t*t);return a>0?d+t:-d-t}if(r[e]+c()*(r[e-1]-r[e])<Math.exp(-.5*t*t))return t;if(a=h(),e=127&a,Math.abs(a)<n[e])return a*i[e]}},u=()=>{for(var a;;){if(0==e)return 7.69711-Math.log(c());if(a=t*s[e],l[e]+c()*(l[e-1]-l[e])<Math.exp(-a))return a;if((t=h())<o[e=255&t])return t*s[e]}};this.SHR3=h,this.UNI=c,this.RNOR=()=>(a=h(),e=127&a,Math.abs(a)<n[e]?a*i[e]:d()),this.REXP=()=>(t=h()>>>0)<n[e=255&t]?t*s[e]:u(),this.zigset=()=>{var e,t,a=2147483648,h=4294967296,c=3.442619855899,d=c,u=.00991256303526217,_=7.697117470131487,g=_,m=.003949659822581572;for(e=u/Math.exp(-.5*c*c),n[0]=Math.floor(c/e*a),n[1]=0,i[0]=e/a,i[127]=c/a,r[0]=1,r[127]=Math.exp(-.5*c*c),t=126;t>=1;t--)c=Math.sqrt(-2*Math.log(u/c+Math.exp(-.5*c*c))),n[t+1]=Math.floor(c/d*a),d=c,r[t]=Math.exp(-.5*c*c),i[t]=c/a;for(e=m/Math.exp(-_),o[0]=Math.floor(_/e*h),o[1]=0,s[0]=e/h,s[255]=_/h,l[0]=1,l[255]=Math.exp(-_),t=254;t>=1;t--)_=-Math.log(m/_+Math.exp(-_)),o[t+1]=Math.floor(_/g*h),g=_,l[t]=Math.exp(-_),s[t]=_/h}};function F(){let e=performance.now();if(n._loop)d=n._targetFrameRate?setTimeout(F,1e3/n._targetFrameRate):requestAnimationFrame(F);else if(n.frameCount>0)return;if(d&&0!=n.frameCount){if(e-n._lastFrameTime<1e3/(n._targetFrameRate||60)-5)return}n.deltaTime=e-n._lastFrameTime,n._frameRate=1e3/n.deltaTime,n.frameCount++,n._shouldResize&&(n._windowResizedFn(),n._shouldResize=!1);for(let e of Q5.prototype._methods.pre)e.call(n);I(),u=!0,o.save(),n._drawFn();for(let e of Q5.prototype._methods.post)e.call(n);o.restore(),n.resetMatrix();let t=performance.now();n._fps=Math.round(1e3/(t-e)),n._lastFrameTime=e,n.pmouseX=n.mouseX,n.pmouseY=n.mouseY}function Q(e){const t=n.canvas.getBoundingClientRect(),a=n.canvas.scrollWidth/n.width||1,o=n.canvas.scrollHeight/n.height||1;return{x:(e.clientX-t.left)/a,y:(e.clientY-t.top)/o,id:e.identifier}}function L(){return n._touchStartedFn.isPlaceHolder&&n._touchMovedFn.isPlaceHolder&&n._touchEndedFn.isPlaceHolder}z.hasInit=!1,n.randomGaussian=(e,t)=>(z.hasInit||(z.zigset(),z.hasInit=!0),z.RNOR()*t+e),n.randomExponential=()=>(z.hasInit||(z.zigset(),z.hasInit=!0),z.REXP()),n.print=console.log,n.cursor=(e,t,a)=>{let o="";e.includes(".")&&(e=`url("${e}")`,o=", auto"),void 0!==t&&(e+=" "+t+" "+a),n.canvas.style.cursor=e+o},n.noCursor=()=>{n.canvas.style.cursor="none"},n.createCapture=e=>{var t=document.createElement("video");return t.playsinline="playsinline",t.autoplay="autoplay",navigator.mediaDevices.getUserMedia(e).then((e=>{t.srcObject=e})),t.style.position="absolute",t.style.opacity=1e-5,t.style.zIndex=-1e3,document.body.append(t),t},n.noLoop=()=>{n._loop=!1,d=null},n.loop=()=>{n._loop=!0,null==d&&F()},n.redraw=()=>F(),n.frameRate=e=>(e&&(n._targetFrameRate=e),n._frameRate),n.getFrameRate=()=>n._frameRate,n.getFPS=()=>n._fps,n._updateMouse=function(e){let t=this,a=t.canvas.getBoundingClientRect(),n=t.canvas.scrollWidth/t.width||1,o=t.canvas.scrollHeight/t.height||1;t.mouseX=(e.clientX-a.left)/n,t.mouseY=(e.clientY-a.top)/o}.bind(n),n._onmousemove=function(e){n._updateMouse(e),this.mouseIsPressed?this._mouseDraggedFn(e):this._mouseMovedFn(e)}.bind(n),n._onmousedown=e=>{n._updateMouse(e),n.mouseIsPressed=!0,n.mouseButton=[n.LEFT,n.CENTER,n.RIGHT][e.button],n._mousePressedFn(e)},n._onmouseup=e=>{n._updateMouse(e),n.mouseIsPressed=!1,n._mouseReleasedFn(e)},n._onclick=e=>{n._updateMouse(e),n.mouseIsPressed=!0,n._mouseClickedFn(e),n.mouseIsPressed=!1},n._onkeydown=e=>{e.repeat||(n.keyIsPressed=!0,n.key=e.key,n.keyCode=e.keyCode,g[n.keyCode]=!0,n._keyPressedFn(e),1==e.key.length&&n._keyTypedFn(e))},n._onkeyup=e=>{n.keyIsPressed=!1,n.key=e.key,n.keyCode=e.keyCode,g[n.keyCode]=!1,n._keyReleasedFn(e)},n.canvas.onmousedown=e=>n._onmousedown(e),n.canvas.onmouseup=e=>n._onmouseup(e),n.canvas.onclick=e=>n._onclick(e),n.keyIsDown=e=>!!g[e],n._ontouchstart=e=>{n.touches=[...e.touches].map(Q),L()&&(n.mouseX=n.touches[0].x,n.mouseY=n.touches[0].y,n.mouseIsPressed=!0,n.mouseButton=n.LEFT,n._mousePressedFn(e)||e.preventDefault()),n._touchStartedFn(e)||e.preventDefault()},n._ontouchmove=e=>{n.touches=[...e.touches].map(Q),L()&&(n.mouseX=n.touches[0].x,n.mouseY=n.touches[0].y,n._mouseDraggedFn(e)||e.preventDefault()),n._touchMovedFn(e)||e.preventDefault()},n._ontouchend=e=>{n.touches=[...e.touches].map(Q),L()&&!n.touches.length&&(n.mouseIsPressed=!1,n._mouseReleasedFn(e)||e.preventDefault()),n._touchEndedFn(e)||e.preventDefault()},n.canvas.ontouchstart=e=>n._ontouchstart(e),n.canvas.ontouchmove=e=>n._ontouchmove(e),n.canvas.ontouchcancel=n.canvas.ontouchend=e=>n._ontouchend(e),n.hasSensorPermission=!window.DeviceOrientationEvent&&!window.DeviceMotionEvent||!(DeviceOrientationEvent.requestPermission||DeviceMotionEvent.requestPermission),n.requestSensorPermissions=()=>{DeviceOrientationEvent.requestPermission&&DeviceOrientationEvent.requestPermission().then((e=>{"granted"==e&&DeviceMotionEvent.requestPermission&&DeviceMotionEvent.requestPermission().then((e=>{"granted"==e&&(n.hasSensorPermission=!0)})).catch(alert)})).catch(alert)};"undefined"!=typeof window&&(window.ondeviceorientation=e=>{n.pRotationX=n.rotationX,n.pRotationY=n.rotationY,n.pRotationZ=n.rotationZ,n.pRelRotationX=n.relRotationX,n.pRelRotationY=n.relRotationY,n.pRelRotationZ=n.relRotationZ,n.rotationX=e.beta*(Math.PI/180),n.rotationY=e.gamma*(Math.PI/180),n.rotationZ=e.alpha*(Math.PI/180),n.relRotationX=[-n.rotationY,-n.rotationX,n.rotationY][1+~~(window.orientation/90)],n.relRotationY=[-n.rotationX,n.rotationY,n.rotationX][1+~~(window.orientation/90)],n.relRotationZ=n.rotationZ},window.ondevicemotion=e=>{if(n.pAccelerationX=n.accelerationX,n.pAccelerationY=n.accelerationY,n.pAccelerationZ=n.accelerationZ,!e.acceleration){let i=((e,t)=>[(e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3])/(e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15]),(e[4]*t[0]+e[5]*t[1]+e[6]*t[2]+e[7])/(e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15]),(e[8]*t[0]+e[9]*t[1]+e[10]*t[2]+e[11])/(e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15])])((o=n.rotationY,t=[n.cos(o),0,n.sin(o),0,0,1,0,0,-n.sin(o),0,n.cos(o),0,0,0,0,1],a=(e=>[1,0,0,0,0,n.cos(e),-n.sin(e),0,0,n.sin(e),n.cos(e),0,0,0,0,1])(n.rotationX),[t[0]*a[0]+t[1]*a[4]+t[2]*a[8]+t[3]*a[12],t[0]*a[1]+t[1]*a[5]+t[2]*a[9]+t[3]*a[13],t[0]*a[2]+t[1]*a[6]+t[2]*a[10]+t[3]*a[14],t[0]*a[3]+t[1]*a[7]+t[2]*a[11]+t[3]*a[15],t[4]*a[0]+t[5]*a[4]+t[6]*a[8]+t[7]*a[12],t[4]*a[1]+t[5]*a[5]+t[6]*a[9]+t[7]*a[13],t[4]*a[2]+t[5]*a[6]+t[6]*a[10]+t[7]*a[14],t[4]*a[3]+t[5]*a[7]+t[6]*a[11]+t[7]*a[15],t[8]*a[0]+t[9]*a[4]+t[10]*a[8]+t[11]*a[12],t[8]*a[1]+t[9]*a[5]+t[10]*a[9]+t[11]*a[13],t[8]*a[2]+t[9]*a[6]+t[10]*a[10]+t[11]*a[14],t[8]*a[3]+t[9]*a[7]+t[10]*a[11]+t[11]*a[15],t[12]*a[0]+t[13]*a[4]+t[14]*a[8]+t[15]*a[12],t[12]*a[1]+t[13]*a[5]+t[14]*a[9]+t[15]*a[13],t[12]*a[2]+t[13]*a[6]+t[14]*a[10]+t[15]*a[14],t[12]*a[3]+t[13]*a[7]+t[14]*a[11]+t[15]*a[15]]),[0,0,-9.80665]);n.accelerationX=e.accelerationIncludingGravity.x+i[0],n.accelerationY=e.accelerationIncludingGravity.y+i[1],n.accelerationZ=e.accelerationIncludingGravity.z-i[2]}var t,a,o}),n.year=()=>(new Date).getFullYear(),n.day=()=>(new Date).getDay(),n.hour=()=>(new Date).getHours(),n.minute=()=>(new Date).getMinutes(),n.second=()=>(new Date).getSeconds(),n.millis=()=>performance.now()-m,n.storeItem=localStorage.setItem,n.getItem=localStorage.getItem,n.removeItem=localStorage.removeItem,n.clearStorage=localStorage.clear,n._loadFile=(e,t,n)=>{a++;let o={};return fetch(e).then((e=>"json"==n?e.json():"text"==n?e.text():void 0)).then((e=>{a--,Object.assign(o,e),t&&t(e)})),o},n.loadStrings=(e,t)=>n._loadFile(e,t,"text"),n.loadJSON=(e,t)=>n._loadFile(e,t,"json"),n.loadSound=(e,t)=>{a++;let n=new Audio(e);return n.addEventListener("canplaythrough",(()=>{a--,t&&t(n)})),n.load(),n.setVolume=e=>n.volume=e,n.setLoop=e=>n.loop=e,n},n.Element=function(e){this.elt=e},n._elements=[],"global"==e&&(Object.assign(Q5,n),delete Q5.Q5),Q5.Image??=_Q5Image;for(let G of Q5.prototype._methods.init)G.call(n);for(let[V,q]of Object.entries(Q5.prototype))"_"!=V[0]&&"function"==typeof n[V]&&(n[V]=q.bind(n));if("global"==e){let B=Object.getOwnPropertyNames(n);for(let H of B)"function"==typeof n[H]?window[H]=n[H]:Object.defineProperty(window,H,{get:()=>n[H],set:e=>n[H]=e})}function N(){let t="global"==e?window:n,i=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of i){let a="_"+e+"Fn";n[a]=()=>{},n[a].isPlaceHolder=!0,t[e]?n[a]=t[e]:Object.defineProperty(n,e,{set:e=>{n[a]=e}})}if("graphics"!=e||"image"!=e){n._preloadFn(),m=performance.now(),function e(){if(a>0)return requestAnimationFrame(e);o.save(),n._setupFn(),n._setupDone=!0,o.restore(),n.resetMatrix(),requestAnimationFrame(F)}()}addEventListener("mousemove",(e=>n._onmousemove(e)),!1),addEventListener("keydown",(e=>n._onkeydown(e)),!1),addEventListener("keyup",(e=>n._onkeyup(e)),!1)}"function"==typeof e&&e(n),"global"==e?N():requestAnimationFrame(N)}Q5.Color=class{constructor(e,t,a,n){this.MAGIC=786698,this._r=e,this._g=t,this._b=a,this._a=n,this._h=0,this._s=0,this._v=0,this._hsvInferred=!1}setRed(e){this._r=e,this._hsvInferred=!1}setGreen(e){this._g=e,this._hsvInferred=!1}setBlue(e){this._b=e,this._hsvInferred=!1}setAlpha(e){this._a=e/255,this._hsvInferred=!1}get levels(){return[this._r,this._g,this._b,255*this._a]}_inferHSV(){this._hsvInferred||([this._h,this._s,this._v]=Q5.Color._rgb2hsv(this._r,this._g,this._b),this._hsvInferred=!0)}toString(){return`rgba(${Math.round(this._r)},${Math.round(this._g)},${Math.round(this._b)},${~~(1e3*this._a)/1e3})`}},Q5._instanceCount=0,Q5.Color._rgb2hsv=(e,t,a)=>{let n,o,i,r,s;return n=e<t?e<a?e:a:t<a?t:a,o=e>t?e>a?e:a:t>a?t:a,s=100*o/255,0==s?(i=0,r=0,[i,r,s]):(r=100*(o-n)/o,0==r?(i=0,[i,r,s]):(i=o==e?0+60*(t-a)/(o-n):o==t?120+60*(a-e)/(o-n):240+60*(e-t)/(o-n),[i,r,s]))},Q5.Color._hsv2rgb=(e,t,a)=>{let n,o,i,r,s,l,h,c,d;if(0==t)return n=a,o=a,i=a,[255*n,255*o,255*i];switch(r=e,r>360&&(r=0),r/=60,s=~~r,l=r-s,h=a*(1-t),c=a*(1-t*l),d=a*(1-t*(1-l)),s){case 0:n=a,o=d,i=h;break;case 1:n=c,o=a,i=h;break;case 2:n=h,o=a,i=d;break;case 3:n=h,o=c,i=a;break;case 4:n=d,o=h,i=a;break;default:n=a,o=h,i=c}return[255*n,255*o,255*i]},Q5.Vector=class{constructor(e,t,a,n){this.x=e||0,this.y=t||0,this.z=a||0,this._$=n||window,this._cn=null,this._cnsq=null}set(e,t,a){this.x=e||0,this.y=t||0,this.z=a||0}copy(){return new Q5.Vector(this.x,this.y,this.z)}_arg2v(e,t,a){return void 0!==e.x?e:void 0!==t?{x:e,y:t,z:a||0}:{x:e,y:e,z:e}}_calcNorm(){null==this._cnsq&&(this._cnsq=this.x*this.x+this.y*this.y+this.z*this.z,this._cn=Math.sqrt(this._cnsq))}_deprecNorm(){this._cnsq=null,this._cn=null}add(){let e=this._arg2v(...arguments);return this.x+=e.x,this.y+=e.y,this.z+=e.z,this._deprecNorm(),this}rem(){let e=this._arg2v(...arguments);return this.x%=e.x,this.y%=e.y,this.z%=e.z,this._deprecNorm(),this}sub(){let e=this._arg2v(...arguments);return this.x-=e.x,this.y-=e.y,this.z-=e.z,this._deprecNorm(),this}mult(){let e=this._arg2v(...arguments);return this.x*=e.x,this.y*=e.y,this.z*=e.z,this._deprecNorm(),this}div(){let e=this._arg2v(...arguments);return e.x?this.x/=e.x:this.x=0,e.y?this.y/=e.y:this.y=0,e.z?this.z/=e.z:this.z=0,this._deprecNorm(),this}mag(){return this._calcNorm(),this._cn}magSq(){return this._calcNorm(),this._cnsq}dot(){let e=this._arg2v(...arguments);return this.x*e.x+this.y*e.y+this.z*e.z}dist(){let e=this._arg2v(...arguments),t=this.x-e.x,a=this.y-e.y,n=this.z-e.z;return Math.sqrt(t*t+a*a+n*n)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,a=this.z*e.x-this.x*e.z,n=this.x*e.y-this.y*e.x;return this.x=t,this.y=a,this.z=n,this._deprecNorm(),this}normalize(){this._calcNorm();let e=this._cn;return 0!=e&&(this.x/=e,this.y/=e,this.z/=e),this._cn=1,this._cnsq=1,this}limit(e){this._calcNorm();let t=this._cn;if(t>e){let a=e/t;this.x*=a,this.y*=a,this.z*=a,this._cn=e,this._cnsq=e*e}return this}setMag(e){this._calcNorm();let t=e/this._cn;return this.x*=t,this.y*=t,this.z*=t,this._cn=e,this._cnsq=e*e,this}heading(){return this._$.atan2(this.y,this.x)}rotate(e){let t=this._$.cos(e),a=this._$.sin(e),n=this.x*t-this.y*a,o=this.x*a+this.y*t;return this.x=n,this.y=o,this}angleBetween(){let e=this._arg2v(...arguments),t=Q5.Vector.cross(this,e);return this._$.atan2(t.mag(),this.dot(e))*Math.sign(t.z||1)}lerp(){let e=[...arguments],t=this._arg2v(...e.slice(0,-1)),a=e[e.length-1];return this.x+=(t.x-this.x)*a,this.y+=(t.y-this.y)*a,this.z+=(t.z-this.z)*a,this._deprecNorm(),this}reflect(e){return e.normalize(),this.sub(e.mult(2*this.dot(e)))}array(){return[this.x,this.y,this.z]}equals(e,t){return t??=Number.EPSILON||0,Math.abs(e.x-this.x)<t&&Math.abs(e.y-this.y)<t&&Math.abs(e.z-this.z)<t}fromAngle(e,t){return void 0===t&&(t=1),this._cn=t,this._cnsq=t*t,this.x=t*this._$.cos(e),this.y=t*this._$.sin(e),this.z=0,this}fromAngles(e,t,a){void 0===a&&(a=1),this._cn=a,this._cnsq=a*a;const n=this._$.cos(t),o=this._$.sin(t),i=this._$.cos(e),r=this._$.sin(e);return this.x=a*r*o,this.y=-a*i,this.z=a*r*n,this}random2D(){return this._cn=this._cnsq=1,this.fromAngle(Math.random()*Math.PI*2)}random3D(){return this._cn=this._cnsq=1,this.fromAngles(Math.random()*Math.PI*2,Math.random()*Math.PI*2)}toString(){return`[${this.x}, ${this.y}, ${this.z}]`}},Q5.Vector.add=(e,t)=>e.copy().add(t),Q5.Vector.cross=(e,t)=>e.copy().cross(t),Q5.Vector.dist=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z),Q5.Vector.div=(e,t)=>e.copy().div(t),Q5.Vector.dot=(e,t)=>e.copy().dot(t),Q5.Vector.equals=(e,t,a)=>e.equals(t,a),Q5.Vector.lerp=(e,t,a)=>e.copy().lerp(t,a),Q5.Vector.limit=(e,t)=>e.copy().limit(t),Q5.Vector.heading=e=>this._$.atan2(e.y,e.x),Q5.Vector.magSq=e=>e.x*e.x+e.y*e.y+e.z*e.z,Q5.Vector.mag=e=>Math.sqrt(Q5.Vector.magSq(e)),Q5.Vector.mult=(e,t)=>e.copy().mult(t),Q5.Vector.normalize=e=>e.copy().normalize(),Q5.Vector.rem=(e,t)=>e.copy().rem(t),Q5.Vector.sub=(e,t)=>e.copy().sub(t);for(let e of["fromAngle","fromAngles","random2D","random3D"])Q5.Vector[e]=(t,a,n)=>(new Q5.Vector)[e](t,a,n);class _Q5Image extends Q5{constructor(e,t){super("image"),this.createCanvas(e,t),delete this.createCanvas,this._loop=!1}}Q5._friendlyError=(e,t)=>{throw t+": "+e},Q5.prototype._methods={init:[],pre:[],post:[],remove:[]},Q5.prototype.registerMethod=(e,t)=>Q5.prototype._methods[e].push(t),Q5.prototype.registerPreloadMethod=(e,t)=>Q5.prototype[e]=t[e],Q5._validateParameters=()=>!0,"undefined"!=typeof module?module.exports=Q5:window.p5??=Q5,document.addEventListener("DOMContentLoaded",(()=>{Q5._hasGlobal||new Q5("auto")}));