diff --git a/package.json b/package.json index 65c255a..d7b76d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "q5", - "version": "2.0.2", + "version": "2.0.3", "description": "The sequel to p5.js that's smaller and faster", "author": "quinton-ashley", "contributors": [ diff --git a/q5.js b/q5.js index 82bf958..1f1a223 100644 --- a/q5.js +++ b/q5.js @@ -183,6 +183,7 @@ function Q5(scope, parent) { }; let t = globalScope || $; + $._isTouchAware = t.touchStarted || t.touchMoved || t.mouseReleased; let preloadDefined = t.preload; let userFns = [ 'setup', @@ -215,8 +216,6 @@ function Q5(scope, parent) { } } - $._isTouchAware = $.touchStarted || $.touchMoved || $.mouseReleased; - if (!($.setup || $.draw)) return; $._startDone = false; diff --git a/q5.min.js b/q5.min.js index d47bca0..83c82f0 100644 --- a/q5.min.js +++ b/q5.min.js @@ -5,4 +5,4 @@ * @license LGPL-3.0 * @class Q5 */ -function Q5(e,t){let a,o=this;if(o._q5=!0,o._scope=e,o._parent=t,o._preloadCount=0,e??="global","auto"==e){if(!window.setup&&!window.draw)return;e="global"}"global"==e&&(Q5._hasGlobal=o._isGlobal=!0,a=Q5._nodejs?global:window);let n=new Proxy(o,{set:(e,t,n)=>(o[t]=n,o._isGlobal&&(a[t]=n),!0)});o.canvas=o.ctx=o.drawingContext=null,o.pixels=[];let r=null;o.frameCount=0,o.deltaTime=16,o._targetFrameRate=0,o._targetFrameDuration=16.666666666666668,o._frameRate=o._fps=60,o._loop=!0;let i=0;function s(e){let t=e||performance.now();if(o._lastFrameTime??=t-o._targetFrameDuration,o._shouldResize&&(o.windowResized(),o._shouldResize=!1),o._loop)r=l(s);else if(o.frameCount&&!o._redraw)return;if(r&&o.frameCount){if(t-o._lastFrameTimeperformance.now()-i,o.noCanvas=()=>{o.canvas?.remove&&o.canvas.remove(),o.canvas=0,n.ctx=n.drawingContext=0},window&&(o.windowWidth=window.innerWidth,o.windowHeight=window.innerHeight,o.deviceOrientation=window.screen?.orientation?.type),o._incrementPreload=()=>n._preloadCount++,o._decrementPreload=()=>n._preloadCount--,o.noLoop=()=>{o._loop=!1,r=null},o.loop=()=>{o._loop=!0,null==r&&s()},o.redraw=(e=1)=>{o._redraw=!0;for(let t=0;t{o.noLoop(),o.canvas.remove()},o.frameRate=e=>(e&&(o._targetFrameRate=e,o._targetFrameDuration=1e3/e),o._frameRate),o.getTargetFrameRate=()=>o._targetFrameRate,o.getFPS=()=>o._fps,o.Element=function(e){this.elt=e},o._elements=[],o.TWO_PI=o.TAU=2*Math.PI,o.log=o.print=console.log,o.describe=()=>{};for(let e in Q5.modules)Q5.modules[e](o,n);for(let e in Q5)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&(o[e]=Q5[e]);"global"==e&&(Object.assign(Q5,o),delete Q5.Q5);for(let e of Q5.prototype._methods.init)e.call(o);for(let[e,t]of Object.entries(Q5.prototype))"_"!=e[0]&&"function"==typeof o[e]&&(o[e]=t.bind(o));if("global"==e){let e=Object.getOwnPropertyNames(o);for(let t of e)"_"!=t[0]&&(a[t]=o[t])}if("function"==typeof e&&e(o),"graphics"==e)return;Q5._instanceCount++;let l=window.requestAnimationFrame||function(e){const t=o._lastFrameTime+o._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},c=a||o,d=c.preload,h=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of h)c[e]?o._isGlobal&&(o[e]=()=>{try{c[e]()}catch(e){o._aiErrorAssistance?o._aiErrorAssistance(e):console.error(e)}}):o[e]=()=>{};async function u(){if(o._startDone=!0,o._preloadCount>0)return l(u);i=performance.now(),await o.setup(),o.frameCount||(null===o.ctx&&o.createCanvas(100,100),o._setupDone=!0,o.ctx&&o.resetMatrix(),l(s))}o._isTouchAware=o.touchStarted||o.touchMoved||o.mouseReleased,(o.setup||o.draw)&&(o._startDone=!1,arguments.length&&"namespace"!=e||d?(o.preload(),u()):(c.preload=o.preload=()=>{o._startDone||u()},setTimeout(o.preload,32)))}Q5.modules={},Q5._nodejs="object"==typeof process,Q5._instanceCount=0,Q5._friendlyError=(e,t)=>{throw Error(t+": "+e)},Q5._validateParameters=()=>!0,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._nodejs?global.p5??=global.Q5=Q5:"object"==typeof window?window.p5??=window.Q5=Q5:window=0,"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{Q5._hasGlobal||new Q5("auto")})),Q5.modules.q2d_canvas=(e,t)=>{e._OffscreenCanvas=window.OffscreenCanvas||function(){return document.createElement("canvas")},Q5._nodejs?Q5._createNodeJSCanvas&&(t.canvas=Q5._createNodeJSCanvas(100,100)):"image"!=e._scope&&"graphics"!=e._scope||(t.canvas=new e._OffscreenCanvas(100,100)),e.canvas||("object"==typeof document?(t.canvas=document.createElement("canvas"),e.canvas.id="q5Canvas"+Q5._instanceCount,e.canvas.classList.add("q5Canvas")):e.noCanvas());let a=e.canvas;if(a.width=e.width=100,a.height=e.height=100,a&&"graphics"!=e._scope&&"image"!=e._scope){e._setupDone=!1;let r=e._parent;function o(){r??=document.getElementsByTagName("main")[0],r||(r=document.createElement("main"),document.body.append(r)),a.parent(r)}r&&"string"==typeof r&&(r=document.getElementById(r)),a.parent=t=>{function o(){e.frameCount>1&&(e._shouldResize=!0,e._adjustDisplay())}"string"==typeof t&&(t=document.getElementById(t)),t.append(a),"function"==typeof ResizeObserver?(e._ro&&e._ro.disconnect(),e._ro=new ResizeObserver(o),e._ro.observe(r)):e.frameCount||window.addEventListener("resize",o)},document.body?o():document.addEventListener("DOMContentLoaded",o)}function n(o,n){o??=window.innerWidth,n??=window.innerHeight;let r,i=function(){let t={};for(let a in e.ctx)"function"!=typeof e.ctx[a]&&(t[a]=e.ctx[a]);return delete t.canvas,t}();if(e.frameCount){r=new e._OffscreenCanvas(a.width,a.height),r.w=a.w,r.h=a.h,r.getContext("2d").drawImage(a,0,0)}a.width=Math.ceil(o*e._pixelDensity),a.height=Math.ceil(n*e._pixelDensity),a.w=o,a.h=n,a.hw=o/2,a.hh=n/2;for(let t in i)e.ctx[t]=i[t];e.ctx.scale(e._pixelDensity,e._pixelDensity),e.frameCount&&e.ctx.drawImage(r,0,0,r.w,r.h),e._da?e.flexibleCanvas(e._dau):(t.width=o,t.height=n),0!=e.frameCount&&e._adjustDisplay()}e._adjustDisplay=()=>{a.style&&(a.style.width=a.w+"px",a.style.height=a.h+"px")},e.createCanvas=function(o,n,r,i){if("webgl"==r)throw Error("webgl renderer is not supported in q5, use '2d'");"object"==typeof r&&(i=r),t.width=a.width=a.w=o||window.innerWidth,t.height=a.height=a.h=n||window.innerHeight,a.hw=o/2,a.hh=n/2,a.renderer="2d";let s=Object.assign({},Q5.canvasOptions);if(i&&Object.assign(s,i),t.ctx=t.drawingContext=a.getContext("2d",s),Object.assign(a,s),"rgb"==e._colorMode&&e.colorMode("rgb"),"image"!=e._scope&&(e._defaultStyle(),e._da=0),e.ctx.save(),"image"!=e._scope){let t=e.displayDensity();"graphics"==e._scope?t=this._pixelDensity:window.IntersectionObserver&&new IntersectionObserver((e=>{a.visible=e[0].isIntersecting})).observe(a),e.pixelDensity(Math.ceil(t))}else this._pixelDensity=1;return e.displayMode?e.displayMode():e._adjustDisplay(),a},e._createCanvas=e.createCanvas,"image"!=e._scope&&(e._defaultStyle=()=>{e.ctx.fillStyle="white",e.ctx.strokeStyle="black",e.ctx.lineCap="round",e.ctx.lineJoin="miter",e.ctx.textAlign="left"},e.resizeCanvas=(e,t)=>{e==a.w&&t==a.h||n(e,t)},e._pixelDensity=1,e.displayDensity=()=>window.devicePixelRatio,e.pixelDensity=t=>t&&t!=e._pixelDensity?(e._pixelDensity=t,n(a.w,a.h),t):e._pixelDensity,"image"!=e._scope&&(e.fullscreen=e=>{if(void 0===e)return document.fullscreenElement;e?document.body.requestFullscreen():document.body.exitFullscreen()},e.flexibleCanvas=(o=400)=>{o?(e._da=a.width/(o*e._pixelDensity),t.width=e._dau=o,t.height=a.h/a.w*o):e._da=0},e.translate=(t,a)=>{e._da&&(t*=e._da,a*=e._da),e.ctx.translate(t,a)},e.rotate=t=>{"degrees"==e._angleMode&&(t=e.radians(t)),e.ctx.rotate(t)},e.scale=(t,a)=>{a??=t,e.ctx.scale(t,a)},e.opacity=t=>e.ctx.globalAlpha=t,e.applyMatrix=(t,a,o,n,r,i)=>e.ctx.transform(t,a,o,n,r,i),e.shearX=t=>e.ctx.transform(1,0,e.tan(t),1,0,0),e.shearY=t=>e.ctx.transform(1,e.tan(t),0,1,0,0),e.resetMatrix=()=>{e.ctx.resetTransform(),e.ctx.scale(e._pixelDensity,e._pixelDensity)},e._styleNames=["_doStroke","_doFill","_strokeSet","_fillSet","_tint","_imageMode","_rectMode","_ellipseMode","_textFont","_textLeading","_leadingSet","_textSize","_textAlign","_textBaseline","_textStyle","_textWrap"],e._styles=[],e.push=e.pushMatrix=()=>{e.ctx.save();let t={};for(let a of e._styleNames)t[a]=e[a];e._styles.push(t)},e.pop=e.popMatrix=()=>{e.ctx.restore();let t=e._styles.pop();for(let a of e._styleNames)e[a]=t[a]},e.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},e.createGraphics=function(t,a,o){let n=new Q5("graphics");return o??={},o.alpha??=!0,n._createCanvas.call(e,t,a,o),n},window&&"graphics"!=e._scope&&window.addEventListener("resize",(()=>{e._shouldResize=!0,t.windowWidth=window.innerWidth,t.windowHeight=window.innerHeight,t.deviceOrientation=window.screen?.orientation?.type}))))},Q5.canvasOptions={alpha:!1,desynchronized:!1,colorSpace:"display-p3"},window.matchMedia&&matchMedia("(dynamic-range: high) and (color-gamut: p3)").matches?Q5.supportsHDR=!0:Q5.canvasOptions.colorSpace="srgb",Q5.modules.q2d_drawing=e=>{e.CHORD=0,e.PIE=1,e.OPEN=2,e.RADIUS="radius",e.CORNER="corner",e.CORNERS="corners",e.ROUND="round",e.SQUARE="butt",e.PROJECT="square",e.MITER="miter",e.BEVEL="bevel",e.CLOSE=1,e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.LANDSCAPE="landscape",e.PORTRAIT="portrait",e.BLEND="source-over",e.REMOVE="destination-out",e.ADD="lighter",e.DARKEST="darken",e.LIGHTEST="lighten",e.DIFFERENCE="difference",e.SUBTRACT="subtract",e.EXCLUSION="exclusion",e.MULTIPLY="multiply",e.SCREEN="screen",e.REPLACE="copy",e.OVERLAY="overlay",e.HARD_LIGHT="hard-light",e.SOFT_LIGHT="soft-light",e.DODGE="color-dodge",e.BURN="color-burn",e._doStroke=!0,e._doFill=!0,e._strokeSet=!1,e._fillSet=!1,e._ellipseMode=e.CENTER,e._rectMode=e.CORNER,e._curveDetail=20,e._curveAlpha=0;let t=!0,a=[];function o(){e._doFill&&e.ctx.fill(),e._doStroke&&e.ctx.stroke()}function n(t){let a=e._angleMode==e.DEGREES?360:e.TAU;return(t%=a)<0&&(t+=a),t}function r(t,a,r,i,s,l,c,d){if(!e._doFill&&!e._doStroke)return;let h=n(s),u=n(l);if(h>u&&([h,u]=[u,h]),0!=h||0!=u){if(e.ctx.beginPath(),r==i)e.ctx.arc(t,a,r/2,h,u);else{for(let o=0;o{t||(e._doStroke=!1),e._da&&(t*=e._da),e.ctx.lineWidth=t||1e-4},e.stroke=function(t){if(e._doStroke=!0,e._strokeSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._basicColors[t]&&(t=e.color(...e._basicColors[t])):t=e.color(...arguments),t.a<=0))return e._doStroke=!1;e.ctx.strokeStyle=t.toString()},e.noStroke=()=>e._doStroke=!1,e.fill=function(t){if(e._doFill=!0,e._fillSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._basicColors[t]&&(t=e.color(...e._basicColors[t])):t=e.color(...arguments),t.a<=0))return e._doFill=!1;e.ctx.fillStyle=t.toString()},e.noFill=()=>e._doFill=!1,e.blendMode=t=>e.ctx.globalCompositeOperation=t,e.strokeCap=t=>e.ctx.lineCap=t,e.strokeJoin=t=>e.ctx.lineJoin=t,e.ellipseMode=t=>e._ellipseMode=t,e.rectMode=t=>e._rectMode=t,e.curveDetail=t=>e._curveDetail=t,e.curveAlpha=t=>e._curveAlpha=t,e.curveTightness=t=>e._curveAlpha=t,e.clear=()=>{e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height)},e.background=function(t){if(t.canvas)return e.image(t,0,0,e.width,e.height);e.ctx.save(),e.ctx.resetTransform(),Q5.Color&&(t._q5Color||"string"==typeof t?e._basicColors[t]&&(t=e.color(...e._basicColors[t])):t=e.color(...arguments)),e.ctx.fillStyle=t.toString(),e.ctx.fillRect(0,0,e.canvas.width,e.canvas.height),e.ctx.restore()},e.line=(t,a,o,n)=>{e._doStroke&&(e._da&&(t*=e._da,a*=e._da,o*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.moveTo(t,a),e.ctx.lineTo(o,n),e.ctx.stroke())},e.arc=(t,a,o,n,i,s,l,c=25)=>{if(i==s)return e.ellipse(t,a,o,n);l??=e.PIE,e._ellipseMode==e.CENTER?r(t,a,o,n,i,s,l,c):e._ellipseMode==e.RADIUS?r(t,a,2*o,2*n,i,s,l,c):e._ellipseMode==e.CORNER?r(t+o/2,a+n/2,o,n,i,s,l,c):e._ellipseMode==e.CORNERS&&r((t+o)/2,(a+n)/2,o-t,n-a,i,s,l,c)},e.ellipse=(t,a,o,n)=>{n??=o,e._ellipseMode==e.CENTER?i(t,a,o,n):e._ellipseMode==e.RADIUS?i(t,a,2*o,2*n):e._ellipseMode==e.CORNER?i(t+o/2,a+n/2,o,n):e._ellipseMode==e.CORNERS&&i((t+o)/2,(a+n)/2,o-t,n-a)},e.circle=(t,a,n)=>{e._ellipseMode==e.CENTER?(e._da&&(t*=e._da,a*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.arc(t,a,n/2,0,e.TAU),o()):e.ellipse(t,a,n,n)},e.point=(t,a)=>{t.x&&(a=t.y,t=t.x),e._da&&(t*=e._da,a*=e._da),e.ctx.save(),e.ctx.beginPath(),e.ctx.arc(t,a,e.ctx.lineWidth/2,0,e.TAU),e.ctx.fillStyle=e.ctx.strokeStyle,e.ctx.fill(),e.ctx.restore()},e.rect=(t,a,o,n=o,r,i,l,c)=>{e._rectMode==e.CENTER?s(t-o/2,a-n/2,o,n,r,i,l,c):e._rectMode==e.RADIUS?s(t-o,a-n,2*o,2*n,r,i,l,c):e._rectMode==e.CORNER?s(t,a,o,n,r,i,l,c):e._rectMode==e.CORNERS&&s(t,a,o-t,n-a,r,i,l,c)},e.square=(t,a,o,n,r,i,s)=>e.rect(t,a,o,o,n,r,i,s),e.beginShape=()=>{l(),e.ctx.beginPath(),t=!0},e.beginContour=()=>{e.ctx.closePath(),l(),t=!0},e.endContour=()=>{l(),t=!0},e.vertex=(a,o)=>{e._da&&(a*=e._da,o*=e._da),l(),t?e.ctx.moveTo(a,o):e.ctx.lineTo(a,o),t=!1},e.bezierVertex=(t,a,o,n,r,i)=>{e._da&&(t*=e._da,a*=e._da,o*=e._da,n*=e._da,r*=e._da,i*=e._da),l(),e.ctx.bezierCurveTo(t,a,o,n,r,i)},e.quadraticVertex=(t,a,o,n)=>{e._da&&(t*=e._da,a*=e._da,o*=e._da,n*=e._da),l(),e.ctx.quadraticCurveTo(t,a,o,n)},e.bezier=(t,a,o,n,r,i,s,l)=>{e.beginShape(),e.vertex(t,a),e.bezierVertex(o,n,r,i,s,l),e.endShape()},e.triangle=(t,a,o,n,r,i)=>{e.beginShape(),e.vertex(t,a),e.vertex(o,n),e.vertex(r,i),e.endShape(e.CLOSE)},e.quad=(t,a,o,n,r,i,s,l)=>{e.beginShape(),e.vertex(t,a),e.vertex(o,n),e.vertex(r,i),e.vertex(s,l),e.endShape(e.CLOSE)},e.endShape=t=>{l(),t&&e.ctx.closePath(),o()},e.curveVertex=(o,n)=>{if(e._da&&(o*=e._da,n*=e._da),a.push([o,n]),a.length<4)return;let r=function(e,t,a,o,n,r,i,s,l,c){function d(e,t,a,o,n,r){let i=Math.pow(o-t,2)+Math.pow(n-a,2);return Math.pow(i,.5*r)+e}let h=[],u=d(0,e,t,a,o,c),_=d(u,a,o,n,r,c),g=d(_,n,r,i,s,c);for(let c=0;c0?(p[e]=1,p[e+1]=0):(p[e]=0,p[e+1]=1));let x=e*p[0]+a*p[1],m=t*p[0]+o*p[1],f=a*p[2]+n*p[3],v=o*p[2]+r*p[3],y=n*p[4]+i*p[5],w=r*p[4]+s*p[5],M=x*p[6]+f*p[7],C=m*p[6]+v*p[7],S=f*p[8]+y*p[9],b=v*p[8]+w*p[9],R=M*p[2]+S*p[3],E=C*p[2]+b*p[3];h.push([R,E])}return h}(...a.at(-4),...a.at(-3),...a.at(-2),...a.at(-1),e._curveDetail,e._curveAlpha);for(let a=0;a{e.beginShape(),e.curveVertex(t,a),e.curveVertex(o,n),e.curveVertex(r,i),e.curveVertex(s,l),e.endShape()},e.curvePoint=(e,t,a,o,n)=>{const r=n*n*n,i=n*n;return e*(-.5*r+i-.5*n)+t*(1.5*r-2.5*i+1)+a*(-1.5*r+2*i+.5*n)+o*(.5*r-.5*i)},e.bezierPoint=(e,t,a,o,n)=>{const r=1-n;return Math.pow(r,3)*e+3*Math.pow(r,2)*n*t+3*r*Math.pow(n,2)*a+Math.pow(n,3)*o},e.curveTangent=(e,t,a,o,n)=>{const r=n*n;return e*(-3*r/2+2*n-.5)+t*(9*r/2-5*n)+a*(-9*r/2+4*n+.5)+o*(3*r/2-n)},e.bezierTangent=(e,t,a,o,n)=>{const r=1-n;return 3*o*Math.pow(n,2)-3*a*Math.pow(n,2)+6*a*r*n-6*t*r*n+3*t*Math.pow(r,2)-3*e*Math.pow(r,2)},e.erase=function(t=255,a=255){e.ctx.save(),e.ctx.globalCompositeOperation="destination-out",e.ctx.fillStyle=`rgba(0, 0, 0, ${t/255})`,e.ctx.strokeStyle=`rgba(0, 0, 0, ${a/255})`},e.noErase=function(){e.ctx.globalCompositeOperation="source-over",e.ctx.restore()},e.inFill=(t,a)=>{const o=e._pixelDensity;return e.ctx.isPointInPath(t*o,a*o)},e.inStroke=(t,a)=>{const o=pixelDensity();return e.ctx.isPointInStroke(t*o,a*o)}},Q5.modules.q2d_image=(e,t)=>{e.createImage=(e,t,a)=>new Q5.Image(e,t,a),e._tint=null;let a=null,o=null,n=null;function r(t,a){a??=t||e.canvas.height,t??=e.canvas.width,null==o&&(o=new e._OffscreenCanvas(t,a).getContext("2d",{colorSpace:e.canvas.colorSpace})),o.canvas.width==t&&o.canvas.height==a||(o.canvas.width=t,o.canvas.height=a)}function i(t){o.clearRect(0,0,o.canvas.width,o.canvas.height),o.filter=t,o.drawImage(e.canvas,0,0),e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(o.canvas,0,0),e.ctx.restore()}e._softFilter=()=>{throw"Load q5-2d-soft-filters.js to use software filters."},e.filter=(t,a)=>{if(!e.ctx.filter)return e._softFilter(t,a);if(r(),"string"==typeof t)i(t);else if(t==Q5.THRESHOLD){a??=.5,a=Math.max(a,1e-5),i(`saturate(0%) brightness(${Math.floor(.5/a*100)}%) contrast(1000000%)`)}else t==Q5.GRAY?i("saturate(0%)"):t==Q5.OPAQUE?(o.fillStyle="black",o.fillRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(e.canvas,0,0),e.ctx.save(),e.ctx.resetTransform(),e.ctx.drawImage(o.canvas,0,0),e.ctx.restore()):t==Q5.INVERT?i("invert(100%)"):t==Q5.BLUR?i(`blur(${Math.ceil(a*e._pixelDensity/1)||1}px)`):e._softFilter(t,a)},e.resize=(a,n)=>{r(),o.drawImage(e.canvas,0,0),t.width=a,t.height=n,e.canvas.width=a*e._pixelDensity,e.canvas.height=n*e._pixelDensity,e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(o.canvas,0,0,e.canvas.width,e.canvas.height),e.ctx.restore()},e.trim=()=>{let t=e._pixelDensity||1,a=e.ctx.getImageData(0,0,e.width*t,e.height*t).data,o=e.width,n=0,r=e.height,i=0;for(let s=0;sn&&(n=l),si&&(i=s))}return r=Math.floor(r/t),i=Math.floor(i/t),o=Math.floor(o/t),n=Math.floor(n/t),e.get(o,r,n-o+1,i-r+1)},e.mask=t=>{e.ctx.save(),e.ctx.resetTransform();let a=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="destination-in",e.ctx.drawImage(t.canvas,0,0),e.ctx.globalCompositeOperation=a,e.ctx.restore()},e._save=async(e,t,a)=>{if(t=t||"untitled","jpg"==(a=a||"png")||"png"==a||"webp"==a)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+a});e=await new Promise((e=>{const a=new FileReader;a.onloadend=()=>e(a.result),a.readAsDataURL(t)}))}else e=e.toDataURL("image/"+a);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 o=document.createElement("a");o.href=e,o.download=t+"."+a,document.body.append(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(o.href)},e.save=(t,a,o)=>{if((!t||"string"==typeof t&&(!a||!o&&a.length<5))&&(o=a,a=t,t=e.canvas),o)return e._save(t,a,o);a?(a=a.split("."),e._save(t,a[0],a.at(-1))):e._save(t)},e.get=(t,a,o,n)=>{let r=e._pixelDensity||1;if(void 0!==t&&void 0===o){let o=e.ctx.getImageData(t*r,a*r,1,1).data;return new e.Color(o[0],o[1],o[2],o[3]/255)}t=(t||0)*r,a=(a||0)*r;let i=o=o||e.width,s=n=n||e.height;o*=r,n*=r;let l=e.createImage(o,n),c=e.ctx.getImageData(t,a,o,n);return l.ctx.putImageData(c,0,0),l._pixelDensity=r,l.width=i,l.height=s,l},e.set=(t,a,o)=>{if(o.canvas){let n=e._tint;return e._tint=null,e.image(o,t,a),void(e._tint=n)}e.pixels.length||e.loadPixels();let n=e._pixelDensity||1;for(let r=0;r{a=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height),t.pixels=a.data},e.updatePixels=()=>{null!=a&&e.ctx.putImageData(a,0,0)},e._tinted=function(t){let a=t.a;t.a=255,r(),o.clearRect(0,0,o.canvas.width,o.canvas.height),o.fillStyle=t.toString(),o.fillRect(0,0,o.canvas.width,o.canvas.height),o.globalCompositeOperation="multiply",o.drawImage(e.ctx.canvas,0,0),o.globalCompositeOperation="source-over",e.ctx.save(),e.ctx.resetTransform();let n=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="source-in",e.ctx.drawImage(o.canvas,0,0),e.ctx.globalCompositeOperation=n,e.ctx.restore(),o.globalAlpha=a/255,o.clearRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(e.ctx.canvas,0,0),o.globalAlpha=1,e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.ctx.canvas.width,e.ctx.canvas.height),e.ctx.drawImage(o.canvas,0,0),e.ctx.restore()},e.smooth=()=>e.ctx.imageSmoothingEnabled=!0,e.noSmooth=()=>e.ctx.imageSmoothingEnabled=!1,"image"!=e._scope&&(e.saveCanvas=e.canvas.save=e.save,e.tint=function(t){e._tint=t._q5Color?t:e.color(...arguments)},e.noTint=()=>e._tint=null,e.imageMode=t=>e._imageMode=t,e.image=(t,a,o,r,i,s=0,l=0,c,d)=>{e._da&&(a*=e._da,o*=e._da,r*=e._da,i*=e._da,s*=e._da,l*=e._da,c*=e._da,d*=e._da);let h=t.canvas||t;var u,_;Q5._createNodeJSCanvas&&(h=h.context.canvas),t.canvas&&null!=e._tint&&(u=t.canvas.width,_=t.canvas.height,_??=u||e.canvas.height,u??=e.canvas.width,null==n&&(n=new e._OffscreenCanvas(u,_).getContext("2d",{colorSpace:e.canvas.colorSpace})),n.canvas.width==u&&n.canvas.height==_||(n.canvas.width=u,n.canvas.height=_),n.drawImage(t.canvas,0,0),t._tinted(e._tint)),r??=t.width||t.videoWidth,i??=t.height||t.videoHeight,"center"==e._imageMode&&(a-=.5*r,o-=.5*i);let g=t._pixelDensity||1;c?c*=g:c=h.width||h.videoWidth,d?d*=g:d=h.height||h.videoHeight,e.ctx.drawImage(h,s*g,l*g,c,d,a,o,r,i),function(){if(!t._q5||!e._tint)return;let a=t.ctx;a.save(),a.resetTransform(),a.clearRect(0,0,a.canvas.width,a.canvas.height),a.drawImage(n.canvas,0,0),a.restore()}()},e.loadImage=function(a,o,n){if(a.canvas)return a;if("gif"==a.slice(-3).toLowerCase())throw"In q5, GIFs are not supported due to their impact on performance. Use a video or p5play animation instead.";t._preloadCount++;let r=[...arguments].at(-1);n="object"!=typeof r||r;let i=e.createImage(1,1,n.alpha),s=i.ctx;if(Q5._nodejs&&global.CairoCanvas)CairoCanvas.loadImage(a).then((e=>{i.width=s.canvas.width=e.width,i.height=s.canvas.height=e.height,s.drawImage(e,0,0),t._preloadCount--,o&&o(i)})).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=a,e.crossOrigin="Anonymous",e._pixelDensity=1,e.onload=()=>{i.width=s.canvas.width=e.naturalWidth,i.height=s.canvas.height=e.naturalHeight,s.drawImage(e,0,0),t._preloadCount--,o&&o(i)},e.onerror=e=>{throw t._preloadCount--,e}}return i})},Q5.imageModules=["q2d_canvas","q2d_image"];class _Q5Image{constructor(e,t,a){let o=this;o._scope="image",o.canvas=o.ctx=o.drawingContext=null,o.pixels=[];for(let e of Q5.imageModules)Q5.modules[e](o,o);delete this.createCanvas,a??={},a.alpha??=!0,this._createCanvas(e,t,"2d",a),this._loop=!1}get w(){return this.width}get h(){return this.height}}Q5.Image??=_Q5Image,Q5.THRESHOLD=1,Q5.GRAY=2,Q5.OPAQUE=3,Q5.INVERT=4,Q5.POSTERIZE=5,Q5.DILATE=6,Q5.ERODE=7,Q5.BLUR=8,Q5.modules.q2d_soft_filters=e=>{let t=null;function a(){let a=e.canvas.width*e.canvas.height*4;t&&a==t.length||(t=new Uint8ClampedArray(a))}e._softFilter=(o,n)=>{e._filters||(e._filters=[],e._filters[Q5.THRESHOLD]=(e,t)=>{void 0===t?t=127.5:t*=255;for(let a=0;a=t?255:0}},e._filters[Q5.GRAY]=e=>{for(let t=0;t{for(let t=0;t{for(let t=0;t{let a=t-1;for(let o=0;o>8)/a,e[o+1]=255*(e[o+1]*t>>8)/a,e[o+2]=255*(e[o+2]*t>>8)/a},e._filters[Q5.DILATE]=o=>{a(),t.set(o);let[n,r]=[e.canvas.width,e.canvas.height];for(let e=0;e{a(),t.set(o);let[n,r]=[e.canvas.width,e.canvas.height];for(let e=0;e{n=n||1,n=Math.floor(n*e._pixelDensity),a(),t.set(o);let r=2*n+1,i=function(e){let t=new Float32Array(e),a=.3*n+.8,o=a*a*2;for(let n=0;n{e.NORMAL="normal",e.ITALIC="italic",e.BOLD="bold",e.BOLDITALIC="italic bold",e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.BASELINE="alphabetic",e._textFont="sans-serif",e._textSize=12,e._textLeading=15,e._textLeadDiff=3,e._textStyle="normal",e.loadFont=(e,a)=>{t._preloadCount++;let o=e.split("/"),n=o[o.length-1].split(".")[0].replace(" ",""),r=new FontFace(n,"url("+e+")");return document.fonts.add(r),r.load().then((()=>{t._preloadCount--,a&&a(n)})),n},e.textFont=t=>e._textFont=t,e.textSize=t=>{if(void 0===t)return e._textSize;e._da&&(t*=e._da),e._textSize=t,e._leadingSet||(e._textLeading=1.25*t,e._textLeadDiff=e._textLeading-t)},e.textLeading=t=>{if(void 0===t)return e._textLeading;e._da&&(t*=e._da),e._textLeading=t,e._textLeadDiff=t-e._textSize,e._leadingSet=!0},e.textStyle=t=>e._textStyle=t,e.textAlign=(t,a)=>{e.ctx.textAlign=t,a&&(e.ctx.textBaseline=a==e.CENTER?"middle":a)},e.textWidth=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).width),e.textAscent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxAscent),e.textDescent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxDescent),e._textCache=!!Q5.Image,e._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[o,n]of this.entries())n.lastAccessed(a&&(e._tic.maxSize=a),void 0!==t&&(e._textCache=t),e._textCache),e._genTextImageKey=(t,a,o)=>t.slice(0,200)+e._textStyle+e._textSize+e._textFont+(e._doFill?e.ctx.fillStyle:"")+"_"+(e._doStroke&&e._strokeSet?e.ctx.lineWidth+e.ctx.strokeStyle+"_":"")+(a||"")+(o?"x"+o:""),e.createTextImage=(t,a,o)=>{let n=e._textCache;e._textCache=!0,e._genTextImage=!0,e.text(t,0,0,a,o),e._genTextImage=!1;let r=e._genTextImageKey(t,a,o);return e._textCache=n,e._tic.get(r)},e.text=(t,a,o,n,r)=>{if(void 0===t)return;if(t=t.toString(),e._da&&(a*=e._da,o*=e._da),!e._doFill&&!e._doStroke)return;let i,s,l,c,d,h,u,_,g=1,p=e.ctx.getTransform(),x=e._genTextImage||e._textCache&&(0!=p.b||0!=p.c);if(x){if(c=e._genTextImageKey(t,n,r),s=e._tic.get(c),s&&!e._genTextImage)return void e.textImage(s,a,o);l=e.createGraphics.call(e,1,1),i=l.ctx,g=e._pixelDensity}else i=e.ctx,d=a,h=o;i.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`;let m=t.split("\n");if(x){d=0,h=e._textLeading*m.length;let a=i.measureText(" ");u=a.fontBoundingBoxAscent,_=a.fontBoundingBoxDescent,r??=h+_,l.resizeCanvas(Math.ceil(i.measureText(t).width),Math.ceil(r)),i.fillStyle=e.ctx.fillStyle,i.strokeStyle=e.ctx.strokeStyle,i.lineWidth=e.ctx.lineWidth}let f=i.fillStyle;e._fillSet||(i.fillStyle="black");for(let t=0;tr));t++);e._fillSet||(i.fillStyle=f),x&&(s=l.get(),s._ascent=u,s._descent=_,e._tic.set(c,s),e._genTextImage||e.textImage(s,a,o))},e.textImage=(t,a,o)=>{let n=e._imageMode;e._imageMode="corner","center"==e.ctx.textAlign?a-=.5*t.width:"right"==e.ctx.textAlign&&(a-=t.width),"alphabetic"==e.ctx.textBaseline&&(o-=e._textLeading),"middle"==e.ctx.textBaseline?o-=t._descent+.5*t._ascent+e._textLeadDiff:"bottom"==e.ctx.textBaseline?o-=t._ascent+t._descent+e._textLeadDiff:"top"==e.ctx.textBaseline&&(o-=t._descent+e._textLeadDiff),e.image(t,a,o),e._imageMode=n},e.nf=(e,t,a)=>{let o=e<0,n=(e=Math.abs(e)).toFixed(a).split(".");n[0]=n[0].padStart(t,"0");let r=n.join(".");return o&&(r="-"+r),r}},Q5.modules.ai=e=>{e.askAI=(e="")=>{throw Error("Ask AI ✨ "+e)},e._aiErrorAssistance=async e=>{let t=e.message?.includes("Ask AI ✨");if(t||console.error(e),Q5.disableFriendlyErrors)return;!t&&Q5.errorTolerant||noLoop();let a=e.stack?.split("\n");if(!e.stack||a.length<=1)return;let o=1,n="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(o=0,n="@");a[o].indexOf("q5.js:")>=0;)o++;let r=a[o].split(n).at(-1);r=r.split(":");let i=parseInt(r.at(-2));t&&i++;let s=r.slice(0,-2).join(":"),l=s.split("/").at(-1);try{let a=(await(await fetch(s)).text()).split("\n"),o=a[i-1].trim(),n="",r=1;for(;n.length<1600&&(i-r>=0&&(n=a[i-r].trim()+"\n"+n),i+r10?e.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(t?"":"%0A%0A"+encodeURIComponent(e.name+": "+e.message))+"%0A%0ALine%3A+"+encodeURIComponent(o)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(n);t||console.log("Error in "+l+" on line "+i+":\n\n"+o),console.warn("Ask AI ✨ "+c),t&&window.open(c,"_blank")}catch(e){}}},Q5.modules.color=(e,t)=>{e.RGB=e.RGBA=e._colorMode="rgb",Q5.supportsHDR?e.Color=Q5.ColorRGBA_P3:e.Color=Q5.ColorRGBA,e.colorMode=a=>{e._colorMode=a,"oklch"==a?t.Color=Q5.ColorOKLCH:"rgb"==a?"srgb"==e.canvas.colorSpace?t.Color=Q5.ColorRGBA:t.Color=Q5.ColorRGBA_P3:"srgb"==a&&(t.Color=Q5.ColorRGBA,e._colorMode="rgb")},e._basicColors={aqua:[0,255,255],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],crimson:[220,20,60],cyan:[0,255,255],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]},e.color=function(t,a,o,n){let r=e.Color;if(t._q5Color)return new r(...t.levels);let i=arguments;if(1==i.length){if("string"==typeof t)return"#"==t[0]?new r(parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16),9!=t.length?null:parseInt(t.slice(7,9),16)):e._basicColors[t]?new r(...e._basicColors[t]):new r(0,0,0);if(Array.isArray(t))return new r(...t)}if("rgb"==e._colorMode){if(1==i.length)return new r(t,t,t);if(2==i.length)return new r(t,t,t,a);if(3==i.length)return new r(t,a,o);if(4==i.length)return new r(t,a,o,n)}},e.red=e=>e.r,e.green=e=>e.g,e.blue=e=>e.b,e.alpha=e=>e.a,e.lightness=e=>100*(.2126*e.r+.7152*e.g+.0722*e.b)/255,e.lerpColor=(t,a,o)=>{if("rgb"==e._colorMode)return new e.Color(e.constrain(e.lerp(t.r,a.r,o),0,255),e.constrain(e.lerp(t.g,a.g,o),0,255),e.constrain(e.lerp(t.b,a.b,o),0,255),e.constrain(e.lerp(t.a,a.a,o),0,255));{let n=a.h-t.h;n>180&&(n-=360),n<-180&&(n+=360);let r=t.h+o*n;return r<0&&(r+=360),r>360&&(r-=360),new e.Color(e.constrain(e.lerp(t.l,a.l,o),0,100),e.constrain(e.lerp(t.c,a.c,o),0,100),r,e.constrain(e.lerp(t.a,a.a,o),0,255))}}},Q5.Color=class{constructor(){this._q5Color=!0}},Q5.ColorOKLCH=class extends Q5.Color{constructor(e,t,a,o){super(),this.l=e,this.c=t,this.h=a,this.a=o??1}toString(){return`color(oklch ${this.l} ${this.c} ${this.h} / ${this.a})`}},Q5.ColorRGBA=class extends Q5.Color{constructor(e,t,a,o){super(),this.r=e,this.g=t,this.b=a,this.a=o??255}setRed(e){this.r=e}setGreen(e){this.g=e}setBlue(e){this.b=e}setAlpha(e){this.a=e}get levels(){return[this.r,this.g,this.b,this.a]}toString(){return`rgb(${this.r} ${this.g} ${this.b} / ${this.a/255})`}},Q5.ColorRGBA_P3=class extends Q5.ColorRGBA{constructor(e,t,a,o){super(e,t,a,o),this._edited=!0}get r(){return this._r}set r(e){this._r=e,this._edited=!0}get g(){return this._g}set g(e){this._g=e,this._edited=!0}get b(){return this._b}set b(e){this._b=e,this._edited=!0}get a(){return this._a}set a(e){this._a=e,this._edited=!0}toString(){if(this._edited){let e=(this._r/255).toFixed(3),t=(this._g/255).toFixed(3),a=(this._b/255).toFixed(3),o=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${a} / ${o})`,this._edited=!1}return this._css}},Q5.modules.display=e=>{if(!e.canvas||"graphics"==e._scope)return;let t=e.canvas;0!=Q5._instanceCount||Q5._nodejs||document.head.insertAdjacentHTML("beforeend",""),e._adjustDisplay=()=>{let a=t.style,o=t.parentElement;a&&o&&t.displayMode&&("pixelated"==t.renderQuality&&(t.classList.add("q5-pixelated"),e.pixelDensity(1),e.noSmooth&&e.noSmooth(),e.textFont&&e.textFont("monospace")),"normal"==t.displayMode?(o.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),a.width=t.w*t.displayScale+"px",a.height=t.h*t.displayScale+"px"):(o.classList.add("q5-"+t.displayMode),o=o.getBoundingClientRect(),t.w/t.h>o.width/o.height?("centered"==t.displayMode?(a.width=t.w*t.displayScale+"px",a.maxWidth="100%"):a.width="100%",a.height="auto",a.maxHeight=""):(a.width="auto",a.maxWidth="","centered"==t.displayMode?(a.height=t.h*t.displayScale+"px",a.maxHeight="100%"):a.height="100%")))},e.displayMode=(a="normal",o="default",n=1)=>{"string"==typeof n&&(n=parseFloat(n.slice(1))),Object.assign(t,{displayMode:a,renderQuality:o,displayScale:n}),e._adjustDisplay()}},Q5.modules.input=(e,t)=>{if("graphics"==e._scope)return;e.mouseX=0,e.mouseY=0,e.pmouseX=0,e.pmouseY=0,e.touches=[],e.mouseButton=null,e.keyIsPressed=!1,e.mouseIsPressed=!1,e.key=null,e.keyCode=null,e.UP_ARROW=38,e.DOWN_ARROW=40,e.LEFT_ARROW=37,e.RIGHT_ARROW=39,e.SHIFT=16,e.TAB=9,e.BACKSPACE=8,e.ENTER=e.RETURN=13,e.ALT=e.OPTION=18,e.CONTROL=17,e.DELETE=46,e.ESCAPE=27,e.ARROW="default",e.CROSS="crosshair",e.HAND="pointer",e.MOVE="move",e.TEXT="text";let a={},o=[e.LEFT,e.CENTER,e.RIGHT],n=e.canvas;function r(t){const a=e.canvas.getBoundingClientRect(),o=e.canvas.scrollWidth/e.width||1,n=e.canvas.scrollHeight/e.height||1;return{x:(t.clientX-a.left)/o,y:(t.clientY-a.top)/n,id:t.identifier}}if(e._startAudio=()=>{e.getAudioContext&&"suspended"==e.getAudioContext()?.state&&e.userStartAudio()},e._updateMouse=a=>{if(a.changedTouches)return;let o=e.canvas.getBoundingClientRect(),n=e.canvas.scrollWidth/e.width||1,r=e.canvas.scrollHeight/e.height||1;t.mouseX=(a.clientX-o.left)/n,t.mouseY=(a.clientY-o.top)/r},e._onmousedown=a=>{e._startAudio(),e._updateMouse(a),t.mouseIsPressed=!0,t.mouseButton=o[a.button],e.mousePressed(a)},e._onmousemove=t=>{e._updateMouse(t),e.mouseIsPressed?e.mouseDragged(t):e.mouseMoved(t)},e._onmouseup=a=>{e._updateMouse(a),t.mouseIsPressed=!1,e.mouseReleased(a)},e._onclick=a=>{e._updateMouse(a),t.mouseIsPressed=!0,e.mouseClicked(a),t.mouseIsPressed=!1},n.addEventListener("mousedown",(t=>e._onmousedown(t))),n.addEventListener("mouseup",(t=>e._onmouseup(t))),n.addEventListener("click",(t=>e._onclick(t))),e.cursor=(t,a,o)=>{let n="";t.includes(".")&&(t=`url("${t}")`,n=", auto"),void 0!==a&&(t+=" "+a+" "+o),e.canvas.style.cursor=t+n},e.noCursor=()=>{e.canvas.style.cursor="none"},e.requestPointerLock=document.body.requestPointerLock,e.exitPointerLock=document.exitPointerLock,e._onkeydown=o=>{o.repeat||(e._startAudio,t.keyIsPressed=!0,t.key=o.key,t.keyCode=o.keyCode,a[e.keyCode]=a[e.key]=!0,e.keyPressed(o),1==o.key.length&&e.keyTyped(o))},e._onkeyup=o=>{t.keyIsPressed=!1,t.key=o.key,t.keyCode=o.keyCode,a[e.keyCode]=a[e.key]=!1,e.keyReleased(o)},e.keyIsDown=e=>!!a[e],e._ontouchstart=a=>{e._startAudio(),t.touches=[...a.touches].map(r),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,t.mouseIsPressed=!0,t.mouseButton=e.LEFT,e.mousePressed(a)||a.preventDefault()),e.touchStarted(a)||a.preventDefault()},e._ontouchmove=a=>{t.touches=[...a.touches].map(r),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,e.mouseDragged(a)||a.preventDefault()),e.touchMoved(a)||a.preventDefault()},e._ontouchend=a=>{t.touches=[...a.touches].map(r),e._isTouchAware||e.touches.length||(t.mouseIsPressed=!1,e.mouseReleased(a)||a.preventDefault()),e.touchEnded(a)||a.preventDefault()},n.addEventListener("touchstart",(t=>e._ontouchstart(t))),n.addEventListener("touchmove",(t=>e._ontouchmove(t))),n.addEventListener("touchcancel",(t=>e._ontouchend(t))),n.addEventListener("touchend",(t=>e._ontouchend(t))),window){let t=window.addEventListener;t("mousemove",(t=>e._onmousemove(t)),!1),t("keydown",(t=>e._onkeydown(t)),!1),t("keyup",(t=>e._onkeyup(t)),!1)}},Q5.modules.math=(e,t)=>{function a(){let e,t,a=4294967295;return{setSeed(o){e=t=(o??Math.random()*a)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/a)}}e.DEGREES="degrees",e.RADIANS="radians",e.PI=Math.PI,e.HALF_PI=Math.PI/2,e.QUARTER_PI=Math.PI/4,e.abs=Math.abs,e.ceil=Math.ceil,e.exp=Math.exp,e.floor=Math.floor,e.loge=Math.log,e.mag=Math.hypot,e.max=Math.max,e.min=Math.min,e.round=Math.round,e.pow=Math.pow,e.sqrt=Math.sqrt,e.SHR3=1,e.LCG=2,e.angleMode=t=>e._angleMode=t,e._DEGTORAD=Math.PI/180,e._RADTODEG=180/Math.PI,e.degrees=t=>t*e._RADTODEG,e.radians=t=>t*e._DEGTORAD,e.map=(e,t,a,o,n,r)=>{let i=o+1*(e-t)/(a-t)*(n-o);return r?oe*(1-a)+t*a,e.constrain=(e,t,a)=>Math.min(Math.max(e,t),a),e.dist=function(){let e=arguments;return 4==e.length?Math.hypot(e[0]-e[2],e[1]-e[3]):Math.hypot(e[0]-e[3],e[1]-e[4],e[2]-e[5])},e.norm=(t,a,o)=>e.map(t,a,o,0,1),e.sq=e=>e*e,e.fract=e=>e-Math.floor(e),e.sin=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.sin(t)),e.cos=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.cos(t)),e.tan=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.tan(t)),e.asin=t=>{let a=Math.asin(t);return"degrees"==e._angleMode&&(a=e.degrees(a)),a},e.acos=t=>{let a=Math.acos(t);return"degrees"==e._angleMode&&(a=e.degrees(a)),a},e.atan=t=>{let a=Math.atan(t);return"degrees"==e._angleMode&&(a=e.degrees(a)),a},e.atan2=(t,a)=>{let o=Math.atan2(t,a);return"degrees"==e._angleMode&&(o=e.degrees(o)),o};let o=a();o.setSeed(),e.randomSeed=e=>o.setSeed(e),e.random=(e,t)=>void 0===e?o.rand():"number"==typeof e?void 0!==t?o.rand()*(t-e)+e:o.rand()*e:e[Math.trunc(e.length*o.rand())],e.randomGenerator=t=>{t==e.LCG?o=function(){const e=4294967296;let t,a;return{setSeed(o){a=t=(o??Math.random()*e)>>>0},getSeed:()=>t,rand:()=>(a=(1664525*a+1013904223)%e,a/e)}}():t==e.SHR3&&(o=a()),o.setSeed()};var n=new function(){var e,t,a,n=new Array(128),r=new Array(256),i=new Array(128),s=new Array(128),l=new Array(256),c=new Array(256),d=()=>4294967296*o.rand()-2147483648,h=()=>.5+2.328306e-10*(d()|0),u=()=>{for(var t,o,r,l,c=3.44262;;){if(t=a*i[e],0==e){do{r=h(),l=h(),t=.2904764*-Math.log(r),o=-Math.log(l)}while(o+o0?c+t:-c-t}if(s[e]+h()*(s[e-1]-s[e]){for(var a;;){if(0==e)return 7.69711-Math.log(h());if(a=t*l[e],c[e]+h()*(c[e-1]-c[e])(a=d(),e=127&a,Math.abs(a)(t=d()>>>0){var e,t,a=2147483648,o=4294967296,d=3.442619855899,h=d,u=.00991256303526217,_=7.697117470131487,g=_,p=.003949659822581572;for(e=u/Math.exp(-.5*d*d),n[0]=Math.floor(d/e*a),n[1]=0,i[0]=e/a,i[127]=d/a,s[0]=1,s[127]=Math.exp(-.5*d*d),t=126;t>=1;t--)d=Math.sqrt(-2*Math.log(u/d+Math.exp(-.5*d*d))),n[t+1]=Math.floor(d/h*a),h=d,s[t]=Math.exp(-.5*d*d),i[t]=d/a;for(e=p/Math.exp(-_),r[0]=Math.floor(_/e*o),r[1]=0,l[0]=e/o,l[255]=_/o,c[0]=1,c[255]=Math.exp(-_),t=254;t>=1;t--)_=-Math.log(p/_+Math.exp(-_)),r[t+1]=Math.floor(_/g*o),g=_,c[t]=Math.exp(-_),l[t]=_/o}};let r;n.hasInit=!1,e.randomGaussian=(e,t)=>(n.hasInit||(n.zigset(),n.hasInit=!0),n.RNOR()*t+e),e.randomExponential=()=>(n.hasInit||(n.zigset(),n.hasInit=!0),n.REXP()),e.PERLIN="perlin",e.SIMPLEX="simplex",e.BLOCKY="blocky",e.Noise=Q5.PerlinNoise,e.noiseMode=e=>{t.Noise=Q5[e[0].toUpperCase()+e.slice(1)+"Noise"],r=null},e.noiseSeed=t=>{r=new e.Noise(t)},e.noise=(t=0,a=0,o=0)=>(r??=new e.Noise,r.noise(t,a,o)),e.noiseDetail=(t,a)=>{r??=new e.Noise,t>0&&(r.octaves=t),a>0&&(r.falloff=a)}},Q5.Noise=class{constructor(){}},Q5.PerlinNoise=class extends Q5.Noise{constructor(e){super(),this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.octaves=1,this.falloff=.5,this.p=null==e?Array.from({length:256},(()=>Math.floor(256*Math.random()))):this.seedPermutation(e),this.p=this.p.concat(this.p)}seedPermutation(e){let t,a,o=[];for(let e=0;e<256;e++)o[e]=e;for(let n=255;n>0;n--)t=(e=16807*e%2147483647)%(n+1),a=o[n],o[n]=o[t],o[t]=a;return o}dot(e,t,a,o){return e[0]*t+e[1]*a+e[2]*o}mix(e,t,a){return(1-a)*e+a*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,a){let o=this,n=0,r=1,i=1,s=0;for(let l=0;l{e.loadSound=(a,o)=>{t._preloadCount++,e.aud??=new window.AudioContext;let n=new Audio(a);return n.addEventListener("canplaythrough",(()=>{t._preloadCount--,o&&o(n)})),n.load(),n.setVolume=e=>n.volume=e,n.setLoop=e=>n.loop=e,n.panner=e.aud.createStereoPanner(),n.source=e.aud.createMediaElementSource(n),n.source.connect(n.panner),n.panner.connect(e.aud.destination),Object.defineProperty(n,"pan",{get:()=>n.panner.pan.value,set:e=>n.panner.pan.value=e}),n.setPan=e=>n.pan=e,n},e.getAudioContext=()=>e.aud,e.userStartAudio=()=>e.aud.resume()},Q5.modules.util=(e,t)=>{e._loadFile=(e,a,o)=>{t._preloadCount++;let n={};return fetch(e).then((e=>"json"==o?e.json():"text"==o?e.text():void 0)).then((e=>{t._preloadCount--,Object.assign(n,e),a&&a(e)})),n},e.loadStrings=(t,a)=>e._loadFile(t,a,"text"),e.loadJSON=(t,a)=>e._loadFile(t,a,"json"),"object"==typeof localStorage&&(e.storeItem=localStorage.setItem,e.getItem=localStorage.getItem,e.removeItem=localStorage.removeItem,e.clearStorage=localStorage.clear),e.year=()=>(new Date).getFullYear(),e.day=()=>(new Date).getDay(),e.hour=()=>(new Date).getHours(),e.minute=()=>(new Date).getMinutes(),e.second=()=>(new Date).getSeconds()},Q5.modules.vector=e=>{e.createVector=(t,a,o)=>new Q5.Vector(t,a,o,e)},Q5.Vector=class{constructor(e,t,a,o){this.x=e||0,this.y=t||0,this.z=a||0,this._$=o||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(){this._cnsq=this.x*this.x+this.y*this.y+this.z*this.z,this._cn=Math.sqrt(this._cnsq)}add(){let e=this._arg2v(...arguments);return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}rem(){let e=this._arg2v(...arguments);return this.x%=e.x,this.y%=e.y,this.z%=e.z,this}sub(){let e=this._arg2v(...arguments);return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}mult(){let e=this._arg2v(...arguments);return this.x*=e.x,this.y*=e.y,this.z*=e.z,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}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,o=this.z-e.z;return Math.sqrt(t*t+a*a+o*o)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,a=this.z*e.x-this.x*e.z,o=this.x*e.y-this.y*e.x;return this.x=t,this.y=a,this.z=o,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),o=this.x*t-this.y*a,n=this.x*a+this.y*t;return this.x=o,this.y=n,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}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)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,o)=>(new Q5.Vector)[e](t,a,o); +function Q5(e,t){let a,o=this;if(o._q5=!0,o._scope=e,o._parent=t,o._preloadCount=0,e??="global","auto"==e){if(!window.setup&&!window.draw)return;e="global"}"global"==e&&(Q5._hasGlobal=o._isGlobal=!0,a=Q5._nodejs?global:window);let n=new Proxy(o,{set:(e,t,n)=>(o[t]=n,o._isGlobal&&(a[t]=n),!0)});o.canvas=o.ctx=o.drawingContext=null,o.pixels=[];let r=null;o.frameCount=0,o.deltaTime=16,o._targetFrameRate=0,o._targetFrameDuration=16.666666666666668,o._frameRate=o._fps=60,o._loop=!0;let i=0;function s(e){let t=e||performance.now();if(o._lastFrameTime??=t-o._targetFrameDuration,o._shouldResize&&(o.windowResized(),o._shouldResize=!1),o._loop)r=l(s);else if(o.frameCount&&!o._redraw)return;if(r&&o.frameCount){if(t-o._lastFrameTimeperformance.now()-i,o.noCanvas=()=>{o.canvas?.remove&&o.canvas.remove(),o.canvas=0,n.ctx=n.drawingContext=0},window&&(o.windowWidth=window.innerWidth,o.windowHeight=window.innerHeight,o.deviceOrientation=window.screen?.orientation?.type),o._incrementPreload=()=>n._preloadCount++,o._decrementPreload=()=>n._preloadCount--,o.noLoop=()=>{o._loop=!1,r=null},o.loop=()=>{o._loop=!0,null==r&&s()},o.redraw=(e=1)=>{o._redraw=!0;for(let t=0;t{o.noLoop(),o.canvas.remove()},o.frameRate=e=>(e&&(o._targetFrameRate=e,o._targetFrameDuration=1e3/e),o._frameRate),o.getTargetFrameRate=()=>o._targetFrameRate,o.getFPS=()=>o._fps,o.Element=function(e){this.elt=e},o._elements=[],o.TWO_PI=o.TAU=2*Math.PI,o.log=o.print=console.log,o.describe=()=>{};for(let e in Q5.modules)Q5.modules[e](o,n);for(let e in Q5)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&(o[e]=Q5[e]);"global"==e&&(Object.assign(Q5,o),delete Q5.Q5);for(let e of Q5.prototype._methods.init)e.call(o);for(let[e,t]of Object.entries(Q5.prototype))"_"!=e[0]&&"function"==typeof o[e]&&(o[e]=t.bind(o));if("global"==e){let e=Object.getOwnPropertyNames(o);for(let t of e)"_"!=t[0]&&(a[t]=o[t])}if("function"==typeof e&&e(o),"graphics"==e)return;Q5._instanceCount++;let l=window.requestAnimationFrame||function(e){const t=o._lastFrameTime+o._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},c=a||o;o._isTouchAware=c.touchStarted||c.touchMoved||c.mouseReleased;let d=c.preload,h=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of h)c[e]?o._isGlobal&&(o[e]=()=>{try{c[e]()}catch(e){o._aiErrorAssistance?o._aiErrorAssistance(e):console.error(e)}}):o[e]=()=>{};async function u(){if(o._startDone=!0,o._preloadCount>0)return l(u);i=performance.now(),await o.setup(),o.frameCount||(null===o.ctx&&o.createCanvas(100,100),o._setupDone=!0,o.ctx&&o.resetMatrix(),l(s))}(o.setup||o.draw)&&(o._startDone=!1,arguments.length&&"namespace"!=e||d?(o.preload(),u()):(c.preload=o.preload=()=>{o._startDone||u()},setTimeout(o.preload,32)))}Q5.modules={},Q5._nodejs="object"==typeof process,Q5._instanceCount=0,Q5._friendlyError=(e,t)=>{throw Error(t+": "+e)},Q5._validateParameters=()=>!0,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._nodejs?global.p5??=global.Q5=Q5:"object"==typeof window?window.p5??=window.Q5=Q5:window=0,"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{Q5._hasGlobal||new Q5("auto")})),Q5.modules.q2d_canvas=(e,t)=>{e._OffscreenCanvas=window.OffscreenCanvas||function(){return document.createElement("canvas")},Q5._nodejs?Q5._createNodeJSCanvas&&(t.canvas=Q5._createNodeJSCanvas(100,100)):"image"!=e._scope&&"graphics"!=e._scope||(t.canvas=new e._OffscreenCanvas(100,100)),e.canvas||("object"==typeof document?(t.canvas=document.createElement("canvas"),e.canvas.id="q5Canvas"+Q5._instanceCount,e.canvas.classList.add("q5Canvas")):e.noCanvas());let a=e.canvas;if(a.width=e.width=100,a.height=e.height=100,a&&"graphics"!=e._scope&&"image"!=e._scope){e._setupDone=!1;let r=e._parent;function o(){r??=document.getElementsByTagName("main")[0],r||(r=document.createElement("main"),document.body.append(r)),a.parent(r)}r&&"string"==typeof r&&(r=document.getElementById(r)),a.parent=t=>{function o(){e.frameCount>1&&(e._shouldResize=!0,e._adjustDisplay())}"string"==typeof t&&(t=document.getElementById(t)),t.append(a),"function"==typeof ResizeObserver?(e._ro&&e._ro.disconnect(),e._ro=new ResizeObserver(o),e._ro.observe(r)):e.frameCount||window.addEventListener("resize",o)},document.body?o():document.addEventListener("DOMContentLoaded",o)}function n(o,n){o??=window.innerWidth,n??=window.innerHeight;let r,i=function(){let t={};for(let a in e.ctx)"function"!=typeof e.ctx[a]&&(t[a]=e.ctx[a]);return delete t.canvas,t}();if(e.frameCount){r=new e._OffscreenCanvas(a.width,a.height),r.w=a.w,r.h=a.h,r.getContext("2d").drawImage(a,0,0)}a.width=Math.ceil(o*e._pixelDensity),a.height=Math.ceil(n*e._pixelDensity),a.w=o,a.h=n,a.hw=o/2,a.hh=n/2;for(let t in i)e.ctx[t]=i[t];e.ctx.scale(e._pixelDensity,e._pixelDensity),e.frameCount&&e.ctx.drawImage(r,0,0,r.w,r.h),e._da?e.flexibleCanvas(e._dau):(t.width=o,t.height=n),0!=e.frameCount&&e._adjustDisplay()}e._adjustDisplay=()=>{a.style&&(a.style.width=a.w+"px",a.style.height=a.h+"px")},e.createCanvas=function(o,n,r,i){if("webgl"==r)throw Error("webgl renderer is not supported in q5, use '2d'");"object"==typeof r&&(i=r),t.width=a.width=a.w=o||window.innerWidth,t.height=a.height=a.h=n||window.innerHeight,a.hw=o/2,a.hh=n/2,a.renderer="2d";let s=Object.assign({},Q5.canvasOptions);if(i&&Object.assign(s,i),t.ctx=t.drawingContext=a.getContext("2d",s),Object.assign(a,s),"rgb"==e._colorMode&&e.colorMode("rgb"),"image"!=e._scope&&(e._defaultStyle(),e._da=0),e.ctx.save(),"image"!=e._scope){let t=e.displayDensity();"graphics"==e._scope?t=this._pixelDensity:window.IntersectionObserver&&new IntersectionObserver((e=>{a.visible=e[0].isIntersecting})).observe(a),e.pixelDensity(Math.ceil(t))}else this._pixelDensity=1;return e.displayMode?e.displayMode():e._adjustDisplay(),a},e._createCanvas=e.createCanvas,"image"!=e._scope&&(e._defaultStyle=()=>{e.ctx.fillStyle="white",e.ctx.strokeStyle="black",e.ctx.lineCap="round",e.ctx.lineJoin="miter",e.ctx.textAlign="left"},e.resizeCanvas=(e,t)=>{e==a.w&&t==a.h||n(e,t)},e._pixelDensity=1,e.displayDensity=()=>window.devicePixelRatio,e.pixelDensity=t=>t&&t!=e._pixelDensity?(e._pixelDensity=t,n(a.w,a.h),t):e._pixelDensity,"image"!=e._scope&&(e.fullscreen=e=>{if(void 0===e)return document.fullscreenElement;e?document.body.requestFullscreen():document.body.exitFullscreen()},e.flexibleCanvas=(o=400)=>{o?(e._da=a.width/(o*e._pixelDensity),t.width=e._dau=o,t.height=a.h/a.w*o):e._da=0},e.translate=(t,a)=>{e._da&&(t*=e._da,a*=e._da),e.ctx.translate(t,a)},e.rotate=t=>{"degrees"==e._angleMode&&(t=e.radians(t)),e.ctx.rotate(t)},e.scale=(t,a)=>{a??=t,e.ctx.scale(t,a)},e.opacity=t=>e.ctx.globalAlpha=t,e.applyMatrix=(t,a,o,n,r,i)=>e.ctx.transform(t,a,o,n,r,i),e.shearX=t=>e.ctx.transform(1,0,e.tan(t),1,0,0),e.shearY=t=>e.ctx.transform(1,e.tan(t),0,1,0,0),e.resetMatrix=()=>{e.ctx.resetTransform(),e.ctx.scale(e._pixelDensity,e._pixelDensity)},e._styleNames=["_doStroke","_doFill","_strokeSet","_fillSet","_tint","_imageMode","_rectMode","_ellipseMode","_textFont","_textLeading","_leadingSet","_textSize","_textAlign","_textBaseline","_textStyle","_textWrap"],e._styles=[],e.push=e.pushMatrix=()=>{e.ctx.save();let t={};for(let a of e._styleNames)t[a]=e[a];e._styles.push(t)},e.pop=e.popMatrix=()=>{e.ctx.restore();let t=e._styles.pop();for(let a of e._styleNames)e[a]=t[a]},e.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},e.createGraphics=function(t,a,o){let n=new Q5("graphics");return o??={},o.alpha??=!0,n._createCanvas.call(e,t,a,o),n},window&&"graphics"!=e._scope&&window.addEventListener("resize",(()=>{e._shouldResize=!0,t.windowWidth=window.innerWidth,t.windowHeight=window.innerHeight,t.deviceOrientation=window.screen?.orientation?.type}))))},Q5.canvasOptions={alpha:!1,desynchronized:!1,colorSpace:"display-p3"},window.matchMedia&&matchMedia("(dynamic-range: high) and (color-gamut: p3)").matches?Q5.supportsHDR=!0:Q5.canvasOptions.colorSpace="srgb",Q5.modules.q2d_drawing=e=>{e.CHORD=0,e.PIE=1,e.OPEN=2,e.RADIUS="radius",e.CORNER="corner",e.CORNERS="corners",e.ROUND="round",e.SQUARE="butt",e.PROJECT="square",e.MITER="miter",e.BEVEL="bevel",e.CLOSE=1,e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.LANDSCAPE="landscape",e.PORTRAIT="portrait",e.BLEND="source-over",e.REMOVE="destination-out",e.ADD="lighter",e.DARKEST="darken",e.LIGHTEST="lighten",e.DIFFERENCE="difference",e.SUBTRACT="subtract",e.EXCLUSION="exclusion",e.MULTIPLY="multiply",e.SCREEN="screen",e.REPLACE="copy",e.OVERLAY="overlay",e.HARD_LIGHT="hard-light",e.SOFT_LIGHT="soft-light",e.DODGE="color-dodge",e.BURN="color-burn",e._doStroke=!0,e._doFill=!0,e._strokeSet=!1,e._fillSet=!1,e._ellipseMode=e.CENTER,e._rectMode=e.CORNER,e._curveDetail=20,e._curveAlpha=0;let t=!0,a=[];function o(){e._doFill&&e.ctx.fill(),e._doStroke&&e.ctx.stroke()}function n(t){let a=e._angleMode==e.DEGREES?360:e.TAU;return(t%=a)<0&&(t+=a),t}function r(t,a,r,i,s,l,c,d){if(!e._doFill&&!e._doStroke)return;let h=n(s),u=n(l);if(h>u&&([h,u]=[u,h]),0!=h||0!=u){if(e.ctx.beginPath(),r==i)e.ctx.arc(t,a,r/2,h,u);else{for(let o=0;o{t||(e._doStroke=!1),e._da&&(t*=e._da),e.ctx.lineWidth=t||1e-4},e.stroke=function(t){if(e._doStroke=!0,e._strokeSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._basicColors[t]&&(t=e.color(...e._basicColors[t])):t=e.color(...arguments),t.a<=0))return e._doStroke=!1;e.ctx.strokeStyle=t.toString()},e.noStroke=()=>e._doStroke=!1,e.fill=function(t){if(e._doFill=!0,e._fillSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._basicColors[t]&&(t=e.color(...e._basicColors[t])):t=e.color(...arguments),t.a<=0))return e._doFill=!1;e.ctx.fillStyle=t.toString()},e.noFill=()=>e._doFill=!1,e.blendMode=t=>e.ctx.globalCompositeOperation=t,e.strokeCap=t=>e.ctx.lineCap=t,e.strokeJoin=t=>e.ctx.lineJoin=t,e.ellipseMode=t=>e._ellipseMode=t,e.rectMode=t=>e._rectMode=t,e.curveDetail=t=>e._curveDetail=t,e.curveAlpha=t=>e._curveAlpha=t,e.curveTightness=t=>e._curveAlpha=t,e.clear=()=>{e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height)},e.background=function(t){if(t.canvas)return e.image(t,0,0,e.width,e.height);e.ctx.save(),e.ctx.resetTransform(),Q5.Color&&(t._q5Color||"string"==typeof t?e._basicColors[t]&&(t=e.color(...e._basicColors[t])):t=e.color(...arguments)),e.ctx.fillStyle=t.toString(),e.ctx.fillRect(0,0,e.canvas.width,e.canvas.height),e.ctx.restore()},e.line=(t,a,o,n)=>{e._doStroke&&(e._da&&(t*=e._da,a*=e._da,o*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.moveTo(t,a),e.ctx.lineTo(o,n),e.ctx.stroke())},e.arc=(t,a,o,n,i,s,l,c=25)=>{if(i==s)return e.ellipse(t,a,o,n);l??=e.PIE,e._ellipseMode==e.CENTER?r(t,a,o,n,i,s,l,c):e._ellipseMode==e.RADIUS?r(t,a,2*o,2*n,i,s,l,c):e._ellipseMode==e.CORNER?r(t+o/2,a+n/2,o,n,i,s,l,c):e._ellipseMode==e.CORNERS&&r((t+o)/2,(a+n)/2,o-t,n-a,i,s,l,c)},e.ellipse=(t,a,o,n)=>{n??=o,e._ellipseMode==e.CENTER?i(t,a,o,n):e._ellipseMode==e.RADIUS?i(t,a,2*o,2*n):e._ellipseMode==e.CORNER?i(t+o/2,a+n/2,o,n):e._ellipseMode==e.CORNERS&&i((t+o)/2,(a+n)/2,o-t,n-a)},e.circle=(t,a,n)=>{e._ellipseMode==e.CENTER?(e._da&&(t*=e._da,a*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.arc(t,a,n/2,0,e.TAU),o()):e.ellipse(t,a,n,n)},e.point=(t,a)=>{t.x&&(a=t.y,t=t.x),e._da&&(t*=e._da,a*=e._da),e.ctx.save(),e.ctx.beginPath(),e.ctx.arc(t,a,e.ctx.lineWidth/2,0,e.TAU),e.ctx.fillStyle=e.ctx.strokeStyle,e.ctx.fill(),e.ctx.restore()},e.rect=(t,a,o,n=o,r,i,l,c)=>{e._rectMode==e.CENTER?s(t-o/2,a-n/2,o,n,r,i,l,c):e._rectMode==e.RADIUS?s(t-o,a-n,2*o,2*n,r,i,l,c):e._rectMode==e.CORNER?s(t,a,o,n,r,i,l,c):e._rectMode==e.CORNERS&&s(t,a,o-t,n-a,r,i,l,c)},e.square=(t,a,o,n,r,i,s)=>e.rect(t,a,o,o,n,r,i,s),e.beginShape=()=>{l(),e.ctx.beginPath(),t=!0},e.beginContour=()=>{e.ctx.closePath(),l(),t=!0},e.endContour=()=>{l(),t=!0},e.vertex=(a,o)=>{e._da&&(a*=e._da,o*=e._da),l(),t?e.ctx.moveTo(a,o):e.ctx.lineTo(a,o),t=!1},e.bezierVertex=(t,a,o,n,r,i)=>{e._da&&(t*=e._da,a*=e._da,o*=e._da,n*=e._da,r*=e._da,i*=e._da),l(),e.ctx.bezierCurveTo(t,a,o,n,r,i)},e.quadraticVertex=(t,a,o,n)=>{e._da&&(t*=e._da,a*=e._da,o*=e._da,n*=e._da),l(),e.ctx.quadraticCurveTo(t,a,o,n)},e.bezier=(t,a,o,n,r,i,s,l)=>{e.beginShape(),e.vertex(t,a),e.bezierVertex(o,n,r,i,s,l),e.endShape()},e.triangle=(t,a,o,n,r,i)=>{e.beginShape(),e.vertex(t,a),e.vertex(o,n),e.vertex(r,i),e.endShape(e.CLOSE)},e.quad=(t,a,o,n,r,i,s,l)=>{e.beginShape(),e.vertex(t,a),e.vertex(o,n),e.vertex(r,i),e.vertex(s,l),e.endShape(e.CLOSE)},e.endShape=t=>{l(),t&&e.ctx.closePath(),o()},e.curveVertex=(o,n)=>{if(e._da&&(o*=e._da,n*=e._da),a.push([o,n]),a.length<4)return;let r=function(e,t,a,o,n,r,i,s,l,c){function d(e,t,a,o,n,r){let i=Math.pow(o-t,2)+Math.pow(n-a,2);return Math.pow(i,.5*r)+e}let h=[],u=d(0,e,t,a,o,c),_=d(u,a,o,n,r,c),g=d(_,n,r,i,s,c);for(let c=0;c0?(p[e]=1,p[e+1]=0):(p[e]=0,p[e+1]=1));let x=e*p[0]+a*p[1],m=t*p[0]+o*p[1],f=a*p[2]+n*p[3],v=o*p[2]+r*p[3],y=n*p[4]+i*p[5],w=r*p[4]+s*p[5],M=x*p[6]+f*p[7],C=m*p[6]+v*p[7],S=f*p[8]+y*p[9],b=v*p[8]+w*p[9],R=M*p[2]+S*p[3],E=C*p[2]+b*p[3];h.push([R,E])}return h}(...a.at(-4),...a.at(-3),...a.at(-2),...a.at(-1),e._curveDetail,e._curveAlpha);for(let a=0;a{e.beginShape(),e.curveVertex(t,a),e.curveVertex(o,n),e.curveVertex(r,i),e.curveVertex(s,l),e.endShape()},e.curvePoint=(e,t,a,o,n)=>{const r=n*n*n,i=n*n;return e*(-.5*r+i-.5*n)+t*(1.5*r-2.5*i+1)+a*(-1.5*r+2*i+.5*n)+o*(.5*r-.5*i)},e.bezierPoint=(e,t,a,o,n)=>{const r=1-n;return Math.pow(r,3)*e+3*Math.pow(r,2)*n*t+3*r*Math.pow(n,2)*a+Math.pow(n,3)*o},e.curveTangent=(e,t,a,o,n)=>{const r=n*n;return e*(-3*r/2+2*n-.5)+t*(9*r/2-5*n)+a*(-9*r/2+4*n+.5)+o*(3*r/2-n)},e.bezierTangent=(e,t,a,o,n)=>{const r=1-n;return 3*o*Math.pow(n,2)-3*a*Math.pow(n,2)+6*a*r*n-6*t*r*n+3*t*Math.pow(r,2)-3*e*Math.pow(r,2)},e.erase=function(t=255,a=255){e.ctx.save(),e.ctx.globalCompositeOperation="destination-out",e.ctx.fillStyle=`rgba(0, 0, 0, ${t/255})`,e.ctx.strokeStyle=`rgba(0, 0, 0, ${a/255})`},e.noErase=function(){e.ctx.globalCompositeOperation="source-over",e.ctx.restore()},e.inFill=(t,a)=>{const o=e._pixelDensity;return e.ctx.isPointInPath(t*o,a*o)},e.inStroke=(t,a)=>{const o=pixelDensity();return e.ctx.isPointInStroke(t*o,a*o)}},Q5.modules.q2d_image=(e,t)=>{e.createImage=(e,t,a)=>new Q5.Image(e,t,a),e._tint=null;let a=null,o=null,n=null;function r(t,a){a??=t||e.canvas.height,t??=e.canvas.width,null==o&&(o=new e._OffscreenCanvas(t,a).getContext("2d",{colorSpace:e.canvas.colorSpace})),o.canvas.width==t&&o.canvas.height==a||(o.canvas.width=t,o.canvas.height=a)}function i(t){o.clearRect(0,0,o.canvas.width,o.canvas.height),o.filter=t,o.drawImage(e.canvas,0,0),e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(o.canvas,0,0),e.ctx.restore()}e._softFilter=()=>{throw"Load q5-2d-soft-filters.js to use software filters."},e.filter=(t,a)=>{if(!e.ctx.filter)return e._softFilter(t,a);if(r(),"string"==typeof t)i(t);else if(t==Q5.THRESHOLD){a??=.5,a=Math.max(a,1e-5),i(`saturate(0%) brightness(${Math.floor(.5/a*100)}%) contrast(1000000%)`)}else t==Q5.GRAY?i("saturate(0%)"):t==Q5.OPAQUE?(o.fillStyle="black",o.fillRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(e.canvas,0,0),e.ctx.save(),e.ctx.resetTransform(),e.ctx.drawImage(o.canvas,0,0),e.ctx.restore()):t==Q5.INVERT?i("invert(100%)"):t==Q5.BLUR?i(`blur(${Math.ceil(a*e._pixelDensity/1)||1}px)`):e._softFilter(t,a)},e.resize=(a,n)=>{r(),o.drawImage(e.canvas,0,0),t.width=a,t.height=n,e.canvas.width=a*e._pixelDensity,e.canvas.height=n*e._pixelDensity,e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(o.canvas,0,0,e.canvas.width,e.canvas.height),e.ctx.restore()},e.trim=()=>{let t=e._pixelDensity||1,a=e.ctx.getImageData(0,0,e.width*t,e.height*t).data,o=e.width,n=0,r=e.height,i=0;for(let s=0;sn&&(n=l),si&&(i=s))}return r=Math.floor(r/t),i=Math.floor(i/t),o=Math.floor(o/t),n=Math.floor(n/t),e.get(o,r,n-o+1,i-r+1)},e.mask=t=>{e.ctx.save(),e.ctx.resetTransform();let a=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="destination-in",e.ctx.drawImage(t.canvas,0,0),e.ctx.globalCompositeOperation=a,e.ctx.restore()},e._save=async(e,t,a)=>{if(t=t||"untitled","jpg"==(a=a||"png")||"png"==a||"webp"==a)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+a});e=await new Promise((e=>{const a=new FileReader;a.onloadend=()=>e(a.result),a.readAsDataURL(t)}))}else e=e.toDataURL("image/"+a);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 o=document.createElement("a");o.href=e,o.download=t+"."+a,document.body.append(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(o.href)},e.save=(t,a,o)=>{if((!t||"string"==typeof t&&(!a||!o&&a.length<5))&&(o=a,a=t,t=e.canvas),o)return e._save(t,a,o);a?(a=a.split("."),e._save(t,a[0],a.at(-1))):e._save(t)},e.get=(t,a,o,n)=>{let r=e._pixelDensity||1;if(void 0!==t&&void 0===o){let o=e.ctx.getImageData(t*r,a*r,1,1).data;return new e.Color(o[0],o[1],o[2],o[3]/255)}t=(t||0)*r,a=(a||0)*r;let i=o=o||e.width,s=n=n||e.height;o*=r,n*=r;let l=e.createImage(o,n),c=e.ctx.getImageData(t,a,o,n);return l.ctx.putImageData(c,0,0),l._pixelDensity=r,l.width=i,l.height=s,l},e.set=(t,a,o)=>{if(o.canvas){let n=e._tint;return e._tint=null,e.image(o,t,a),void(e._tint=n)}e.pixels.length||e.loadPixels();let n=e._pixelDensity||1;for(let r=0;r{a=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height),t.pixels=a.data},e.updatePixels=()=>{null!=a&&e.ctx.putImageData(a,0,0)},e._tinted=function(t){let a=t.a;t.a=255,r(),o.clearRect(0,0,o.canvas.width,o.canvas.height),o.fillStyle=t.toString(),o.fillRect(0,0,o.canvas.width,o.canvas.height),o.globalCompositeOperation="multiply",o.drawImage(e.ctx.canvas,0,0),o.globalCompositeOperation="source-over",e.ctx.save(),e.ctx.resetTransform();let n=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="source-in",e.ctx.drawImage(o.canvas,0,0),e.ctx.globalCompositeOperation=n,e.ctx.restore(),o.globalAlpha=a/255,o.clearRect(0,0,o.canvas.width,o.canvas.height),o.drawImage(e.ctx.canvas,0,0),o.globalAlpha=1,e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.ctx.canvas.width,e.ctx.canvas.height),e.ctx.drawImage(o.canvas,0,0),e.ctx.restore()},e.smooth=()=>e.ctx.imageSmoothingEnabled=!0,e.noSmooth=()=>e.ctx.imageSmoothingEnabled=!1,"image"!=e._scope&&(e.saveCanvas=e.canvas.save=e.save,e.tint=function(t){e._tint=t._q5Color?t:e.color(...arguments)},e.noTint=()=>e._tint=null,e.imageMode=t=>e._imageMode=t,e.image=(t,a,o,r,i,s=0,l=0,c,d)=>{e._da&&(a*=e._da,o*=e._da,r*=e._da,i*=e._da,s*=e._da,l*=e._da,c*=e._da,d*=e._da);let h=t.canvas||t;var u,_;Q5._createNodeJSCanvas&&(h=h.context.canvas),t.canvas&&null!=e._tint&&(u=t.canvas.width,_=t.canvas.height,_??=u||e.canvas.height,u??=e.canvas.width,null==n&&(n=new e._OffscreenCanvas(u,_).getContext("2d",{colorSpace:e.canvas.colorSpace})),n.canvas.width==u&&n.canvas.height==_||(n.canvas.width=u,n.canvas.height=_),n.drawImage(t.canvas,0,0),t._tinted(e._tint)),r??=t.width||t.videoWidth,i??=t.height||t.videoHeight,"center"==e._imageMode&&(a-=.5*r,o-=.5*i);let g=t._pixelDensity||1;c?c*=g:c=h.width||h.videoWidth,d?d*=g:d=h.height||h.videoHeight,e.ctx.drawImage(h,s*g,l*g,c,d,a,o,r,i),function(){if(!t._q5||!e._tint)return;let a=t.ctx;a.save(),a.resetTransform(),a.clearRect(0,0,a.canvas.width,a.canvas.height),a.drawImage(n.canvas,0,0),a.restore()}()},e.loadImage=function(a,o,n){if(a.canvas)return a;if("gif"==a.slice(-3).toLowerCase())throw"In q5, GIFs are not supported due to their impact on performance. Use a video or p5play animation instead.";t._preloadCount++;let r=[...arguments].at(-1);n="object"!=typeof r||r;let i=e.createImage(1,1,n.alpha),s=i.ctx;if(Q5._nodejs&&global.CairoCanvas)CairoCanvas.loadImage(a).then((e=>{i.width=s.canvas.width=e.width,i.height=s.canvas.height=e.height,s.drawImage(e,0,0),t._preloadCount--,o&&o(i)})).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=a,e.crossOrigin="Anonymous",e._pixelDensity=1,e.onload=()=>{i.width=s.canvas.width=e.naturalWidth,i.height=s.canvas.height=e.naturalHeight,s.drawImage(e,0,0),t._preloadCount--,o&&o(i)},e.onerror=e=>{throw t._preloadCount--,e}}return i})},Q5.imageModules=["q2d_canvas","q2d_image"];class _Q5Image{constructor(e,t,a){let o=this;o._scope="image",o.canvas=o.ctx=o.drawingContext=null,o.pixels=[];for(let e of Q5.imageModules)Q5.modules[e](o,o);delete this.createCanvas,a??={},a.alpha??=!0,this._createCanvas(e,t,"2d",a),this._loop=!1}get w(){return this.width}get h(){return this.height}}Q5.Image??=_Q5Image,Q5.THRESHOLD=1,Q5.GRAY=2,Q5.OPAQUE=3,Q5.INVERT=4,Q5.POSTERIZE=5,Q5.DILATE=6,Q5.ERODE=7,Q5.BLUR=8,Q5.modules.q2d_soft_filters=e=>{let t=null;function a(){let a=e.canvas.width*e.canvas.height*4;t&&a==t.length||(t=new Uint8ClampedArray(a))}e._softFilter=(o,n)=>{e._filters||(e._filters=[],e._filters[Q5.THRESHOLD]=(e,t)=>{void 0===t?t=127.5:t*=255;for(let a=0;a=t?255:0}},e._filters[Q5.GRAY]=e=>{for(let t=0;t{for(let t=0;t{for(let t=0;t{let a=t-1;for(let o=0;o>8)/a,e[o+1]=255*(e[o+1]*t>>8)/a,e[o+2]=255*(e[o+2]*t>>8)/a},e._filters[Q5.DILATE]=o=>{a(),t.set(o);let[n,r]=[e.canvas.width,e.canvas.height];for(let e=0;e{a(),t.set(o);let[n,r]=[e.canvas.width,e.canvas.height];for(let e=0;e{n=n||1,n=Math.floor(n*e._pixelDensity),a(),t.set(o);let r=2*n+1,i=function(e){let t=new Float32Array(e),a=.3*n+.8,o=a*a*2;for(let n=0;n{e.NORMAL="normal",e.ITALIC="italic",e.BOLD="bold",e.BOLDITALIC="italic bold",e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.BASELINE="alphabetic",e._textFont="sans-serif",e._textSize=12,e._textLeading=15,e._textLeadDiff=3,e._textStyle="normal",e.loadFont=(e,a)=>{t._preloadCount++;let o=e.split("/"),n=o[o.length-1].split(".")[0].replace(" ",""),r=new FontFace(n,"url("+e+")");return document.fonts.add(r),r.load().then((()=>{t._preloadCount--,a&&a(n)})),n},e.textFont=t=>e._textFont=t,e.textSize=t=>{if(void 0===t)return e._textSize;e._da&&(t*=e._da),e._textSize=t,e._leadingSet||(e._textLeading=1.25*t,e._textLeadDiff=e._textLeading-t)},e.textLeading=t=>{if(void 0===t)return e._textLeading;e._da&&(t*=e._da),e._textLeading=t,e._textLeadDiff=t-e._textSize,e._leadingSet=!0},e.textStyle=t=>e._textStyle=t,e.textAlign=(t,a)=>{e.ctx.textAlign=t,a&&(e.ctx.textBaseline=a==e.CENTER?"middle":a)},e.textWidth=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).width),e.textAscent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxAscent),e.textDescent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxDescent),e._textCache=!!Q5.Image,e._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[o,n]of this.entries())n.lastAccessed(a&&(e._tic.maxSize=a),void 0!==t&&(e._textCache=t),e._textCache),e._genTextImageKey=(t,a,o)=>t.slice(0,200)+e._textStyle+e._textSize+e._textFont+(e._doFill?e.ctx.fillStyle:"")+"_"+(e._doStroke&&e._strokeSet?e.ctx.lineWidth+e.ctx.strokeStyle+"_":"")+(a||"")+(o?"x"+o:""),e.createTextImage=(t,a,o)=>{let n=e._textCache;e._textCache=!0,e._genTextImage=!0,e.text(t,0,0,a,o),e._genTextImage=!1;let r=e._genTextImageKey(t,a,o);return e._textCache=n,e._tic.get(r)},e.text=(t,a,o,n,r)=>{if(void 0===t)return;if(t=t.toString(),e._da&&(a*=e._da,o*=e._da),!e._doFill&&!e._doStroke)return;let i,s,l,c,d,h,u,_,g=1,p=e.ctx.getTransform(),x=e._genTextImage||e._textCache&&(0!=p.b||0!=p.c);if(x){if(c=e._genTextImageKey(t,n,r),s=e._tic.get(c),s&&!e._genTextImage)return void e.textImage(s,a,o);l=e.createGraphics.call(e,1,1),i=l.ctx,g=e._pixelDensity}else i=e.ctx,d=a,h=o;i.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`;let m=t.split("\n");if(x){d=0,h=e._textLeading*m.length;let a=i.measureText(" ");u=a.fontBoundingBoxAscent,_=a.fontBoundingBoxDescent,r??=h+_,l.resizeCanvas(Math.ceil(i.measureText(t).width),Math.ceil(r)),i.fillStyle=e.ctx.fillStyle,i.strokeStyle=e.ctx.strokeStyle,i.lineWidth=e.ctx.lineWidth}let f=i.fillStyle;e._fillSet||(i.fillStyle="black");for(let t=0;tr));t++);e._fillSet||(i.fillStyle=f),x&&(s=l.get(),s._ascent=u,s._descent=_,e._tic.set(c,s),e._genTextImage||e.textImage(s,a,o))},e.textImage=(t,a,o)=>{let n=e._imageMode;e._imageMode="corner","center"==e.ctx.textAlign?a-=.5*t.width:"right"==e.ctx.textAlign&&(a-=t.width),"alphabetic"==e.ctx.textBaseline&&(o-=e._textLeading),"middle"==e.ctx.textBaseline?o-=t._descent+.5*t._ascent+e._textLeadDiff:"bottom"==e.ctx.textBaseline?o-=t._ascent+t._descent+e._textLeadDiff:"top"==e.ctx.textBaseline&&(o-=t._descent+e._textLeadDiff),e.image(t,a,o),e._imageMode=n},e.nf=(e,t,a)=>{let o=e<0,n=(e=Math.abs(e)).toFixed(a).split(".");n[0]=n[0].padStart(t,"0");let r=n.join(".");return o&&(r="-"+r),r}},Q5.modules.ai=e=>{e.askAI=(e="")=>{throw Error("Ask AI ✨ "+e)},e._aiErrorAssistance=async e=>{let t=e.message?.includes("Ask AI ✨");if(t||console.error(e),Q5.disableFriendlyErrors)return;!t&&Q5.errorTolerant||noLoop();let a=e.stack?.split("\n");if(!e.stack||a.length<=1)return;let o=1,n="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(o=0,n="@");a[o].indexOf("q5.js:")>=0;)o++;let r=a[o].split(n).at(-1);r=r.split(":");let i=parseInt(r.at(-2));t&&i++;let s=r.slice(0,-2).join(":"),l=s.split("/").at(-1);try{let a=(await(await fetch(s)).text()).split("\n"),o=a[i-1].trim(),n="",r=1;for(;n.length<1600&&(i-r>=0&&(n=a[i-r].trim()+"\n"+n),i+r10?e.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(t?"":"%0A%0A"+encodeURIComponent(e.name+": "+e.message))+"%0A%0ALine%3A+"+encodeURIComponent(o)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(n);t||console.log("Error in "+l+" on line "+i+":\n\n"+o),console.warn("Ask AI ✨ "+c),t&&window.open(c,"_blank")}catch(e){}}},Q5.modules.color=(e,t)=>{e.RGB=e.RGBA=e._colorMode="rgb",Q5.supportsHDR?e.Color=Q5.ColorRGBA_P3:e.Color=Q5.ColorRGBA,e.colorMode=a=>{e._colorMode=a,"oklch"==a?t.Color=Q5.ColorOKLCH:"rgb"==a?"srgb"==e.canvas.colorSpace?t.Color=Q5.ColorRGBA:t.Color=Q5.ColorRGBA_P3:"srgb"==a&&(t.Color=Q5.ColorRGBA,e._colorMode="rgb")},e._basicColors={aqua:[0,255,255],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],crimson:[220,20,60],cyan:[0,255,255],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]},e.color=function(t,a,o,n){let r=e.Color;if(t._q5Color)return new r(...t.levels);let i=arguments;if(1==i.length){if("string"==typeof t)return"#"==t[0]?new r(parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16),9!=t.length?null:parseInt(t.slice(7,9),16)):e._basicColors[t]?new r(...e._basicColors[t]):new r(0,0,0);if(Array.isArray(t))return new r(...t)}if("rgb"==e._colorMode){if(1==i.length)return new r(t,t,t);if(2==i.length)return new r(t,t,t,a);if(3==i.length)return new r(t,a,o);if(4==i.length)return new r(t,a,o,n)}},e.red=e=>e.r,e.green=e=>e.g,e.blue=e=>e.b,e.alpha=e=>e.a,e.lightness=e=>100*(.2126*e.r+.7152*e.g+.0722*e.b)/255,e.lerpColor=(t,a,o)=>{if("rgb"==e._colorMode)return new e.Color(e.constrain(e.lerp(t.r,a.r,o),0,255),e.constrain(e.lerp(t.g,a.g,o),0,255),e.constrain(e.lerp(t.b,a.b,o),0,255),e.constrain(e.lerp(t.a,a.a,o),0,255));{let n=a.h-t.h;n>180&&(n-=360),n<-180&&(n+=360);let r=t.h+o*n;return r<0&&(r+=360),r>360&&(r-=360),new e.Color(e.constrain(e.lerp(t.l,a.l,o),0,100),e.constrain(e.lerp(t.c,a.c,o),0,100),r,e.constrain(e.lerp(t.a,a.a,o),0,255))}}},Q5.Color=class{constructor(){this._q5Color=!0}},Q5.ColorOKLCH=class extends Q5.Color{constructor(e,t,a,o){super(),this.l=e,this.c=t,this.h=a,this.a=o??1}toString(){return`color(oklch ${this.l} ${this.c} ${this.h} / ${this.a})`}},Q5.ColorRGBA=class extends Q5.Color{constructor(e,t,a,o){super(),this.r=e,this.g=t,this.b=a,this.a=o??255}setRed(e){this.r=e}setGreen(e){this.g=e}setBlue(e){this.b=e}setAlpha(e){this.a=e}get levels(){return[this.r,this.g,this.b,this.a]}toString(){return`rgb(${this.r} ${this.g} ${this.b} / ${this.a/255})`}},Q5.ColorRGBA_P3=class extends Q5.ColorRGBA{constructor(e,t,a,o){super(e,t,a,o),this._edited=!0}get r(){return this._r}set r(e){this._r=e,this._edited=!0}get g(){return this._g}set g(e){this._g=e,this._edited=!0}get b(){return this._b}set b(e){this._b=e,this._edited=!0}get a(){return this._a}set a(e){this._a=e,this._edited=!0}toString(){if(this._edited){let e=(this._r/255).toFixed(3),t=(this._g/255).toFixed(3),a=(this._b/255).toFixed(3),o=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${a} / ${o})`,this._edited=!1}return this._css}},Q5.modules.display=e=>{if(!e.canvas||"graphics"==e._scope)return;let t=e.canvas;0!=Q5._instanceCount||Q5._nodejs||document.head.insertAdjacentHTML("beforeend",""),e._adjustDisplay=()=>{let a=t.style,o=t.parentElement;a&&o&&t.displayMode&&("pixelated"==t.renderQuality&&(t.classList.add("q5-pixelated"),e.pixelDensity(1),e.noSmooth&&e.noSmooth(),e.textFont&&e.textFont("monospace")),"normal"==t.displayMode?(o.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),a.width=t.w*t.displayScale+"px",a.height=t.h*t.displayScale+"px"):(o.classList.add("q5-"+t.displayMode),o=o.getBoundingClientRect(),t.w/t.h>o.width/o.height?("centered"==t.displayMode?(a.width=t.w*t.displayScale+"px",a.maxWidth="100%"):a.width="100%",a.height="auto",a.maxHeight=""):(a.width="auto",a.maxWidth="","centered"==t.displayMode?(a.height=t.h*t.displayScale+"px",a.maxHeight="100%"):a.height="100%")))},e.displayMode=(a="normal",o="default",n=1)=>{"string"==typeof n&&(n=parseFloat(n.slice(1))),Object.assign(t,{displayMode:a,renderQuality:o,displayScale:n}),e._adjustDisplay()}},Q5.modules.input=(e,t)=>{if("graphics"==e._scope)return;e.mouseX=0,e.mouseY=0,e.pmouseX=0,e.pmouseY=0,e.touches=[],e.mouseButton=null,e.keyIsPressed=!1,e.mouseIsPressed=!1,e.key=null,e.keyCode=null,e.UP_ARROW=38,e.DOWN_ARROW=40,e.LEFT_ARROW=37,e.RIGHT_ARROW=39,e.SHIFT=16,e.TAB=9,e.BACKSPACE=8,e.ENTER=e.RETURN=13,e.ALT=e.OPTION=18,e.CONTROL=17,e.DELETE=46,e.ESCAPE=27,e.ARROW="default",e.CROSS="crosshair",e.HAND="pointer",e.MOVE="move",e.TEXT="text";let a={},o=[e.LEFT,e.CENTER,e.RIGHT],n=e.canvas;function r(t){const a=e.canvas.getBoundingClientRect(),o=e.canvas.scrollWidth/e.width||1,n=e.canvas.scrollHeight/e.height||1;return{x:(t.clientX-a.left)/o,y:(t.clientY-a.top)/n,id:t.identifier}}if(e._startAudio=()=>{e.getAudioContext&&"suspended"==e.getAudioContext()?.state&&e.userStartAudio()},e._updateMouse=a=>{if(a.changedTouches)return;let o=e.canvas.getBoundingClientRect(),n=e.canvas.scrollWidth/e.width||1,r=e.canvas.scrollHeight/e.height||1;t.mouseX=(a.clientX-o.left)/n,t.mouseY=(a.clientY-o.top)/r},e._onmousedown=a=>{e._startAudio(),e._updateMouse(a),t.mouseIsPressed=!0,t.mouseButton=o[a.button],e.mousePressed(a)},e._onmousemove=t=>{e._updateMouse(t),e.mouseIsPressed?e.mouseDragged(t):e.mouseMoved(t)},e._onmouseup=a=>{e._updateMouse(a),t.mouseIsPressed=!1,e.mouseReleased(a)},e._onclick=a=>{e._updateMouse(a),t.mouseIsPressed=!0,e.mouseClicked(a),t.mouseIsPressed=!1},n.addEventListener("mousedown",(t=>e._onmousedown(t))),n.addEventListener("mouseup",(t=>e._onmouseup(t))),n.addEventListener("click",(t=>e._onclick(t))),e.cursor=(t,a,o)=>{let n="";t.includes(".")&&(t=`url("${t}")`,n=", auto"),void 0!==a&&(t+=" "+a+" "+o),e.canvas.style.cursor=t+n},e.noCursor=()=>{e.canvas.style.cursor="none"},e.requestPointerLock=document.body.requestPointerLock,e.exitPointerLock=document.exitPointerLock,e._onkeydown=o=>{o.repeat||(e._startAudio,t.keyIsPressed=!0,t.key=o.key,t.keyCode=o.keyCode,a[e.keyCode]=a[e.key]=!0,e.keyPressed(o),1==o.key.length&&e.keyTyped(o))},e._onkeyup=o=>{t.keyIsPressed=!1,t.key=o.key,t.keyCode=o.keyCode,a[e.keyCode]=a[e.key]=!1,e.keyReleased(o)},e.keyIsDown=e=>!!a[e],e._ontouchstart=a=>{e._startAudio(),t.touches=[...a.touches].map(r),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,t.mouseIsPressed=!0,t.mouseButton=e.LEFT,e.mousePressed(a)||a.preventDefault()),e.touchStarted(a)||a.preventDefault()},e._ontouchmove=a=>{t.touches=[...a.touches].map(r),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,e.mouseDragged(a)||a.preventDefault()),e.touchMoved(a)||a.preventDefault()},e._ontouchend=a=>{t.touches=[...a.touches].map(r),e._isTouchAware||e.touches.length||(t.mouseIsPressed=!1,e.mouseReleased(a)||a.preventDefault()),e.touchEnded(a)||a.preventDefault()},n.addEventListener("touchstart",(t=>e._ontouchstart(t))),n.addEventListener("touchmove",(t=>e._ontouchmove(t))),n.addEventListener("touchcancel",(t=>e._ontouchend(t))),n.addEventListener("touchend",(t=>e._ontouchend(t))),window){let t=window.addEventListener;t("mousemove",(t=>e._onmousemove(t)),!1),t("keydown",(t=>e._onkeydown(t)),!1),t("keyup",(t=>e._onkeyup(t)),!1)}},Q5.modules.math=(e,t)=>{function a(){let e,t,a=4294967295;return{setSeed(o){e=t=(o??Math.random()*a)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/a)}}e.DEGREES="degrees",e.RADIANS="radians",e.PI=Math.PI,e.HALF_PI=Math.PI/2,e.QUARTER_PI=Math.PI/4,e.abs=Math.abs,e.ceil=Math.ceil,e.exp=Math.exp,e.floor=Math.floor,e.loge=Math.log,e.mag=Math.hypot,e.max=Math.max,e.min=Math.min,e.round=Math.round,e.pow=Math.pow,e.sqrt=Math.sqrt,e.SHR3=1,e.LCG=2,e.angleMode=t=>e._angleMode=t,e._DEGTORAD=Math.PI/180,e._RADTODEG=180/Math.PI,e.degrees=t=>t*e._RADTODEG,e.radians=t=>t*e._DEGTORAD,e.map=(e,t,a,o,n,r)=>{let i=o+1*(e-t)/(a-t)*(n-o);return r?oe*(1-a)+t*a,e.constrain=(e,t,a)=>Math.min(Math.max(e,t),a),e.dist=function(){let e=arguments;return 4==e.length?Math.hypot(e[0]-e[2],e[1]-e[3]):Math.hypot(e[0]-e[3],e[1]-e[4],e[2]-e[5])},e.norm=(t,a,o)=>e.map(t,a,o,0,1),e.sq=e=>e*e,e.fract=e=>e-Math.floor(e),e.sin=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.sin(t)),e.cos=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.cos(t)),e.tan=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.tan(t)),e.asin=t=>{let a=Math.asin(t);return"degrees"==e._angleMode&&(a=e.degrees(a)),a},e.acos=t=>{let a=Math.acos(t);return"degrees"==e._angleMode&&(a=e.degrees(a)),a},e.atan=t=>{let a=Math.atan(t);return"degrees"==e._angleMode&&(a=e.degrees(a)),a},e.atan2=(t,a)=>{let o=Math.atan2(t,a);return"degrees"==e._angleMode&&(o=e.degrees(o)),o};let o=a();o.setSeed(),e.randomSeed=e=>o.setSeed(e),e.random=(e,t)=>void 0===e?o.rand():"number"==typeof e?void 0!==t?o.rand()*(t-e)+e:o.rand()*e:e[Math.trunc(e.length*o.rand())],e.randomGenerator=t=>{t==e.LCG?o=function(){const e=4294967296;let t,a;return{setSeed(o){a=t=(o??Math.random()*e)>>>0},getSeed:()=>t,rand:()=>(a=(1664525*a+1013904223)%e,a/e)}}():t==e.SHR3&&(o=a()),o.setSeed()};var n=new function(){var e,t,a,n=new Array(128),r=new Array(256),i=new Array(128),s=new Array(128),l=new Array(256),c=new Array(256),d=()=>4294967296*o.rand()-2147483648,h=()=>.5+2.328306e-10*(d()|0),u=()=>{for(var t,o,r,l,c=3.44262;;){if(t=a*i[e],0==e){do{r=h(),l=h(),t=.2904764*-Math.log(r),o=-Math.log(l)}while(o+o0?c+t:-c-t}if(s[e]+h()*(s[e-1]-s[e]){for(var a;;){if(0==e)return 7.69711-Math.log(h());if(a=t*l[e],c[e]+h()*(c[e-1]-c[e])(a=d(),e=127&a,Math.abs(a)(t=d()>>>0){var e,t,a=2147483648,o=4294967296,d=3.442619855899,h=d,u=.00991256303526217,_=7.697117470131487,g=_,p=.003949659822581572;for(e=u/Math.exp(-.5*d*d),n[0]=Math.floor(d/e*a),n[1]=0,i[0]=e/a,i[127]=d/a,s[0]=1,s[127]=Math.exp(-.5*d*d),t=126;t>=1;t--)d=Math.sqrt(-2*Math.log(u/d+Math.exp(-.5*d*d))),n[t+1]=Math.floor(d/h*a),h=d,s[t]=Math.exp(-.5*d*d),i[t]=d/a;for(e=p/Math.exp(-_),r[0]=Math.floor(_/e*o),r[1]=0,l[0]=e/o,l[255]=_/o,c[0]=1,c[255]=Math.exp(-_),t=254;t>=1;t--)_=-Math.log(p/_+Math.exp(-_)),r[t+1]=Math.floor(_/g*o),g=_,c[t]=Math.exp(-_),l[t]=_/o}};let r;n.hasInit=!1,e.randomGaussian=(e,t)=>(n.hasInit||(n.zigset(),n.hasInit=!0),n.RNOR()*t+e),e.randomExponential=()=>(n.hasInit||(n.zigset(),n.hasInit=!0),n.REXP()),e.PERLIN="perlin",e.SIMPLEX="simplex",e.BLOCKY="blocky",e.Noise=Q5.PerlinNoise,e.noiseMode=e=>{t.Noise=Q5[e[0].toUpperCase()+e.slice(1)+"Noise"],r=null},e.noiseSeed=t=>{r=new e.Noise(t)},e.noise=(t=0,a=0,o=0)=>(r??=new e.Noise,r.noise(t,a,o)),e.noiseDetail=(t,a)=>{r??=new e.Noise,t>0&&(r.octaves=t),a>0&&(r.falloff=a)}},Q5.Noise=class{constructor(){}},Q5.PerlinNoise=class extends Q5.Noise{constructor(e){super(),this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.octaves=1,this.falloff=.5,this.p=null==e?Array.from({length:256},(()=>Math.floor(256*Math.random()))):this.seedPermutation(e),this.p=this.p.concat(this.p)}seedPermutation(e){let t,a,o=[];for(let e=0;e<256;e++)o[e]=e;for(let n=255;n>0;n--)t=(e=16807*e%2147483647)%(n+1),a=o[n],o[n]=o[t],o[t]=a;return o}dot(e,t,a,o){return e[0]*t+e[1]*a+e[2]*o}mix(e,t,a){return(1-a)*e+a*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,a){let o=this,n=0,r=1,i=1,s=0;for(let l=0;l{e.loadSound=(a,o)=>{t._preloadCount++,e.aud??=new window.AudioContext;let n=new Audio(a);return n.addEventListener("canplaythrough",(()=>{t._preloadCount--,o&&o(n)})),n.load(),n.setVolume=e=>n.volume=e,n.setLoop=e=>n.loop=e,n.panner=e.aud.createStereoPanner(),n.source=e.aud.createMediaElementSource(n),n.source.connect(n.panner),n.panner.connect(e.aud.destination),Object.defineProperty(n,"pan",{get:()=>n.panner.pan.value,set:e=>n.panner.pan.value=e}),n.setPan=e=>n.pan=e,n},e.getAudioContext=()=>e.aud,e.userStartAudio=()=>e.aud.resume()},Q5.modules.util=(e,t)=>{e._loadFile=(e,a,o)=>{t._preloadCount++;let n={};return fetch(e).then((e=>"json"==o?e.json():"text"==o?e.text():void 0)).then((e=>{t._preloadCount--,Object.assign(n,e),a&&a(e)})),n},e.loadStrings=(t,a)=>e._loadFile(t,a,"text"),e.loadJSON=(t,a)=>e._loadFile(t,a,"json"),"object"==typeof localStorage&&(e.storeItem=localStorage.setItem,e.getItem=localStorage.getItem,e.removeItem=localStorage.removeItem,e.clearStorage=localStorage.clear),e.year=()=>(new Date).getFullYear(),e.day=()=>(new Date).getDay(),e.hour=()=>(new Date).getHours(),e.minute=()=>(new Date).getMinutes(),e.second=()=>(new Date).getSeconds()},Q5.modules.vector=e=>{e.createVector=(t,a,o)=>new Q5.Vector(t,a,o,e)},Q5.Vector=class{constructor(e,t,a,o){this.x=e||0,this.y=t||0,this.z=a||0,this._$=o||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(){this._cnsq=this.x*this.x+this.y*this.y+this.z*this.z,this._cn=Math.sqrt(this._cnsq)}add(){let e=this._arg2v(...arguments);return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}rem(){let e=this._arg2v(...arguments);return this.x%=e.x,this.y%=e.y,this.z%=e.z,this}sub(){let e=this._arg2v(...arguments);return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}mult(){let e=this._arg2v(...arguments);return this.x*=e.x,this.y*=e.y,this.z*=e.z,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}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,o=this.z-e.z;return Math.sqrt(t*t+a*a+o*o)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,a=this.z*e.x-this.x*e.z,o=this.x*e.y-this.y*e.x;return this.x=t,this.y=a,this.z=o,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),o=this.x*t-this.y*a,n=this.x*a+this.y*t;return this.x=o,this.y=n,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}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)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,o)=>(new Q5.Vector)[e](t,a,o); diff --git a/src/q5-core.js b/src/q5-core.js index f5d731b..9a58143 100644 --- a/src/q5-core.js +++ b/src/q5-core.js @@ -183,6 +183,7 @@ function Q5(scope, parent) { }; let t = globalScope || $; + $._isTouchAware = t.touchStarted || t.touchMoved || t.mouseReleased; let preloadDefined = t.preload; let userFns = [ 'setup', @@ -215,8 +216,6 @@ function Q5(scope, parent) { } } - $._isTouchAware = $.touchStarted || $.touchMoved || $.mouseReleased; - if (!($.setup || $.draw)) return; $._startDone = false;