UNPKG

q5.js

Version:

[q5 fork] p5.js small & fast alternative (experimental) implementation.

1 lines 36.2 kB
function Q5(e,t){"use strict";return new function e(n){let o="offscreen"!==n&&void 0!==n?window:this;o.canvas=document.createElement("canvas");let a=o.canvas.getContext("2d",t);if(o.width=100,o.height=100,o.canvas.width=o.width,o.canvas.height=o.height,"offscreen"!=n){let e="global"==n||void 0===n?document.body:document.querySelector(n);document.body?e.appendChild(o.canvas):window.addEventListener("load",(function(){e.appendChild(o.canvas)}))}m(),o.MAGIC=161533525,o.RGB=0,o.HSV=1,o.HSB=1,o.CHORD=0,o.PIE=1,o.OPEN=2,o.RADIUS=1,o.CORNER=2,o.CORNERS=3,o.ROUND="round",o.SQUARE="butt",o.PROJECT="square",o.MITER="miter",o.BEVEL="bevel",o.CLOSE=1,o.BLEND="source-over",o.REMOVE="destination-out",o.ADD="lighter",o.DARKEST="darken",o.LIGHTEST="lighten",o.DIFFERENCE="difference",o.SUBTRACT="subtract",o.EXCLUSION="exclusion",o.MULTIPLY="multiply",o.SCREEN="screen",o.REPLACE="copy",o.OVERLAY="overlay",o.HARD_LIGHT="hard-light",o.SOFT_LIGHT="soft-light",o.DODGE="color-dodge",o.BURN="color-burn",o.NORMAL="normal",o.ITALIC="italic",o.BOLD="bold",o.BOLDITALIC="italic bold",o.CENTER="center",o.LEFT="left",o.RIGHT="right",o.TOP="top",o.BOTTOM="bottom",o.BASELINE="alphabetic",o.LANDSCAPE="landscape",o.PORTRAIT="portrait",o.ALT=18,o.BACKSPACE=8,o.CONTROL=17,o.DELETE=46,o.DOWN_ARROW=40,o.ENTER=13,o.ESCAPE=27,o.LEFT_ARROW=37,o.OPTION=18,o.RETURN=13,o.RIGHT_ARROW=39,o.SHIFT=16,o.TAB=9,o.UP_ARROW=38,o.HALF_PI=Math.PI/2,o.PI=Math.PI,o.QUARTER_PI=Math.PI/4,o.TAU=2*Math.PI,o.TWO_PI=2*Math.PI,o.THRESHOLD=1,o.GRAY=2,o.OPAQUE=3,o.INVERT=4,o.POSTERIZE=5,o.DILATE=6,o.ERODE=7,o.BLUR=8,o.BRIGHTNESS=9,o.CONTRAST=10,o.SATURATE=11,o.ARROW="default",o.CROSS="crosshair",o.HAND="pointer",o.MOVE="move",o.TEXT="text",o.VIDEO={video:!0,audio:!1},o.AUDIO={video:!1,audio:!0},o.SHR3=1,o.LCG=2,o.HARDWARE_FILTERS=!0,o.hint=function(e,t){o[e]=t},o.frameCount=0,o.mouseX=0,o.mouseY=0,o.pmouseX=0,o.pmouseY=0,o.mouseButton=null,o.keyIsPressed=!1,o.mouseIsPressed=!1,o.key=null,o.keyCode=null,o.pixels=null,o.accelerationX=0,o.accelerationY=0,o.accelerationZ=0,o.rotationX=0,o.rotationY=0,o.rotationZ=0,o.relRotationX=0,o.relRotationY=0,o.relRotationZ=0,o.pAccelerationX=0,o.pAccelerationY=0,o.pAccelerationZ=0,o.pRotationX=0,o.pRotationY=0,o.pRotationZ=0,o.pRelRotationX=0,o.pRelRotationY=0,o.pRelRotationZ=0,o.touches=[],o._styleCache=[{colorMode:o.RGB,noStroke:!1,noFill:!1,ellipseMode:o.CENTER,rectMode:o.CORNER,curveDetail:20,curveAlpha:0,textFont:"sans-serif",textSize:12,textLeading:12,textStyle:"normal"}],o._style=o._styleCache[o._styleCache.length-1],o._noLoop=!1,o._pixelDensity=1,o._frameRate=null,o._tint=null;let r=null,i=!0,l=[],s=null,u=0,c={},h=0,f=null,d=null,p=null;Object.defineProperty(o,"deviceOrientation",{get:function(){return 90==Math.abs(window.orientation)?o.LANDSCAPE:o.PORTRAIT}}),Object.defineProperty(o,"windowWidth",{get:function(){return window.innerWidth}}),Object.defineProperty(o,"windowHeight",{get:function(){return window.innerHeight}}),Object.defineProperty(o,"drawingContext",{get:function(){return a}}),o.createCanvas=function(e,t){return o.width=e,o.height=t,o.canvas.width=e,o.canvas.height=t,m(),o.canvas},o.resizeCanvas=function(e,t){o.width=e,o.height=t,o.canvas.width=e,o.canvas.height=t},o.createGraphics=o.createImage=function(t,n){let o=new e("offscreen");return o.createCanvas(t,n),o.noLoop(),o},o.pixelDensity=function(e){return null==e||(o._pixelDensity=e,o.canvas.width=Math.ceil(o.width*e),o.canvas.height=Math.ceil(o.height*e),o.canvas.style.width=o.width+"px",o.canvas.style.height=o.height+"px",a.scale(o._pixelDensity,o._pixelDensity),m()),o._pixelDensity},o.map=function(e,t,n,o,a,r){let i=o+1*(e-t)/(n-t)*(a-o);return r?o<a?Math.min(Math.max(i,o),a):Math.min(Math.max(i,a),o):i},o.lerp=function(e,t,n){return e*(1-n)+t*n},o.constrain=function(e,t,n){return Math.min(Math.max(e,t),n)},o.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])},o.norm=function(e,t,n){return o.map(e,t,n,0,1)},o.sq=function(e){return e*e},o.fract=function(e){return e-Math.floor(e)},o.degrees=function(e){return 180*e/Math.PI},o.radians=function(e){return e*Math.PI/180},o.abs=Math.abs,o.ceil=Math.ceil,o.exp=Math.exp,o.floor=Math.floor,o.log=Math.log,o.mag=Math.hypot,o.max=Math.max,o.min=Math.min,o.round=Math.round,o.sqrt=Math.sqrt,o.sin=Math.sin,o.cos=Math.cos,o.tan=Math.tan,o.asin=Math.asin,o.acos=Math.acos,o.atan=Math.atan,o.atan2=Math.atan2,o.Vector=function(e,t,n){let a=this;a.x=e||0,a.y=t||0,a.z=n||0;let r=null,i=null;function l(e,t,n){return null!=e.x?e:null!=t?{x:e,y:t,z:n||0}:{x:e,y:e,z:e}}function s(){null==i&&(i=a.x*a.x+a.y*a.y+a.z*a.z,r=Math.sqrt(i))}function u(){i=null,r=null}a.set=function(e,t,n){a.x=e||0,a.y=t||0,a.z=n||0},a.copy=function(){return new o.Vector(a.x,a.y,a.z)},a.add=function(){let e=l.apply(null,arguments);return a.x+=e.x,a.y+=e.y,a.z+=e.z,u(),a},a.rem=function(){let e=l.apply(null,arguments);return a.x%=e.x,a.y%=e.y,a.z%=e.z,u(),a},a.sub=function(){let e=l.apply(null,arguments);return a.x-=e.x,a.y-=e.y,a.z-=e.z,u(),a},a.mult=function(){let e=l.apply(null,arguments);return a.x*=e.x,a.y*=e.y,a.z*=e.z,u(),a},a.div=function(){let e=l.apply(null,arguments);return a.x/=e.x,a.y/=e.y,a.z/=e.z,u(),a},a.mag=function(){return s(),r},a.magSq=function(){return s(),i},a.dot=function(){let e=l.apply(null,arguments);return a.x*e.x+a.y*e.y+a.z*e.z},a.dist=function(){let e=l.apply(null,arguments),t=a.x-e.x,n=a.y-e.y,o=a.z-e.z;return Math.sqrt(t*t+n*n+o*o)},a.cross=function(){let e=l.apply(null,arguments),t=a.y*e.z-a.z*e.y,n=a.z*e.x-a.x*e.z,o=a.x*e.y-a.y*e.x;return a.x=t,a.y=n,a.z=o,u(),a},a.normalize=function(){s();let e=r;return a.x/=e,a.y/=e,a.z/=e,r=1,i=1,a},a.limit=function(e){s();if(r>e){let t=e/r;a.x*=t,a.y*=t,a.z*=t,r=e,i=e*e}return a},a.setMag=function(e){s();let t=e/r;return a.x*=t,a.y*=t,a.z*=t,r=e,i=e*e,a},a.heading=function(){return Math.atan2(a.y,a.x)},a.rotate=function(e){let t=Math.cos(e),n=Math.sin(e),o=a.x*t-a.y*n,r=a.x*n+a.y*t;return a.x=o,a.y=r,a},a.angleBetween=function(){let e=l.apply(null,arguments);const t=a.dot(e)/(a.mag()*e.mag());let n;return n=Math.acos(Math.min(1,Math.max(-1,t))),n*=Math.sign(a.cross(e).z||1),n},a.lerp=function(e,t){return a.x=a.x*(1-t)+e.x*t,a.y=a.y*(1-t)+e.y*t,a.z=a.z*(1-t)+e.z*t,u(),a},a.reflect=function(e){return e.normalize(),a.sub(e.mult(2*a.dot(e)))},a.array=function(){return[a.x,a.y,a.z]},a.equals=function(e,t){return null==t&&null==(t=Number.EPSILON)&&(t=0),Math.abs(e.x-a.x)<t&&Math.abs(e.y-a.y)<t&&Math.abs(e.z-a.z)<t},a.fromAngle=function(e,t){return null==t&&(t=1),r=t,i=t*t,a.x=t*Math.cos(e),a.y=t*Math.sin(e),a.z=0,a},a.fromAngles=function(e,t,n){null==n&&(n=1),r=n,i=n*n;const o=Math.cos(t),l=Math.sin(t),s=Math.cos(e),u=Math.sin(e);return a.x=n*u*l,a.y=-n*s,a.z=n*u*o,a},a.random2D=function(){return r=1,i=1,a.fromAngle(Math.random()*Math.PI*2)},a.random3D=function(){return r=1,i=1,a.fromAngles(Math.random()*Math.PI*2,Math.random()*Math.PI*2)},a.toString=function(){return`[${a.x}, ${a.y}, ${a.z}]`}},o.Vector.add=function(e,t){return new o.Vector(e.x+t.x,e.y+t.y,e.z+t.z)},o.Vector.rem=function(e,t){return new o.Vector(e.x%t.x,e.y%t.y,e.z%t.z)},o.Vector.sub=function(e,t){return new o.Vector(e.x-t.x,e.y-t.y,e.z-t.z)},o.Vector.mult=function(e,t){return null==t.x?new o.Vector(e.x*t,e.y*t,e.z*t):new o.Vector(e.x*t.x,e.y*t.y,e.z*t.z)},o.Vector.div=function(e,t){return null==t.x?new o.Vector(e.x/t,e.y/t,e.z/t):new o.Vector(e.x/t.x,e.y/t.y,e.z/t.z)},o.Vector.dist=function(e,t){return Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z)},o.Vector.cross=function(e,t){return new o.Vector(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z,e.x*t.y-e.y*t.x)},o.Vector.lerp=function(e,t,n){return new o.Vector(e.x*(1-n)+t.x*n,e.y=e.y*(1-n)+t.y*n,e.z=e.z*(1-n)+t.z*n)},o.Vector.equals=function(e,t,n){return e.equals(t,n)};for(let e of["fromAngle","fromAngles","random2D","random3D"])o.Vector[e]=function(t,n,a){return(new o.Vector)[e](t,n,a)};function y(e,t,n){let o,a,r,i,l,s,u,c,h;if(0==t)return o=n,a=n,r=n,[255*o,255*a,255*r];switch(i=e,i>360&&(i=0),i/=60,l=~~i,s=i-l,u=n*(1-t),c=n*(1-t*s),h=n*(1-t*(1-s)),l){case 0:o=n,a=h,r=u;break;case 1:o=c,a=n,r=u;break;case 2:o=u,a=n,r=h;break;case 3:o=u,a=c,r=n;break;case 4:o=h,a=u,r=n;break;default:o=n,a=u,r=c}return[255*o,255*a,255*r]}function m(){a.fillStyle="white",a.strokeStyle="black",a.lineCap="round",a.lineJoin="miter"}function g(e){if(0<=e&&e<2*Math.PI)return e;for(;e<0;)e+=2*Math.PI;for(;e>=Math.PI;)e-=2*Math.PI;return e}function v(e,t,n,r,i,l,s,u){if(o._style.noFill&&o._style.noStroke)return;let c=g(i),h=g(l);a.beginPath();for(let i=0;i<u+1;i++){let l=i/u,s=o.lerp(c,h,l),f=Math.cos(s)*n/2,d=Math.sin(s)*r/2;a[i?"lineTo":"moveTo"](e+f,t+d)}s==o.CHORD?a.closePath():s==o.PIE&&(a.lineTo(e,t),a.closePath()),o._style.noFill||a.fill(),o._style.noStroke||a.stroke()}function M(e,t,n,r){o._style.noFill&&o._style.noStroke||(a.beginPath(),a.ellipse(e,t,n/2,r/2,0,0,2*Math.PI),o._style.noFill||a.fill(),o._style.noStroke||a.stroke())}function _(e,t,n,r,i,l,s,u){if(o._style.noFill&&o._style.noStroke)return;if(null==i)return function(e,t,n,r){o._style.noFill||a.fillRect(e,t,n,r),o._style.noStroke||a.strokeRect(e,t,n,r)}(e,t,n,r);if(null==l)return _(e,t,n,r,i,i,i,i);const c=Math.min(Math.abs(r),Math.abs(n))/2;i=Math.min(c,i),l=Math.min(c,l),u=Math.min(c,u),s=Math.min(c,s),a.beginPath(),a.moveTo(e+i,t),a.arcTo(e+n,t,e+n,t+r,l),a.arcTo(e+n,t+r,e,t+r,s),a.arcTo(e,t+r,e,t,u),a.arcTo(e,t,e+n,t,i),a.closePath(),o._style.noFill||a.fill(),o._style.noStroke||a.stroke()}function x(){l=[]}o.createVector=function(e,t,n){return new o.Vector(e,t,n)},o.curvePoint=function(e,t,n,o,a){const r=a*a*a,i=a*a;return e*(-.5*r+i-.5*a)+t*(1.5*r-2.5*i+1)+n*(-1.5*r+2*i+.5*a)+o*(.5*r-.5*i)},o.bezierPoint=function(e,t,n,o,a){const r=1-a;return Math.pow(r,3)*e+3*Math.pow(r,2)*a*t+3*r*Math.pow(a,2)*n+Math.pow(a,3)*o},o.curveTangent=function(e,t,n,o,a){const r=a*a;return e*(-3*r/2+2*a-.5)+t*(9*r/2-5*a)+n*(-9*r/2+4*a+.5)+o*(3*r/2-a)},o.bezierTangent=function(e,t,n,o,a){const r=1-a;return 3*o*Math.pow(a,2)-3*n*Math.pow(a,2)+6*n*r*a-6*t*r*a+3*t*Math.pow(r,2)-3*e*Math.pow(r,2)},o.Color=function(e,t,n,o){let a=this;a.MAGIC=786698,a._r=e,a._g=t,a._b=n,a._a=o,a._h=0,a._s=0,a._v=0,a._hsvInferred=!1,a.setRed=function(e){a._r=e,a._hsvInferred=!1},a.setGreen=function(e){a._g=e,a._hsvInferred=!1},a.setBlue=function(e){a._b=e,a._hsvInferred=!1},a.setAlpha=function(e){a._a=e/255,a._hsvInferred=!1},a._inferHSV=function(){a._hsvInferred||([a._h,a._s,a._v]=function(e,t,n){let o,a,r,i,l;return o=e<t?e<n?e:n:t<n?t:n,a=e>t?e>n?e:n:t>n?t:n,l=100*a/255,0==l?(r=0,i=0,[r,i,l]):(i=100*(a-o)/a,0==i?(r=0,[r,i,l]):(r=a==e?0+60*(t-n)/(a-o):a==t?120+60*(n-e)/(a-o):240+60*(e-t)/(a-o),[r,i,l]))}(a._r,a._g,a._b),a._hsvInferred=!0)},a.toString=function(){return`rgba(${Math.round(a._r)},${Math.round(a._g)},${Math.round(a._b)},${~~(1e3*a._a)/1e3})`}},o.colorMode=function(e){o._style.colorMode=e},o.color=function(){if(1==arguments.length&&786698==arguments[0].MAGIC)return arguments[0];if(o._style.colorMode==o.RGB){if(1==arguments.length)return new o.Color(arguments[0],arguments[0],arguments[0],1);if(2==arguments.length)return new o.Color(arguments[0],arguments[0],arguments[0],arguments[1]/255);if(3==arguments.length)return new o.Color(arguments[0],arguments[1],arguments[2],1);if(4==arguments.length)return new o.Color(arguments[0],arguments[1],arguments[2],arguments[3]/255)}else{if(1==arguments.length)return new o.Color(...y(0,0,arguments[0]/100),1);if(2==arguments.length)return new o.Color(...y(0,0,arguments[0]/100),arguments[1]/255);if(3==arguments.length)return new o.Color(...y(arguments[0],arguments[1]/100,arguments[2]/100),1);if(4==arguments.length)return new o.Color(...y(arguments[0],arguments[1]/100,arguments[2]/100),arguments[3])}return null},o.red=function(e){return e._r},o.green=function(e){return e._g},o.blue=function(e){return e._b},o.alpha=function(e){return 255*e._a},o.hue=function(e){return e._inferHSV(),e._h},o.saturation=function(e){return e._inferHSV(),e._s},o.brightness=function(e){return e._inferHSV(),e._v},o.lightness=function(e){return 100*(.2126*e._r+.7152*e._g+.0722*e._b)/255},o.lerpColor=function(e,t,n){return o._style.colorMode==o.RGB?new o.Color(o.constrain(o.lerp(e._r,t._r,n),0,255),o.constrain(o.lerp(e._g,t._g,n),0,255),o.constrain(o.lerp(e._b,t._b,n),0,255),o.constrain(o.lerp(e._a,t._a,n),0,1)):(e._inferHSV(),t._inferHSV(),new o.Color(o.constrain(function(e,t,n){var a=[[Math.abs(t-e),o.map(n,0,1,e,t)],[Math.abs(t+360-e),o.map(n,0,1,e,t+360)],[Math.abs(t-360-e),o.map(n,0,1,e,t-360)]];return a.sort(((e,t)=>e[0]-t[0])),(a[0][1]+720)%360}(e._h,t._h,n),0,360),o.constrain(o.lerp(e._s,t._s,n),0,100),o.constrain(o.lerp(e._v,t._v,n),0,100),o.constrain(o.lerp(e._a,t._a,n),0,1)))},o.strokeWeight=function(e){o._style_noStroke=!1,a.lineWidth=e},o.stroke=function(){if(o._style.noStroke=!1,"string"==typeof arguments[0])return void(a.strokeStyle=arguments[0]);let e=o.color.apply(null,arguments);e._a<=0?o._style.noStroke=!0:a.strokeStyle=e},o.noStroke=function(){o._style.noStroke=!0},o.fill=function(){if(o._style.noFill=!1,"string"==typeof arguments[0])return void(a.fillStyle=arguments[0]);let e=o.color.apply(null,arguments);e._a<=0?o._style.noFill=!0:a.fillStyle=e},o.noFill=function(){o._style.noFill=!0},o.blendMode=function(e){a.globalCompositeOperation=e},o.strokeCap=function(e){a.lineCap=e},o.strokeJoin=function(e){a.lineJoin=e},o.ellipseMode=function(e){o._style.ellipseMode=e},o.rectMode=function(e){o._style.rectMode=e},o.curveDetail=function(e){o._style.curveDetail=e},o.curveAlpha=function(e){o._style.curveAlpha=e},o.curveTightness=function(e){console.warn("curveTightness() sets the 'alpha' parameter of Catmull-Rom curve, and is NOT identical to p5.js counterpart. As this might change in the future, please call curveAlpha() directly."),o._style.curveAlpha=e},o.clear=function(){a.clearRect(0,0,o.width,o.height)},o.background=function(){if(arguments[0]&&arguments[0].MAGIC==o.MAGIC)return o.image(arguments[0],0,0,o.width,o.height);a.save(),a.resetTransform(),a.scale(o._pixelDensity,o._pixelDensity),a.fillStyle="string"==typeof arguments[0]?arguments[0]:o.color(...Array.from(arguments)),a.fillRect(0,0,o.width,o.height),a.restore()},o.line=function(e,t,n,r){o._style.noStroke||(a.beginPath(),a.moveTo(e,t),a.lineTo(n,r),a.stroke())},o.arc=function(e,t,n,a,r,i,l,s){if(r==i)return o.ellipse(e,t,n,a);null==s&&(s=25),null==l&&(l=o.PIE),o._style.ellipseMode==o.CENTER?v(e,t,n,a,r,i,l,s):o._style.ellipseMode==o.RADIUS?v(e,t,2*n,2*a,r,i,l,s):o._style.ellipseMode==o.CORNER?v(e+n/2,t+a/2,n,a,r,i,l,s):o._style.ellipseMode==o.CORNERS&&v((e+n)/2,(t+a)/2,n-e,a-t,r,i,l,s)},o.ellipse=function(e,t,n,a){null==a&&(a=n),o._style.ellipseMode==o.CENTER?M(e,t,n,a):o._style.ellipseMode==o.RADIUS?M(e,t,2*n,2*a):o._style.ellipseMode==o.CORNER?M(e+n/2,t+a/2,n,a):o._style.ellipseMode==o.CORNERS&&M((e+n)/2,(t+a)/2,n-e,a-t)},o.circle=function(e,t,n){return o.ellipse(e,t,n,n)},o.point=function(e,t){e.x&&(t=e.y,e=e.x),a.beginPath(),a.ellipse(e,t,.4,.4,0,0,2*Math.PI),a.stroke()},o.rect=function(e,t,n,a,r,i,l,s){o._style.rectMode==o.CENTER?_(e-n/2,t-a/2,n,a,r,i,l,s):o._style.rectMode==o.RADIUS?_(e-n,t-a,2*n,2*a,r,i,l,s):o._style.rectMode==o.CORNER?_(e,t,n,a,r,i,l,s):o._style.rectMode==o.CORNERS&&_(e,t,n-e,a-t,r,i,l,s)},o.square=function(e,t,n,a,r,i,l){return o.rect(e,t,n,n,a,r,i,l)},o.beginShape=function(){x(),a.beginPath(),i=!0},o.beginContour=function(){a.closePath(),x(),i=!0},o.endContour=function(){x(),i=!0},o.vertex=function(e,t){x(),i?a.moveTo(e,t):a.lineTo(e,t),i=!1},o.bezierVertex=function(e,t,n,o,r,i){x(),a.bezierCurveTo(e,t,n,o,r,i)},o.quadraticVertex=function(e,t,n,o){x(),a.quadraticCurveTo(e,t,n,o)},o.bezier=function(e,t,n,a,r,i,l,s){o.beginShape(),o.vertex(e,t),o.bezierVertex(n,a,r,i,l,s),o.endShape()},o.triangle=function(e,t,n,a,r,i){o.beginShape(),o.vertex(e,t),o.vertex(n,a),o.vertex(r,i),o.endShape(o.CLOSE)},o.quad=function(e,t,n,a,r,i,l,s){o.beginShape(),o.vertex(e,t),o.vertex(n,a),o.vertex(r,i),o.vertex(l,s),o.endShape(o.CLOSE)},o.endShape=function(e){x(),e&&a.closePath(),o._style.noFill||a.fill(),o._style.noStroke||a.stroke(),o._style.noFill&&o._style.noStroke&&(a.save(),a.fillStyle="none",a.fill(),a.restore())},o.curveVertex=function(e,t){if(l.push([e,t]),l.length<4)return;let n=function(e,t,n,o,a,r,i,l,s,u){function c(e,t,n,o,a,r){let i=Math.pow(o-t,2)+Math.pow(a-n,2);return Math.pow(i,.5*r)+e}let h=[],f=c(0,e,t,n,o,u),d=c(f,n,o,a,r,u),p=c(d,a,r,i,l,u);for(let u=0;u<s;u++){let c=f+u/(s-1)*(d-f),y=[(f-c)/(f-0),(c-0)/(f-0),(d-c)/(d-f),(c-f)/(d-f),(p-c)/(p-d),(c-d)/(p-d),(d-c)/(d-0),(c-0)/(d-0),(p-c)/(p-f),(c-f)/(p-f)];for(let e=0;e<y.length;e+=2)isNaN(y[e])&&(y[e]=1,y[e+1]=0),isFinite(y[e])||(y[e]>0?(y[e]=1,y[e+1]=0):(y[e]=0,y[e+1]=1));let m=e*y[0]+n*y[1],g=t*y[0]+o*y[1],v=n*y[2]+a*y[3],M=o*y[2]+r*y[3],_=a*y[4]+i*y[5],x=r*y[4]+l*y[5],w=m*y[6]+v*y[7],R=g*y[6]+M*y[7],I=v*y[8]+_*y[9],S=M*y[8]+x*y[9],C=w*y[2]+I*y[3],E=R*y[2]+S*y[3];h.push([C,E])}return h}(...l[l.length-4],...l[l.length-3],...l[l.length-2],...l[l.length-1],o._style.curveDetail,o._style.curveAlpha);for(let e=0;e<n.length;e++)i?a.moveTo(...n[e]):a.lineTo(...n[e]),i=!1},o.curve=function(e,t,n,a,r,i,l,s){o.beginShape(),o.curveVertex(e,t),o.curveVertex(n,a),o.curveVertex(r,i),o.curveVertex(l,s),o.endShape()},o.translate=function(e,t){a.translate(e,t)},o.rotate=function(e){a.rotate(e)},o.scale=function(e,t){null==t&&(t=e),a.scale(e,t)},o.applyMatrix=function(e,t,n,o,r,i){a.transform(e,t,n,o,r,i)},o.shearX=function(e){a.transform(1,0,Math.tan(e),1,0,0)},o.shearY=function(e){a.transform(1,Math.tan(e),0,1,0,0)},o.resetMatrix=function(){a.resetTransform(),a.scale(o._pixelDensity,o._pixelDensity)},o.pushMatrix=o.push=function(){o._styleCache.push({...o._style}),o._style=o._styleCache[o._styleCache.length-1],a.save()},o.popMatrix=o.pop=function(){o._styleCache.length-1&&(o._styleCache.pop(),o._style=o._styleCache[o._styleCache.length-1],a.restore())},o.image=function(e,t,n,r,i,l,s,u,c){let h=e.MAGIC==o.MAGIC?e.canvas:e;function f(){if(e.MAGIC!=o.MAGIC||!o._tint)return;let t=e.canvas.getContext("2d");t.save(),t.resetTransform(),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.drawImage(d.canvas,0,0),t.restore()}return e.MAGIC==o.MAGIC&&null!=o._tint&&(!function(e,t){null==d&&(d=document.createElement("canvas").getContext("2d"));null==e&&(e=a.canvas.width,t=a.canvas.height);d.canvas.width==e&&d.canvas.height==t||(d.canvas.width=e,d.canvas.height=t)}(e.canvas.width,e.canvas.height),d.drawImage(e.canvas,0,0),e.tinted(o._tint)),r?l?(u||(u=h.width),c||(c=h.height),a.drawImage(h,l,s,u,c,t,n,r,i),void f()):(a.drawImage(h,t,n,r,i),void f()):(e.MAGIC==o.MAGIC||e.width?a.drawImage(h,t,n,e.width,e.height):a.drawImage(h,t,n,e.videoWidth,e.videoHeight),void f())},o.loadPixels=function(){s=a.getImageData(0,0,o.canvas.width,o.canvas.height),o.pixels=s.data},o.updatePixels=function(){null!=s&&a.putImageData(s,0,0)},o.loadImage=function(e,t){u++;let n=o.createGraphics(100,100),a=n.canvas.getContext("2d"),r=new Image;return r.src=e,r.crossOrigin="Anonymous",r.onload=function(){a.canvas.width=r.width,a.canvas.height=r.height,n.width=r.width,n.height=r.height,a.drawImage(r,0,0),u--,t&&t(n)},n};let w={};function R(e,t){null==f&&(f=document.createElement("canvas").getContext("2d")),null==e&&(e=a.canvas.width,t=a.canvas.height),f.canvas.width==e&&f.canvas.height==t||(f.canvas.width=e,f.canvas.height=t)}function I(){let e=a.canvas.width*a.canvas.height*4;null!=p&&e==p.length||(p=new Uint8ClampedArray(e))}function S(e){f.clearRect(0,0,f.canvas.width,f.canvas.height),f.filter=e,f.drawImage(a.canvas,0,0),a.save(),a.resetTransform(),a.clearRect(0,0,a.canvas.width,a.canvas.height),a.drawImage(f.canvas,0,0),a.restore()}w[o.THRESHOLD]=function(e,t){null==t?t=127.5:t*=255;for(let n=0;n<e.length;n+=4){const o=.2126*e[n]+.7152*e[n+1]+.0722*e[n+2];e[n]=e[n+1]=e[n+2]=o>=t?255:0}},w[o.GRAY]=function(e){for(let t=0;t<e.length;t+=4){const n=.2126*e[t]+.7152*e[t+1]+.0722*e[t+2];e[t]=e[t+1]=e[t+2]=n}},w[o.OPAQUE]=function(e){for(let t=0;t<e.length;t+=4)e[t+3]=255},w[o.INVERT]=function(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]},w[o.POSTERIZE]=function(e,t){let n=t-1;for(let o=0;o<e.length;o+=4)e[o]=255*(e[o]*t>>8)/n,e[o+1]=255*(e[o+1]*t>>8)/n,e[o+2]=255*(e[o+2]*t>>8)/n},w[o.DILATE]=function(e){I(),p.set(e);let[t,n]=[a.canvas.width,a.canvas.height];for(let o=0;o<n;o++)for(let a=0;a<t;a++){let r=4*Math.max(a-1,0),i=4*Math.min(a+1,t-1),l=4*Math.max(o-1,0)*t,s=4*Math.min(o+1,n-1)*t,u=4*o*t,c=4*a;for(let t=0;t<4;t++){let n=t+l,o=t+s,a=t+u;e[u+c+t]=Math.max(p[n+c],p[a+r],p[a+c],p[a+i],p[o+c])}}},w[o.ERODE]=function(e){I(),p.set(e);let[t,n]=[a.canvas.width,a.canvas.height];for(let o=0;o<n;o++)for(let a=0;a<t;a++){let r=4*Math.max(a-1,0),i=4*Math.min(a+1,t-1),l=4*Math.max(o-1,0)*t,s=4*Math.min(o+1,n-1)*t,u=4*o*t,c=4*a;for(let t=0;t<4;t++){let n=t+l,o=t+s,a=t+u;e[u+c+t]=Math.min(p[n+c],p[a+r],p[a+c],p[a+i],p[o+c])}}},w[o.BLUR]=function(e,t){t=t||1,t=Math.floor(t*o._pixelDensity),I(),p.set(e);let n=2*t+1;let r=function(e){let n=new Float32Array(e),o=.3*t+.8,a=o*o*2;for(let t=0;t<e;t++){let r=t-e/2,i=Math.exp(-r*r/a)/(2.5066282746*o);n[t]=i}return n}(n),[i,l]=[a.canvas.width,a.canvas.height];for(let o=0;o<l;o++)for(let a=0;a<i;a++){let l=0,s=0,u=0,c=0;for(let e=0;e<n;e++){let n=4*(o*i+Math.min(Math.max(a-t+e,0),i-1));l+=p[n]*r[e],s+=p[n+1]*r[e],u+=p[n+2]*r[e],c+=p[n+3]*r[e]}let h=4*(o*i+a);e[h]=l,e[h+1]=s,e[h+2]=u,e[h+3]=c}p.set(e);for(let o=0;o<l;o++)for(let a=0;a<i;a++){let s=0,u=0,c=0,h=0;for(let e=0;e<n;e++){let n=4*(Math.min(Math.max(o-t+e,0),l-1)*i+a);s+=p[n]*r[e],u+=p[n+1]*r[e],c+=p[n+2]*r[e],h+=p[n+3]*r[e]}let f=4*(o*i+a);e[f]=s,e[f+1]=u,e[f+2]=c,e[f+3]=h}},w[o.BRIGHTNESS]=function(e,t){t=null==t?1.5:t;for(let n=0;n<e.length;n+=4)e[n]*=t,e[n+1]*=t,e[n+2]*=t},w[o.CONTRAST]=function(e,t){t=null==t?1.5:t;for(let n=0;n<e.length;n+=4)e[n+0]=255*((e[n+0]/255-.5)*t+.5),e[n+1]=255*((e[n+1]/255-.5)*t+.5),e[n+2]=255*((e[n+2]/255-.5)*t+.5)},w[o.SATURATE]=function(e,t){t=null==t?1.5:t;const n=.3086*(1-(t=Math.max(0,t))),o=.6094*(1-t),a=.082*(1-t),r=width<<2;for(let i=0;i<height;i++){const l=i*r;for(let r=0;r<width;r++){const i=l+(r<<2),s=e[i+0],u=e[i+1],c=e[i+2];e[i+0]=(n+t)*s+o*u+a*c,e[i+1]=n*s+(o+t)*u+a*c,e[i+2]=n*s+o*u+(a+t)*c}}},o.filter=function(e,t){if(o.HARDWARE_FILTERS&&null!=a.filter)if(R(),e==o.THRESHOLD){null==t&&(t=.5),t=Math.max(t,1e-5),S(`saturate(0%) brightness(${Math.floor(.5/t*100)}%) contrast(1000000%)`)}else if(e==o.GRAY)S("saturate(0%)");else if(e==o.OPAQUE)f.fillStyle="black",f.fillRect(0,0,f.canvas.width,f.canvas.height),f.drawImage(a.canvas,0,0),a.save(),a.resetTransform(),a.drawImage(f.canvas,0,0),a.restore();else if(e==o.INVERT)S("invert(100%)");else if(e==o.BLUR)S(`blur(${Math.ceil(t*o._pixelDensity/1)||1}px)`);else if(e==o.BRIGHTNESS){t=null==t?1.5:t,S(`brightness(${100*Math.max(0,t)}%)`)}else if(e==o.CONTRAST){t=null==t?1.5:t,S(`contrast(${100*Math.max(0,t)}%)`)}else if(e==o.SATURATE){t=null==t?1.5:t,S(`saturate(${100*Math.max(0,t)}%)`)}else{let n=a.getImageData(0,0,a.canvas.width,a.canvas.height);w[e](n.data,t),a.putImageData(n,0,0)}else{let n=a.getImageData(0,0,a.canvas.width,a.canvas.height);w[e](n.data,t),a.putImageData(n,0,0)}},o.resize=function(e,t){R(),f.drawImage(a.canvas,0,0),o.width=e,o.height=t,a.canvas.width=e*o._pixelDensity,a.canvas.height=t*o._pixelDensity,a.save(),a.resetTransform(),a.clearRect(0,0,a.canvas.width,a.canvas.height),a.drawImage(f.canvas,0,0,a.canvas.width,a.canvas.height),a.restore()},o.get=function(e,t,n,r){if(null!=e&&null==n){let n=a.getImageData(e,t,1,1).data;return new o.Color(n[0],n[1],n[2],n[3]/255)}e=e||0,t=t||0,n=n||o.width,r=r||o.height;let i=o.createGraphics(n,r);i.pixelDensity(o._pixelDensity);let l=a.getImageData(e*o._pixelDensity,t*o._pixelDensity,n*o._pixelDensity,r*o._pixelDensity);return i.canvas.getContext("2d").putImageData(l,0,0),i},o.set=function(e,t,n){if(n.MAGIC==o.MAGIC){let a=o._tint;return o._tint=null,o.image(n,e,t),void(o._tint=a)}let r=4*(t*o._pixelDensity*a.canvas.width+e*o._pixelDensity);o.pixels[r]=n._r,o.pixels[r+1]=n._g,o.pixels[r+2]=n._b,o.pixels[r+3]=255*n._a},o.tinted=function(){let e=o.color(...Array.from(arguments)),t=e._a;e._a=1,R(),f.clearRect(0,0,f.canvas.width,f.canvas.height),f.fillStyle=e,f.fillRect(0,0,f.canvas.width,f.canvas.height),f.globalCompositeOperation="multiply",f.drawImage(a.canvas,0,0),f.globalCompositeOperation="source-over",a.save(),a.resetTransform();let n=a.globalCompositeOperation;a.globalCompositeOperation="source-in",a.drawImage(f.canvas,0,0),a.globalCompositeOperation=n,a.restore(),f.globalAlpha=t,f.clearRect(0,0,f.canvas.width,f.canvas.height),f.drawImage(a.canvas,0,0),f.globalAlpha=1,a.save(),a.resetTransform(),a.clearRect(0,0,a.canvas.width,a.canvas.height),a.drawImage(f.canvas,0,0),a.restore()},o.tint=function(){o._tint=o.color(...Array.from(arguments))},o.noTint=function(){o._tint=null},o.mask=function(e){a.save(),a.resetTransform();let t=a.globalCompositeOperation;a.globalCompositeOperation="destination-in",a.drawImage(e.canvas,0,0),a.globalCompositeOperation=t,a.restore()},o.clearTemporaryBuffers=function(){f=null,d=null,p=null},o.save=function(e,t){e=e||"untitled",t=t||"png";var n=document.createElement("a");n.innerHTML="[Download]",n.addEventListener("click",(function(){this.href=a.canvas.toDataURL(),this.download=e+"."+t}),!1),document.body.appendChild(n),n.click(),document.body.removeChild(n)},o.saveCanvas=function(e,t,n){if(e.MAGIC==o.MAGIC){n&&e.save(t,n);let o=t.split(".");return e.save(o.slice(0,-1).join("."),o[o.length-1])}if(t)return o.save(e,t);let a=e.split(".");return o.save(a.slice(0,-1).join("."),a[a.length-1])},o.loadFont=function(e,t,n){let o=e.split("/"),a=o[o.length-1].split(".")[0].replace(" ","");return new FontFace(a,`url('${e}')`).load().then((function(e){document.fonts.add(e),t&&t(a)}),(function(e){n&&n(e)})),a},o.textFont=function(e){o._style.textFont=e},o.textSize=function(e){o._style.textSize=e,o._style.textLeading=e},o.textLeading=function(e){o._style.textLeading=e},o.textStyle=function(e){o._style.textStyle=e},o.textAlign=function(e,t){a.textAlign=e,t&&(a.textBaseline=t==o.CENTER?"middle":t)},o.text=function(e,t,n,r){if(!e)return;if(e=e.toString(),o._style.noFill&&o._style.noStroke)return;a.font=`${o._style.textStyle} ${o._style.textSize}px ${o._style.textFont}`;let i=e.split("\n");for(let e=0;e<i.length;e++)o._style.noFill||a.fillText(i[e],t,n,r),o._style.noStroke||a.strokeText(i[e],t,n,r),n+=o._style.textLeading},o.textWidth=function(e){return a.font=`${o._style.textStyle} ${o._style.textSize}px ${o._style.textFont}`,a.measureText(e).width},o.textAscent=function(e){return a.font=`${o._style.textStyle} ${o._style.textSize}px ${o._style.textFont}`,a.measureText(e).actualBoundingBoxAscent},o.textDescent=function(e){return a.font=`${o._style.textStyle} ${o._style.textSize}px ${o._style.textFont}`,a.measureText(e).actualBoundingBoxDescent};var C,E=4095,T=4,A=.5,D=function(e){return.5*(1-Math.cos(e*Math.PI))};o.noise=function(e,t,n){if(t=t||0,n=n||0,null==C){C=new Array(4096);for(var o=0;o<4096;o++)C[o]=Math.random()}e<0&&(e=-e),t<0&&(t=-t),n<0&&(n=-n);for(var a,r,i,l,s,u=Math.floor(e),c=Math.floor(t),h=Math.floor(n),f=e-u,d=t-c,p=n-h,y=0,m=.5,g=0;g<T;g++){var v=u+(c<<4)+(h<<8);a=D(f),r=D(d),i=C[v&E],i+=a*(C[v+1&E]-i),l=C[v+16&E],i+=r*((l+=a*(C[v+16+1&E]-l))-i),l=C[(v+=256)&E],l+=a*(C[v+1&E]-l),s=C[v+16&E],l+=r*((s+=a*(C[v+16+1&E]-s))-l),y+=(i+=D(p)*(l-i))*m,m*=A,u<<=1,c<<=1,h<<=1,(f*=2)>=1&&(u++,f--),(d*=2)>=1&&(c++,d--),(p*=2)>=1&&(h++,p--)}return y},o.noiseDetail=function(e,t){e>0&&(T=e),t>0&&(A=t)};const P=function(){let e,t,n=4294967295;return{setSeed(o){e=t=(null==o?Math.random()*n:o)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/n)}};let b=P();b.setSeed(),o.noiseSeed=function(e){let t=null==e?4294967295*Math.random():e;C||(C=new Float32Array(4096));for(var n=0;n<4096;n++)t^=t<<17,t^=t>>13,t^=t<<5,C[n]=(t>>>0)/4294967295},o.randomSeed=function(e){b.setSeed(e)},o.random=function(e,t){return null==e?b.rand():"number"==typeof e?null!=t?b.rand()*(t-e)+e:b.rand()*e:e[~~(e.length*b.rand())]},o.randomGenerator=function(e){e==o.LCG?b=function(){const e=4294967296;let t,n;return{setSeed(o){n=t=(null==o?Math.random()*e:o)>>>0},getSeed:()=>t,rand:()=>(n=(1664525*n+1013904223)%e,n/e)}}():e==o.SHR3&&(b=P()),b.setSeed()};var O=new function(){var e,t,n,o=new Array(128),a=new Array(256),r=new Array(128),i=new Array(128),l=new Array(256),s=new Array(256),u=function(){return 4294967296*b.rand()-2147483648},c=function(){return.5+2.328306e-10*(u()|0)},h=function(){for(var t,a,l,s,h=3.44262;;){if(t=n*r[e],0==e){do{l=c(),s=c(),t=.2904764*-Math.log(l),a=-Math.log(s)}while(a+a<t*t);return n>0?h+t:-h-t}if(i[e]+c()*(i[e-1]-i[e])<Math.exp(-.5*t*t))return t;if(n=u(),e=127&n,Math.abs(n)<o[e])return n*r[e]}},f=function(){for(var n;;){if(0==e)return 7.69711-Math.log(c());if(n=t*l[e],s[e]+c()*(s[e-1]-s[e])<Math.exp(-n))return n;if((t=u())<a[e=255&t])return t*l[e]}};this.SHR3=u,this.UNI=c,this.RNOR=function(){return n=u(),e=127&n,Math.abs(n)<o[e]?n*r[e]:h()},this.REXP=function(){return(t=u()>>>0)<o[e=255&t]?t*l[e]:f()},this.zigset=function(){var e,t,n=2147483648,u=4294967296,c=3.442619855899,h=c,f=.00991256303526217,d=7.697117470131487,p=d,y=.003949659822581572;for(e=f/Math.exp(-.5*c*c),o[0]=Math.floor(c/e*n),o[1]=0,r[0]=e/n,r[127]=c/n,i[0]=1,i[127]=Math.exp(-.5*c*c),t=126;t>=1;t--)c=Math.sqrt(-2*Math.log(f/c+Math.exp(-.5*c*c))),o[t+1]=Math.floor(c/h*n),h=c,i[t]=Math.exp(-.5*c*c),r[t]=c/n;for(e=y/Math.exp(-d),a[0]=Math.floor(d/e*u),a[1]=0,l[0]=e/u,l[255]=d/u,s[0]=1,s[255]=Math.exp(-d),t=254;t>=1;t--)d=-Math.log(y/d+Math.exp(-d)),a[t+1]=Math.floor(d/p*u),p=d,s[t]=Math.exp(-d),l[t]=d/u}};O.hasInit=!1,o.randomGaussian=function(e,t){return O.hasInit||(O.zigset(),O.hasInit=!0),O.RNOR()*t+e},o.randomExponential=function(){return O.hasInit||(O.zigset(),O.hasInit=!0),O.REXP()},o.print=console.log,o.cursor=function(e,t,n){let a="";e.includes(".")&&(e=`url("${e}")`,a=", auto"),null!=t&&(e+=" "+t+" "+n),o.canvas.style.cursor=e+a},o.noCursor=function(){o.canvas.style.cursor="none"},o.createCapture=function(e){var t=document.createElement("video");return t.playsinline="playsinline",t.autoplay="autoplay",navigator.mediaDevices.getUserMedia(e).then((function(e){t.srcObject=e})),t.style.position="absolute",t.style.opacity=1e-5,t.style.zIndex=-1e3,document.body.appendChild(t),t};let z=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchEnded"];for(let e of z){let t="_"+e+"Fn";o[t]=function(){},o[t].isPlaceHolder=!0,o[e]?o[t]=o[e]:Object.defineProperty(o,e,{set:function(e){o[t]=e}})}function k(){o._noLoop||(r=null==o._frameRate?requestAnimationFrame(k):setTimeout(k,1e3/o._frameRate)),x(),i=!0,o.push(),o._drawFn(),o.pop(),++o.frameCount}function F(e){const t=o.canvas.getBoundingClientRect(),n=o.canvas.scrollWidth/o.width||1,a=o.canvas.scrollHeight/o.height||1;return{x:(e.clientX-t.left)/n,y:(e.clientY-t.top)/a,id:e.identifier}}function L(){return o._touchStarted.isPlaceHolder&&o._touchMoved.isPlaceHolder&&o._touchEnded.isPlaceHolder}o.noLoop=function(){o._noLoop=!0,r=null},o.loop=function(){o._noLoop=!1,null==r&&k()},o.redraw=function(){k()},o.frameRate=function(e){o._frameRate=e},setTimeout((function(){o._preloadFn(),h=window.performance.now(),function e(){if(u>0)return setTimeout(e,10);o._setupFn(),k()}()}),1),o.canvas.onmousemove=function(e){o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=e.offsetX,o.mouseY=e.offsetY,o.mouseIsPressed?o._mouseDraggedFn(e):o._mouseMovedFn(e)},o.canvas.onmousedown=function(e){o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=e.offsetX,o.mouseY=e.offsetY,o.mouseIsPressed=!0,o.mouseButton=[o.LEFT,o.CENTER,o.RIGHT][e.button],o._mousePressedFn(e)},o.canvas.onmouseup=function(e){o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=e.offsetX,o.mouseY=e.offsetY,o.mouseIsPressed=!1,o._mouseReleasedFn(e)},o.canvas.onclick=function(e){o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=e.offsetX,o.mouseY=e.offsetY,o.mouseIsPressed=!0,o._mouseClickedFn(e),o.mouseIsPressed=!1},window.addEventListener("keydown",(function(e){o.keyIsPressed=!0,o.key=e.key,o.keyCode=e.keyCode,c[o.keyCode]=!0,o._keyPressedFn(e),1==e.key.length&&o._keyTypedFn(e)})),window.addEventListener("keyup",(function(e){o.keyIsPressed=!1,o.key=e.key,o.keyCode=e.keyCode,c[o.keyCode]=!1,o._keyReleasedFn(e)})),o.keyIsDown=function(e){return!!c[e]},o.canvas.ontouchstart=function(e){o.touches=e.touches.map(F),L()&&(o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=o.touches[0].x,o.mouseY=o.touches[0].y,o.mouseIsPressed=!0,o.mouseButton=o.LEFT,o._mousePressedFn(e)||e.preventDefault()),o._touchStartedFn(e)||e.preventDefault()},o.canvas.ontouchmove=function(e){o.touches=e.touches.map(F),L()&&(o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=o.touches[0].x,o.mouseY=o.touches[0].y,o.mouseIsPressed=!0,o.mouseButton=o.LEFT,o._mouseDraggedFn(e)||e.preventDefault()),o._touchMovedFn(e)||e.preventDefault()},o.canvas.ontouchend=o.canvas.ontouchcancel=function(e){o.touches=e.touches.map(F),L()&&(o.pmouseX=o.mouseX,o.pmouseY=o.mouseY,o.mouseX=o.touches[0].x,o.mouseY=o.touches[0].y,o.mouseIsPressed=!1,o._mouseReleasedFn(e)||e.preventDefault()),o._touchEndedFn(e)||e.preventDefault()},o.hasSensorPermission=!window.DeviceOrientationEvent&&!window.DeviceMotionEvent||!(DeviceOrientationEvent.requestPermission||DeviceMotionEvent.requestPermission),o.requestSensorPermissions=function(){DeviceOrientationEvent.requestPermission&&DeviceOrientationEvent.requestPermission().then((e=>{"granted"==e&&DeviceMotionEvent.requestPermission&&DeviceMotionEvent.requestPermission().then((e=>{"granted"==e&&(o.hasSensorPermission=!0)})).catch(alert)})).catch(alert)};window.ondeviceorientation=function(e){o.pRotationX=o.rotationX,o.pRotationY=o.rotationY,o.pRotationZ=o.rotationZ,o.pRelRotationX=o.relRotationX,o.pRelRotationY=o.relRotationY,o.pRelRotationZ=o.relRotationZ,o.rotationX=e.beta*(Math.PI/180),o.rotationY=e.gamma*(Math.PI/180),o.rotationZ=e.alpha*(Math.PI/180),o.relRotationX=[-o.rotationY,-o.rotationX,o.rotationY][1+~~(window.orientation/90)],o.relRotationY=[-o.rotationX,o.rotationY,o.rotationX][1+~~(window.orientation/90)],o.relRotationZ=o.rotationZ},window.ondevicemotion=function(e){if(o.pAccelerationX=o.accelerationX,o.pAccelerationY=o.accelerationY,o.pAccelerationZ=o.accelerationZ,!e.acceleration){let r=((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])])((a=o.rotationY,t=[Math.cos(a),0,Math.sin(a),0,0,1,0,0,-Math.sin(a),0,Math.cos(a),0,0,0,0,1],n=(e=>[1,0,0,0,0,Math.cos(e),-Math.sin(e),0,0,Math.sin(e),Math.cos(e),0,0,0,0,1])(o.rotationX),[t[0]*n[0]+t[1]*n[4]+t[2]*n[8]+t[3]*n[12],t[0]*n[1]+t[1]*n[5]+t[2]*n[9]+t[3]*n[13],t[0]*n[2]+t[1]*n[6]+t[2]*n[10]+t[3]*n[14],t[0]*n[3]+t[1]*n[7]+t[2]*n[11]+t[3]*n[15],t[4]*n[0]+t[5]*n[4]+t[6]*n[8]+t[7]*n[12],t[4]*n[1]+t[5]*n[5]+t[6]*n[9]+t[7]*n[13],t[4]*n[2]+t[5]*n[6]+t[6]*n[10]+t[7]*n[14],t[4]*n[3]+t[5]*n[7]+t[6]*n[11]+t[7]*n[15],t[8]*n[0]+t[9]*n[4]+t[10]*n[8]+t[11]*n[12],t[8]*n[1]+t[9]*n[5]+t[10]*n[9]+t[11]*n[13],t[8]*n[2]+t[9]*n[6]+t[10]*n[10]+t[11]*n[14],t[8]*n[3]+t[9]*n[7]+t[10]*n[11]+t[11]*n[15],t[12]*n[0]+t[13]*n[4]+t[14]*n[8]+t[15]*n[12],t[12]*n[1]+t[13]*n[5]+t[14]*n[9]+t[15]*n[13],t[12]*n[2]+t[13]*n[6]+t[14]*n[10]+t[15]*n[14],t[12]*n[3]+t[13]*n[7]+t[14]*n[11]+t[15]*n[15]]),[0,0,-9.80665]);o.accelerationX=e.accelerationIncludingGravity.x+r[0],o.accelerationY=e.accelerationIncludingGravity.y+r[1],o.accelerationZ=e.accelerationIncludingGravity.z-r[2]}var t,n,a},o.year=function(){return(new Date).getFullYear()},o.day=function(){return(new Date).getDay()},o.hour=function(){return(new Date).getHours()},o.minute=function(){return(new Date).getMinutes()},o.second=function(){return(new Date).getSeconds()},o.millis=function(){return window.performance.now()-h}}(e)}"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=Q5);