diff --git a/Gruntfile.js b/Gruntfile.js index 0a41d41b..447d94a9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -87,7 +87,8 @@ module.exports = function(grunt) { 'reverb': 'src/reverb', 'looper': 'src/looper', 'soundRecorder': 'src/soundRecorder', - 'signal': 'src/signal' + 'signal': 'src/signal', + 'metro': 'src/metro' }, useStrict: true, wrap: { diff --git a/lib/p5.js b/lib/p5.js index 6c118710..b9811319 100644 --- a/lib/p5.js +++ b/lib/p5.js @@ -1,4 +1,4 @@ -/*! p5.js v0.3.2 August 13, 2014 */ +/*! p5.js v0.3.3 August 22, 2014 */ var shim = function (require) { window.requestDraw = function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) { @@ -195,7 +195,13 @@ var core = function (require, shim, constants) { if (typeof userSetup === 'undefined') { this.scale(this._pixelDensity, this._pixelDensity); } + this._registeredMethods.pre.forEach(function (f) { + f.call(this); + }); userDraw(); + this._registeredMethods.post.forEach(function (f) { + f.call(this); + }); this.pop(); } }.bind(this); @@ -234,8 +240,11 @@ var core = function (require, shim, constants) { e.elt.removeEventListener(elt_ev, e._events[elt_ev]); } } + var self = this; this._registeredMethods.remove.forEach(function (f) { - f.call(this); + if (typeof f !== 'undefined') { + f.call(self); + } }); if (this._isGlobal) { for (var p in p5.prototype) { @@ -256,7 +265,6 @@ var core = function (require, shim, constants) { } } } - window.p5 = undefined; }.bind(this); for (var k in constants) { p5.prototype[k] = constants[k]; @@ -310,7 +318,11 @@ var core = function (require, shim, constants) { 'loadShape', 'loadTable' ]; - p5.prototype._registeredMethods = { remove: [] }; + p5.prototype._registeredMethods = { + pre: [], + post: [], + remove: [] + }; p5.prototype.registerPreloadMethod = function (m) { p5.prototype._preloadMethods.push(m); }.bind(this); @@ -319,7 +331,6 @@ var core = function (require, shim, constants) { p5.prototype._registeredMethods[name] = []; } p5.prototype._registeredMethods[name].push(m); - console.log(p5.prototype._registeredMethods); }.bind(this); return p5; }({}, shim, constants); @@ -518,6 +529,9 @@ var p5Element = function (require, core) { p5.Element.prototype.mousePressed = function (fxn) { attachListener('mousedown', fxn, this); }; + p5.Element.prototype.mouseWheel = function (fxn) { + attachListener('mousewheel', fxn, this); + }; p5.Element.prototype.mouseReleased = function (fxn) { attachListener('mouseup', fxn, this); }; @@ -984,28 +998,31 @@ var p5Image = function (require, core, filters) { p5.Image.prototype.blend = function () { p5.prototype.blend.apply(this, arguments); }; - p5.Image.prototype.save = function (extension) { + p5.Image.prototype.save = function (filename, extension) { var mimeType; - switch (extension.toLowerCase()) { - case 'png': - mimeType = 'image/png'; - break; - case 'jpeg': - mimeType = 'image/jpeg'; - break; - case 'jpg': - mimeType = 'image/jpeg'; - break; - default: + if (!extension) { + extension = 'png'; mimeType = 'image/png'; - break; - } - if (mimeType !== undefined) { - var downloadMime = 'image/octet-stream'; - var imageData = this.canvas.toDataURL(mimeType); - imageData = imageData.replace(mimeType, downloadMime); - window.location.href = imageData; + } else { + switch (extension.toLowerCase()) { + case 'png': + mimeType = 'image/png'; + break; + case 'jpeg': + mimeType = 'image/jpeg'; + break; + case 'jpg': + mimeType = 'image/jpeg'; + break; + default: + mimeType = 'image/png'; + break; + } } + var downloadMime = 'image/octet-stream'; + var imageData = this.canvas.toDataURL(mimeType); + imageData = imageData.replace(mimeType, downloadMime); + p5.prototype.downloadFile(imageData, filename, extension); }; return p5.Image; }({}, core, filters); @@ -2941,8 +2958,13 @@ var inputmouse = function (require, core, constants) { var mousePos = getMousePos(this._curElement.elt, e); this._setProperty('pmouseX', this.mouseX); this._setProperty('pmouseY', this.mouseY); - this._setProperty('mouseX', mousePos.x); - this._setProperty('mouseY', mousePos.y); + if (e.type === 'touchstart' || e.type === 'touchmove') { + this._setProperty('mouseX', this.touchX); + this._setProperty('mouseY', this.touchY); + } else { + this._setProperty('mouseX', mousePos.x); + this._setProperty('mouseY', mousePos.y); + } this._setProperty('pwinMouseX', this.winMouseX); this._setProperty('pwinMouseY', this.winMouseY); this._setProperty('winMouseX', e.pageX); @@ -2962,6 +2984,10 @@ var inputmouse = function (require, core, constants) { this._setProperty('mouseButton', constants.RIGHT); } else { this._setProperty('mouseButton', constants.LEFT); + if (e.type === 'touchstart' || e.type === 'touchmove') { + this._setProperty('mouseX', this.touchX); + this._setProperty('mouseY', this.touchY); + } } }; p5.prototype.onmousemove = function (e) { @@ -2970,15 +2996,13 @@ var inputmouse = function (require, core, constants) { if (!this.isMousePressed) { if (typeof context.mouseMoved === 'function') { context.mouseMoved(e); - } else if (typeof context.touchMoved === 'function') { - e.preventDefault(); - context.touchMoved(e); } } else { if (typeof context.mouseDragged === 'function') { context.mouseDragged(e); } else if (typeof context.touchMoved === 'function') { e.preventDefault(); + this.setTouchPoints(e); context.touchMoved(e); } } @@ -2992,6 +3016,7 @@ var inputmouse = function (require, core, constants) { context.mousePressed(e); } else if (typeof context.touchStarted === 'function') { e.preventDefault(); + this.setTouchPoints(e); context.touchStarted(e); } }; @@ -3003,6 +3028,7 @@ var inputmouse = function (require, core, constants) { context.mouseReleased(e); } else if (typeof context.touchEnded === 'function') { e.preventDefault(); + this.setTouchPoints(e); context.touchEnded(e); } }; @@ -3055,48 +3081,55 @@ var inputtouch = function (require, core) { p5.prototype.touches = []; p5.prototype.setTouchPoints = function (e) { var context = this._isGlobal ? window : this; - context._setProperty('touchX', e.changedTouches[0].pageX); - context._setProperty('touchY', e.changedTouches[0].pageY); - var touches = []; - for (var i = 0; i < e.changedTouches.length; i++) { - var ct = e.changedTouches[i]; - touches[i] = { - x: ct.pageX, - y: ct.pageY - }; + if (e.type === 'mousedown' || e.type === 'mousemove') { + context._setProperty('touchX', context.mouseX); + context._setProperty('touchY', context.mouseY); + } else { + context._setProperty('touchX', e.changedTouches[0].pageX); + context._setProperty('touchY', e.changedTouches[0].pageY); + var touches = []; + for (var i = 0; i < e.changedTouches.length; i++) { + var ct = e.changedTouches[i]; + touches[i] = { + x: ct.pageX, + y: ct.pageY + }; + } + context._setProperty('touches', touches); } - context._setProperty('touches', touches); }; p5.prototype.ontouchstart = function (e) { var context = this._isGlobal ? window : this; - context.setTouchPoints(e); + this.setTouchPoints(e); if (typeof context.touchStarted === 'function') { e.preventDefault(); context.touchStarted(e); } else if (typeof context.mousePressed === 'function') { e.preventDefault(); + this.setMouseButton(e); context.mousePressed(e); } }; p5.prototype.ontouchmove = function (e) { var context = this._isGlobal ? window : this; - context.setTouchPoints(e); + this.setTouchPoints(e); if (typeof context.touchMoved === 'function') { e.preventDefault(); context.touchMoved(e); } else if (typeof context.mouseDragged === 'function') { e.preventDefault(); + this.updateMouseCoords(e); context.mouseDragged(e); } }; p5.prototype.ontouchend = function (e) { var context = this._isGlobal ? window : this; - context.setTouchPoints(e); if (typeof context.touchEnded === 'function') { e.preventDefault(); context.touchEnded(e); } else if (typeof context.mouseReleased === 'function') { e.preventDefault(); + this.updateMouseCoords(e); context.mouseReleased(e); } }; @@ -3480,6 +3513,46 @@ var outputfiles = function (require, core) { p5.prototype.saveBytes = function () { throw 'not yet implemented'; }; + p5.prototype.save = function (object, _filename, _options) { + var args = arguments; + var cnv = this._curElement.elt; + if (args.length === 0) { + p5.prototype.saveCanvas(null, null, cnv); + return; + } + if (typeof args[0] === 'string') { + if (typeof args[2] === 'object') { + p5.prototype.saveCanvas(args[0], args[1], args[2]); + } else if (typeof args[1] === 'string') { + p5.prototype.saveCanvas(args[0], args[1], cnv); + } else { + p5.prototype.saveCanvas(args[0], null, cnv); + } + return; + } else { + var extension = _checkFileExtension(args[1], args[2])[1]; + switch (extension) { + case 'json': + p5.prototype.saveJSON(args[0], args[1], args[2]); + break; + case 'txt': + p5.prototype.saveStrings(args[0], args[1], args[2]); + break; + default: + if (args[0] instanceof Array) { + p5.prototype.saveStrings(args[0], args[1], args[2]); + } else if (args[0] instanceof p5.Table) { + p5.prototype.saveTable(args[0], args[1], args[2], args[3]); + } else if (args[0] instanceof p5.Image) { + p5.prototype.saveCanvas(args[1], args[2], args[0].canvas); + } else if (args[0] instanceof p5.SoundFile) { + p5.prototype.saveSound(args[0], args[1], args[2], args[3]); + } else if (args[0] instanceof Object) { + p5.prototype.saveJSON(args[0], args[1], args[2]); + } + } + } + }; p5.prototype.saveJSON = function (json, filename, opt) { var stringify; if (opt) { @@ -3578,30 +3651,25 @@ var outputfiles = function (require, core) { pWriter.flush(); }; p5.prototype.writeFile = function (dataToDownload, filename, extension) { - var ext = ''; - var a = document.createElement('a'); var type = 'application/octet-stream'; - if (_isSafari()) { + if (p5.prototype._isSafari()) { type = 'text/plain'; } - if (filename) { - ext = _checkFileExtension(filename); - } else { - filename = 'untitled'; - } - if (extension) { - if (ext !== extension) { - ext = extension; - filename = filename + '.' + ext; - } - } var blob = new Blob(dataToDownload, { 'type': type }); - a.href = window.URL.createObjectURL(blob); + var href = window.URL.createObjectURL(blob); + p5.prototype.downloadFile(href, filename, extension); + }; + p5.prototype.downloadFile = function (href, fName, extension) { + var fx = _checkFileExtension(fName, extension); + var filename = fx[0]; + var ext = fx[1]; + var a = document.createElement('a'); + a.href = href; a.download = filename; a.onclick = destroyClickedElement; a.style.display = 'none'; document.body.appendChild(a); - if (_isSafari()) { + if (p5.prototype._isSafari()) { var aText = 'Hello, Safari user! To download this file...\n'; aText += '1. Go to File --> Save As.\n'; aText += '2. Choose "Page Source" as the Format.\n'; @@ -3609,15 +3677,33 @@ var outputfiles = function (require, core) { alert(aText); } a.click(); - blob = null; + href = null; }; - function _checkFileExtension(filename) { - return filename.split('.').pop(); + function _checkFileExtension(filename, extension) { + if (!extension) { + extension = ''; + } + var ext = ''; + if (filename) { + ext = filename.split('.').pop(); + } else { + filename = 'untitled'; + } + if (extension) { + if (ext !== extension) { + ext = extension; + filename = filename + '.' + ext; + } + } + return [ + filename, + ext + ]; } - function _isSafari() { + p5.prototype._isSafari = function () { var x = Object.prototype.toString.call(window.HTMLElement); return x.indexOf('Constructor') > 0; - } + }; function destroyClickedElement(event) { document.body.removeChild(event.target); } @@ -3626,8 +3712,109 @@ var outputfiles = function (require, core) { var outputimage = function (require, core) { 'use strict'; var p5 = core; - p5.prototype.save = function () { - window.open(this._curElement.elt.toDataURL('image/png')); + var frames = []; + p5.prototype.saveCanvas = function (filename, extension, _cnv) { + var cnv; + if (_cnv) { + cnv = _cnv; + } else if (this._curElement && this._curElement.elt) { + cnv = this._curElement.elt; + } + if (p5.prototype._isSafari()) { + var aText = 'Hello, Safari user!\n'; + aText += 'Now capturing a screenshot...\n'; + aText += 'To save this image,\n'; + aText += 'go to File --> Save As.\n'; + alert(aText); + window.location.href = cnv.toDataURL(); + } else { + var mimeType; + if (!extension) { + extension = 'png'; + mimeType = 'image/png'; + } else { + switch (extension.toLowerCase()) { + case 'png': + mimeType = 'image/png'; + break; + case 'jpeg': + mimeType = 'image/jpeg'; + break; + case 'jpg': + mimeType = 'image/jpeg'; + break; + default: + mimeType = 'image/png'; + break; + } + } + var downloadMime = 'image/octet-stream'; + var imageData = cnv.toDataURL(mimeType); + imageData = imageData.replace(mimeType, downloadMime); + p5.prototype.downloadFile(imageData, filename, extension); + } + }; + p5.prototype.saveFrames = function (fName, ext, _duration, _fps, callback) { + var duration = _duration || 3; + duration = p5.prototype.constrain(duration, 0, 15); + duration = duration * 1000; + var fps = _fps || 15; + fps = p5.prototype.constrain(fps, 0, 22); + var count = 0; + var makeFrame = p5.prototype._makeFrame; + var cnv = this._curElement.elt; + var frameFactory = setInterval(function () { + makeFrame(fName + count, ext, cnv); + count++; + }, 1000 / fps); + setTimeout(function () { + clearInterval(frameFactory); + if (callback) { + callback(frames); + } else { + for (var i = 0; i < frames.length; i++) { + var f = frames[i]; + p5.prototype.downloadFile(f.imageData, f.filename, f.ext); + } + } + frames = []; + }, duration + 0.01); + }; + p5.prototype._makeFrame = function (filename, extension, _cnv) { + var cnv; + if (this) { + cnv = this._curElement.elt; + } else { + cnv = _cnv; + } + var mimeType; + if (!extension) { + extension = 'png'; + mimeType = 'image/png'; + } else { + switch (extension.toLowerCase()) { + case 'png': + mimeType = 'image/png'; + break; + case 'jpeg': + mimeType = 'image/jpeg'; + break; + case 'jpg': + mimeType = 'image/jpeg'; + break; + default: + mimeType = 'image/png'; + break; + } + } + var downloadMime = 'image/octet-stream'; + var imageData = cnv.toDataURL(mimeType); + imageData = imageData.replace(mimeType, downloadMime); + var thisFrame = {}; + thisFrame.imageData = imageData; + thisFrame.filename = filename; + thisFrame.ext = extension; + frames.push(thisFrame); }; return p5; }({}, core); @@ -4168,25 +4355,8 @@ var transform = function (require, core, constants, outputtext_area) { 'use strict'; var p5 = core; var constants = constants; - p5.prototype._matrices = [[ - 1, - 0, - 0, - 1, - 0, - 0 - ]]; p5.prototype.applyMatrix = function (n00, n01, n02, n10, n11, n12) { this.drawingContext.transform(n00, n01, n02, n10, n11, n12); - var m = this._matrices[this._matrices.length - 1]; - m = multiplyMatrix(m, [ - n00, - n01, - n02, - n10, - n11, - n12 - ]); return this; }; p5.prototype.popMatrix = function () { @@ -4200,14 +4370,6 @@ var transform = function (require, core, constants, outputtext_area) { }; p5.prototype.resetMatrix = function () { this.drawingContext.setTransform(); - this._matrices[this._matrices.length - 1] = [ - 1, - 0, - 0, - 1, - 0, - 0 - ]; return this; }; p5.prototype.rotate = function (r) { @@ -4215,17 +4377,6 @@ var transform = function (require, core, constants, outputtext_area) { r = this.radians(r); } this.drawingContext.rotate(r); - var m = this._matrices[this._matrices.length - 1]; - var c = Math.cos(r); - var s = Math.sin(r); - var m11 = m[0] * c + m[2] * s; - var m12 = m[1] * c + m[3] * s; - var m21 = m[0] * -s + m[2] * c; - var m22 = m[1] * -s + m[3] * c; - m[0] = m11; - m[1] = m12; - m[2] = m21; - m[3] = m22; return this; }; p5.prototype.rotateX = function () { @@ -4243,11 +4394,6 @@ var transform = function (require, core, constants, outputtext_area) { y = arguments[1]; } this.drawingContext.scale(x, y); - var m = this._matrices[this._matrices.length - 1]; - m[0] *= x; - m[1] *= x; - m[2] *= y; - m[3] *= y; return this; }; p5.prototype.shearX = function (angle) { @@ -4255,15 +4401,6 @@ var transform = function (require, core, constants, outputtext_area) { angle = this.radians(angle); } this.drawingContext.transform(1, 0, this.tan(angle), 1, 0, 0); - var m = this._matrices[this._matrices.length - 1]; - m = multiplyMatrix(m, [ - 1, - 0, - this.tan(angle), - 1, - 0, - 0 - ]); return this; }; p5.prototype.shearY = function (angle) { @@ -4271,41 +4408,12 @@ var transform = function (require, core, constants, outputtext_area) { angle = this.radians(angle); } this.drawingContext.transform(1, this.tan(angle), 0, 1, 0, 0); - var m = this._matrices[this._matrices.length - 1]; - m = multiplyMatrix(m, [ - 1, - this.tan(angle), - 0, - 1, - 0, - 0 - ]); return this; }; p5.prototype.translate = function (x, y) { this.drawingContext.translate(x, y); - var m = this._matrices[this._matrices.length - 1]; - m[4] += m[0] * x + m[2] * y; - m[5] += m[1] * x + m[3] * y; return this; }; - function multiplyMatrix(m1, m2) { - var result = []; - var m1Length = m1.length; - var m2Length = m2.length; - var m10Length = m1[0].length; - for (var j = 0; j < m2Length; j++) { - result[j] = []; - for (var k = 0; k < m10Length; k++) { - var sum = 0; - for (var i = 0; i < m1Length; i++) { - sum += m1[i][k] * m2[j][i]; - } - result[j].push(sum); - } - } - return result; - } return p5; }({}, core, constants, outputtext_area); var typographyattributes = function (require, core, constants) { diff --git a/lib/p5.min.js b/lib/p5.min.js index 77b6bd60..79a795e9 100644 --- a/lib/p5.min.js +++ b/lib/p5.min.js @@ -1,5 +1,5 @@ -/*! p5.min.js v0.3.2 August 13, 2014 */ +/*! p5.min.js v0.3.3 August 22, 2014 */ -var shim=function(){window.requestDraw=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}()}({}),constants=function(){var t=Math.PI;return{ARROW:"default",CROSS:"crosshair",HAND:"pointer",MOVE:"move",TEXT:"text",WAIT:"wait",HALF_PI:t/2,PI:t,QUARTER_PI:t/4,TAU:2*t,TWO_PI:2*t,DEGREES:"degrees",RADIANS:"radians",CORNER:"corner",CORNERS:"corners",RADIUS:"radius",RIGHT:"right",LEFT:"left",CENTER:"center",POINTS:"points",LINES:"lines",TRIANGLES:"triangles",TRIANGLE_FAN:"triangles_fan",TRIANGLE_STRIP:"triangles_strip",QUADS:"quads",QUAD_STRIP:"quad_strip",CLOSE:"close",OPEN:"open",CHORD:"chord",PIE:"pie",PROJECT:"square",SQUARE:"butt",ROUND:"round",BEVEL:"bevel",MITER:"miter",RGB:"rgb",HSB:"hsb",AUTO:"auto",ALT:18,BACKSPACE:8,CONTROL:17,DELETE:46,DOWN_ARROW:40,ENTER:13,ESCAPE:27,LEFT_ARROW:37,OPTION:18,RETURN:13,RIGHT_ARROW:39,SHIFT:16,TAB:9,UP_ARROW:38,BLEND:"normal",ADDITIVE:"lighter",DARKEST:"darken",LIGHTEST:"lighten",DIFFERENCE:"difference",EXCLUSION:"exclusion",MULTIPLY:"multiply",SCREEN:"screen",REPLACE:"source-over",OVERLAY:"overlay",HARD_LIGHT:"hard-light",SOFT_LIGHT:"soft-light",DODGE:"color-dodge",BURN:"color-burn",NORMAL:"normal",ITALIC:"italic",BOLD:"bold",LINEAR:"linear",QUADRATIC:"quadratic",BEZIER:"bezier",CURVE:"curve"}}({}),core=function(t,e,r){"use strict";var r=r,o=function(t,e){this._setupDone=!1,this._pixelDensity=window.devicePixelRatio||1,this._startTime=(new Date).getTime(),this._userNode=e,this._curElement=null,this._elements=[],this._preloadCount=0,this._updateInterval=0,this._isGlobal=!1,this._loop=!0,this.styles=[],this._defaultCanvasSize={width:100,height:100},this._events={mousemove:null,mousedown:null,mouseup:null,click:null,mousewheel:null,mouseover:null,mouseout:null,keydown:null,keyup:null,keypress:null,touchstart:null,touchmove:null,touchend:null},this._start=function(){this._userNode&&"string"==typeof this._userNode&&(this._userNode=document.getElementById(this._userNode)),this.createCanvas(this._defaultCanvasSize.width,this._defaultCanvasSize.height,!0);var t=this.preload||window.preload,e=this._isGlobal?window:this;t?(this._preloadMethods.forEach(function(t){e[t]=function(r){return e._preload(t,r)}}),t(),0===this._preloadCount&&(this._setup(),this._runFrames(),this._draw())):(this._setup(),this._runFrames(),this._draw())}.bind(this),this._preload=function(t,e){var r=this._isGlobal?window:this;return r._setProperty("_preloadCount",r._preloadCount+1),o.prototype[t].call(r,e,function(){r._setProperty("_preloadCount",r._preloadCount-1),0===r._preloadCount&&(r._setup(),r._runFrames(),r._draw())})}.bind(this),this._setup=function(){var t=this._isGlobal?window:this;"function"==typeof t.preload&&this._preloadMethods.forEach(function(e){t[e]=o.prototype[e]}),"function"==typeof t.setup&&t.setup();for(var e=new RegExp(/(^|\s)p5_hidden(?!\S)/g),r=document.getElementsByClassName("p5_hidden"),n=0;n=3?(n=arguments[0],i=arguments[1],s=arguments[2],a="number"==typeof arguments[3]?arguments[3]:e[3]):(t?n=i=s=arguments[0]:(n=s=arguments[0],i=0),a="number"==typeof arguments[1]?arguments[1]:e[3]),n*=255/e[0],i*=255/e[1],s*=255/e[2],a*=255/e[3],[n,i,s,a]},o.Color.getRGB=function(t){var e=t[0],r=t[1],o=t[2];e/=255,r/=255,o/=255;var n=[];if(0===r)n=[Math.round(255*o),Math.round(255*o),Math.round(255*o),t[3]];else{var i=6*e;6===i&&(i=0);var s,a,u,p=Math.floor(i),h=o*(1-r),l=o*(1-r*(i-p)),c=o*(1-r*(1-(i-p)));0===p?(s=o,a=c,u=h):1===p?(s=l,a=o,u=h):2===p?(s=h,a=o,u=c):3===p?(s=h,a=l,u=o):4===p?(s=c,a=h,u=o):(s=o,a=h,u=l),n=[Math.round(255*s),Math.round(255*a),Math.round(255*u),t[3]]}return n},o.Color.getHSB=function(t){var e,r,o=t[0]/255,n=t[1]/255,i=t[2]/255,s=Math.min(o,n,i),a=Math.max(o,n,i),u=a-s,p=a;if(0===u)e=0,r=0;else{r=u/a;var h=((a-o)/6+u/2)/u,l=((a-n)/6+u/2)/u,c=((a-i)/6+u/2)/u;o===a?e=c-l:n===a?e=1/3+h-c:i===a&&(e=2/3+l-h),0>e&&(e+=1),e>1&&(e-=1)}return[Math.round(255*e),Math.round(255*r),Math.round(255*p),t[3]]},o.Color.getColorString=function(t){for(var e=0;3>e;e++)t[e]=Math.floor(t[e]);var r="undefined"!=typeof t[3]?t[3]/255:1;return"rgba("+t[0]+","+t[1]+","+t[2]+","+r+")"},o.Color.getColor=function(){if(arguments[0]instanceof o.Color)return arguments[0].colorString;if(arguments[0]instanceof Array)return o.Color.getColorString(arguments[0]);var t=o.Color.getNormalizedColor.apply(this,arguments);return this._colorMode===r.HSB&&(t=o.Color.getRGB(t)),o.Color.getColorString(t)},o.Color}({},core,constants),p5Element=function(t,e){function r(t,e,r){var o=r,n=function(t){e(t,o)};r.elt.addEventListener(t,n,!1),r._events[t]=n}var o=e;return o.Element=function(t,e){this.elt=t,this._pInst=e,this._events={},this.width=this.elt.offsetWidth,this.height=this.elt.offsetHeight},o.Element.prototype.parent=function(t){"string"==typeof t&&(t=document.getElementById(t)),t.appendChild(this.elt)},o.Element.prototype.id=function(t){this.elt.id=t},o.Element.prototype.class=function(t){this.elt.className+=" "+t},o.Element.prototype.mousePressed=function(t){r("mousedown",t,this)},o.Element.prototype.mouseReleased=function(t){r("mouseup",t,this)},o.Element.prototype.mouseClicked=function(t){r("click",t,this)},o.Element.prototype.mouseMoved=function(t){r("mousemove",t,this)},o.Element.prototype.mouseOver=function(t){r("mouseover",t,this)},o.Element.prototype.mouseOut=function(t){r("mouseout",t,this)},o.Element.prototype._setProperty=function(t,e){this[t]=e},o.Element}({},core),p5Graphics=function(t,e,r){var o=e,r=r;return o.Graphics=function(t,e){o.Element.call(this,t,e),this.canvas=t,this.drawingContext=this.canvas.getContext("2d"),this._pInst?(this._pInst._setProperty("_curElement",this),this._pInst._setProperty("canvas",this.canvas),this._pInst._setProperty("drawingContext",this.drawingContext),this._pInst._setProperty("width",this.width),this._pInst._setProperty("height",this.height)):this.canvas.style.display="none",this.drawingContext.fillStyle="#FFFFFF",this.drawingContext.strokeStyle="#000000",this.drawingContext.lineCap=r.ROUND},o.Graphics.prototype=Object.create(o.Element.prototype),o.Graphics}({},core,constants),filters=function(){"use strict";function t(t){var e=3.5*t|0;if(e=1>e?1:248>e?e:248,o!==e){o=e,n=1+o<<1,i=new Int32Array(n),s=new Array(n);for(var r=0;n>r;r++)s[r]=new Int32Array(256);for(var a,u,p,h,l=1,c=e-1;e>l;l++){i[e+l]=i[c]=u=c*c,p=s[e+l],h=s[c--];for(var d=0;256>d;d++)p[d]=h[d]=u*d}a=i[e]=e*e,p=s[e];for(var f=0;256>f;f++)p[f]=a*f}}function e(e,a){for(var u=r._toPixels(e),p=e.width,h=e.height,l=p*h,c=new Int32Array(l),d=0;l>d;d++)c[d]=r._getARGB(u,d);var f,g,y,m,w,v,_,x,b,C=new Int32Array(l),R=new Int32Array(l),E=new Int32Array(l),S=0;t(a);var M,T,I,A;for(T=0;h>T;T++){for(M=0;p>M;M++){if(m=y=g=f=0,w=M-o,0>w)b=-w,w=0;else{if(w>=p)break;b=0}for(I=b;n>I&&!(w>=p);I++){var P=c[w+S];A=s[I],g+=A[(16711680&P)>>16],y+=A[(65280&P)>>8],m+=A[255&P],f+=i[I],w++}v=S+M,C[v]=g/f,R[v]=y/f,E[v]=m/f}S+=p}for(S=0,_=-o,x=_*p,T=0;h>T;T++){for(M=0;p>M;M++){if(m=y=g=f=0,0>_)b=v=-_,w=M;else{if(_>=h)break;b=0,v=_,w=M+x}for(I=b;n>I&&!(v>=h);I++)A=s[I],g+=A[C[w]],y+=A[R[w]],m+=A[E[w]],f+=i[I],v++,w+=p;c[M+S]=4278190080|g/f<<16|y/f<<8|m/f}S+=p,x+=p,_++}r._setPixels(u,c)}var r={};r._toPixels=function(t){return t instanceof ImageData?t.data:t.getContext("2d").getImageData(0,0,t.width,t.height).data},r._getARGB=function(t,e){var r=4*e;return t[r+3]<<24&4278190080|t[r]<<16&16711680|t[r+1]<<8&65280|255&t[r+2]},r._setPixels=function(t,e){for(var r=0,o=0,n=t.length;n>o;o++)r=4*o,t[r+0]=(16711680&e[o])>>>16,t[r+1]=(65280&e[o])>>>8,t[r+2]=255&e[o],t[r+3]=(4278190080&e[o])>>>24},r._toImageData=function(t){return t instanceof ImageData?t:t.getContext("2d").getImageData(0,0,t.width,t.height)},r._createImageData=function(t,e){return r._tmpCanvas=document.createElement("canvas"),r._tmpCtx=r._tmpCanvas.getContext("2d"),this._tmpCtx.createImageData(t,e)},r.apply=function(t,e,r){var o=t.getContext("2d"),n=o.getImageData(0,0,t.width,t.height),i=e(n,r);i instanceof ImageData?o.putImageData(i,0,0,0,0,t.width,t.height):o.putImageData(n,0,0,0,0,t.width,t.height)},r.threshold=function(t,e){var o=r._toPixels(t);void 0===e&&(e=.5);for(var n=Math.floor(255*e),i=0;i=n?255:0,o[i]=o[i+1]=o[i+2]=s}},r.gray=function(t){for(var e=r._toPixels(t),o=0;oe||e>255)throw new Error("Level must be greater than 2 and less than 255 for posterize");for(var n=e-1,i=0;i>8)/n,o[i+1]=255*(a*e>>8)/n,o[i+2]=255*(u*e>>8)/n}},r.dilate=function(t){for(var e,o,n,i,s,a,u,p,h,l,c,d,f,g,y,m,w,v=r._toPixels(t),_=0,x=v.length?v.length/4:0,b=new Int32Array(x);x>_;)for(e=_,o=_+t.width;o>_;)n=i=r._getARGB(v,_),u=_-1,a=_+1,p=_-t.width,h=_+t.width,e>u&&(u=_),a>=o&&(a=_),0>p&&(p=0),h>=x&&(h=_),d=r._getARGB(v,p),c=r._getARGB(v,u),f=r._getARGB(v,h),l=r._getARGB(v,a),s=77*(n>>16&255)+151*(n>>8&255)+28*(255&n),y=77*(c>>16&255)+151*(c>>8&255)+28*(255&c),g=77*(l>>16&255)+151*(l>>8&255)+28*(255&l),m=77*(d>>16&255)+151*(d>>8&255)+28*(255&d),w=77*(f>>16&255)+151*(f>>8&255)+28*(255&f),y>s&&(i=c,s=y),g>s&&(i=l,s=g),m>s&&(i=d,s=m),w>s&&(i=f,s=w),b[_++]=i;r._setPixels(v,b)},r.erode=function(t){for(var e,o,n,i,s,a,u,p,h,l,c,d,f,g,y,m,w,v=r._toPixels(t),_=0,x=v.length?v.length/4:0,b=new Int32Array(x);x>_;)for(e=_,o=_+t.width;o>_;)n=i=r._getARGB(v,_),u=_-1,a=_+1,p=_-t.width,h=_+t.width,e>u&&(u=_),a>=o&&(a=_),0>p&&(p=0),h>=x&&(h=_),d=r._getARGB(v,p),c=r._getARGB(v,u),f=r._getARGB(v,h),l=r._getARGB(v,a),s=77*(n>>16&255)+151*(n>>8&255)+28*(255&n),y=77*(c>>16&255)+151*(c>>8&255)+28*(255&c),g=77*(l>>16&255)+151*(l>>8&255)+28*(255&l),m=77*(d>>16&255)+151*(d>>8&255)+28*(255&d),w=77*(f>>16&255)+151*(f>>8&255)+28*(255&f),s>y&&(i=c,s=y),s>g&&(i=l,s=g),s>m&&(i=d,s=m),s>w&&(i=f,s=w),b[_++]=i;r._setPixels(v,b)};var o,n,i,s;return r.blur=function(t,r){e(t,r)},r}({}),p5Image=function(t,e,r){"use strict";var o=e,n=r;return o.Image=function(t,e){this.width=t,this.height=e,this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.drawingContext=this.canvas.getContext("2d"),this.pixels=[]},o.Image.prototype._setProperty=function(t,e){this[t]=e},o.Image.prototype.loadPixels=function(){o.prototype.loadPixels.call(this)},o.Image.prototype.updatePixels=function(t,e,r,n){o.prototype.updatePixels.call(this,t,e,r,n)},o.Image.prototype.get=function(t,e,r,n){return o.prototype.get.call(this,t,e,r,n)},o.Image.prototype.set=function(t,e,r){o.prototype.set.call(this,t,e,r)},o.Image.prototype.resize=function(t,e){var r=document.createElement("canvas");r.width=t,r.height=e,r.getContext("2d").drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,r.width,r.width),this.canvas.width=this.width=t,this.canvas.height=this.height=e,this.drawingContext.drawImage(r,0,0,t,e,0,0,t,e),this.pixels.length>0&&this.loadPixels()},o.Image.prototype.copy=function(){o.prototype.copy.apply(this,arguments)},o.Image.prototype.mask=function(t){void 0===t&&(t=this);var e=this.drawingContext.globalCompositeOperation,r=[t,0,0,t.width,t.height,0,0,this.width,this.height];this.drawingContext.globalCompositeOperation="destination-out",this.copy.apply(this,r),this.drawingContext.globalCompositeOperation=e},o.Image.prototype.filter=function(t,e){n.apply(this.canvas,n[t.toLowerCase()],e)},o.Image.prototype.blend=function(){o.prototype.blend.apply(this,arguments)},o.Image.prototype.save=function(t){var e;switch(t.toLowerCase()){case"png":e="image/png";break;case"jpeg":e="image/jpeg";break;case"jpg":e="image/jpeg";break;default:e="image/png"}if(void 0!==e){var r="image/octet-stream",o=this.canvas.toDataURL(e);o=o.replace(e,r),window.location.href=o}},o.Image}({},core,filters),polargeometry=function(){return{degreesToRadians:function(t){return 2*Math.PI*t/360},radiansToDegrees:function(t){return 360*t/(2*Math.PI)}}}({}),p5Vector=function(t,e,r,o){"use strict";var n=e,i=r,o=o;return n.Vector=function(){var t,e,r;arguments[0]instanceof n?(this.p5=arguments[0],t=arguments[1][0]||0,e=arguments[1][1]||0,r=arguments[1][2]||0):(t=arguments[0]||0,e=arguments[1]||0,r=arguments[2]||0),this.x=t,this.y=e,this.z=r},n.Vector.prototype.set=function(t,e,r){return t instanceof n.Vector?(this.x=t.x||0,this.y=t.y||0,this.z=t.z||0,this):t instanceof Array?(this.x=t[0]||0,this.y=t[1]||0,this.z=t[2]||0,this):(this.x=t||0,this.y=e||0,this.z=r||0,this)},n.Vector.prototype.get=function(){return this.p5?new n.Vector(this.p5,[this.x,this.y,this.z]):new n.Vector(this.x,this.y,this.z)},n.Vector.prototype.add=function(t,e,r){return t instanceof n.Vector?(this.x+=t.x||0,this.y+=t.y||0,this.z+=t.z||0,this):t instanceof Array?(this.x+=t[0]||0,this.y+=t[1]||0,this.z+=t[2]||0,this):(this.x+=t||0,this.y+=e||0,this.z+=r||0,this)},n.Vector.prototype.sub=function(t,e,r){return t instanceof n.Vector?(this.x-=t.x||0,this.y-=t.y||0,this.z-=t.z||0,this):t instanceof Array?(this.x-=t[0]||0,this.y-=t[1]||0,this.z-=t[2]||0,this):(this.x-=t||0,this.y-=e||0,this.z-=r||0,this)},n.Vector.prototype.mult=function(t){return this.x*=t||0,this.y*=t||0,this.z*=t||0,this},n.Vector.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},n.Vector.prototype.mag=function(){return Math.sqrt(this.magSq())},n.Vector.prototype.magSq=function(){var t=this.x,e=this.y,r=this.z;return t*t+e*e+r*r},n.Vector.prototype.dot=function(t,e,r){return t instanceof n.Vector?this.dot(t.x,t.y,t.z):this.x*(t||0)+this.y*(e||0)+this.z*(r||0)},n.Vector.prototype.cross=function(t){var e=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,o=this.x*t.y-this.y*t.x;return this.p5?new n.Vector(this.p5,[e,r,o]):new n.Vector(e,r,o)},n.Vector.prototype.dist=function(t){var e=t.get().sub(this);return e.mag()},n.Vector.prototype.normalize=function(){return this.div(this.mag())},n.Vector.prototype.limit=function(t){var e=this.magSq();return e>t*t&&(this.div(Math.sqrt(e)),this.mult(t)),this},n.Vector.prototype.setMag=function(t){return this.normalize().mult(t)},n.Vector.prototype.heading=function(){var t=Math.atan2(this.y,this.x);return this.p5?this.p5._angleMode===o.RADIANS?t:i.radiansToDegrees(t):t},n.Vector.prototype.rotate=function(t){this.p5&&this.p5._angleMode===o.DEGREES&&(t=i.degreesToRadians(t));var e=this.heading()+t,r=this.mag();return this.x=Math.cos(e)*r,this.y=Math.sin(e)*r,this},n.Vector.prototype.lerp=function(t,e,r,o){return t instanceof n.Vector?this.lerp(t.x,t.y,t.z,e):(this.x+=(t-this.x)*o||0,this.y+=(e-this.y)*o||0,this.z+=(r-this.z)*o||0,this)},n.Vector.prototype.array=function(){return[this.x||0,this.y||0,this.z||0]},n.Vector.fromAngle=function(t){return this.p5&&this.p5._angleMode===o.DEGREES&&(t=i.degreesToRadians(t)),this.p5?new n.Vector(this.p5,[Math.cos(t),Math.sin(t),0]):new n.Vector(Math.cos(t),Math.sin(t),0)},n.Vector.random2D=function(){var t;return t=this.p5?this.p5.random(this.p5._angleMode===o.DEGREES?360:o.TWO_PI):Math.random()*Math.PI*2,this.fromAngle(t)},n.Vector.random3D=function(){var t,e;this.p5?(t=this.p5.random(0,o.TWO_PI),e=this.p5.random(-1,1)):(t=Math.random()*Math.PI*2,e=2*Math.random()-1);var r=Math.sqrt(1-e*e)*Math.cos(t),i=Math.sqrt(1-e*e)*Math.sin(t);return this.p5?new n.Vector(this.p5,[r,i,e]):new n.Vector(r,i,e)},n.Vector.add=function(t,e){return t.get().add(e)},n.Vector.sub=function(t,e){return t.get().sub(e)},n.Vector.mult=function(t,e){return t.get().mult(e)},n.Vector.div=function(t,e){return t.get().div(e)},n.Vector.dot=function(t,e){return t.dot(e)},n.Vector.cross=function(t,e){return t.cross(e)},n.Vector.dist=function(t,e){return t.dist(e)},n.Vector.lerp=function(t,e,r){return t.get().lerp(e,r)},n.Vector.angleBetween=function(t,e){var r=Math.acos(t.dot(e)/(t.mag()*e.mag()));return this.p5&&this.p5._angleMode===o.DEGREES&&(r=i.radiansToDegrees(r)),r},n.Vector}({},core,polargeometry,constants),p5TableRow=function(t,e){"use strict";var r=e;return r.TableRow=function(t,e){var r=[],o={};t&&(e=e||",",r=t.split(e));for(var n=0;n=0))throw'This table has no column named "'+t+'"';this.obj[t]=e,this.arr[r]=e}else{if(!(ta;a++)s.push(r.prototype.lerp(t.rgba[a],e.rgba[a],o));return new r.Color(this,s)}return r.prototype.lerp(t,e,o)},r.prototype.red=function(t){if(t instanceof Array)return t[0];if(t instanceof r.Color)return t.rgba[0];throw new Error("Needs p5.Color or pixel array as argument.")},r.prototype.saturation=function(t){if(!t instanceof r.Color)throw new Error("Needs p5.Color as argument.");return t.hsba||(t.hsba=r.Color.getRGB(t.rgba),t.hsba=t.hsba.concat(t.rgba[3])),t.hsba[1]},r}({},core,p5Color),colorsetting=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._doStroke=!0,o.prototype._doFill=!0,o.prototype._colorMode=r.RGB,o.prototype._maxRGB=[255,255,255,255],o.prototype._maxHSB=[255,255,255,255],o.prototype.background=function(){if(arguments[0]instanceof o.Image)this.image(arguments[0],0,0,this.width,this.height);else{var t=this.drawingContext.fillStyle,e=this.drawingContext;e.fillStyle=o.Color.getColor.apply(this,arguments),e.fillRect(0,0,this.width,this.height),e.fillStyle=t}},o.prototype.clear=function(){this.drawingContext.clearRect(0,0,this.width,this.height)},o.prototype.colorMode=function(){if(arguments[0]===r.RGB||arguments[0]===r.HSB){this._colorMode=arguments[0];var t=this._colorMode===r.RGB,e=t?this._maxRGB:this._maxHSB;2===arguments.length?(e[0]=arguments[1],e[1]=arguments[1],e[2]=arguments[1]):arguments.length>2&&(e[0]=arguments[1],e[1]=arguments[2],e[2]=arguments[3]),5===arguments.length&&(e[3]=arguments[4])}},o.prototype.fill=function(){this._setProperty("_doFill",!0);var t=this.drawingContext;t.fillStyle=o.Color.getColor.apply(this,arguments)},o.prototype.noFill=function(){this._setProperty("_doFill",!1)},o.prototype.noStroke=function(){this._setProperty("_doStroke",!1)},o.prototype.stroke=function(){this._setProperty("_doStroke",!0);var t=this.drawingContext;t.strokeStyle=o.Color.getColor.apply(this,arguments)},o}({},core,constants,p5Color),dataarray_functions=function(t,e){"use strict";var r=e;return r.prototype.append=function(t,e){return t.push(e),t},r.prototype.arrayCopy=function(t,e,r,o,n){var i,s;"undefined"!=typeof n?(s=Math.min(n,t.length),i=o,t=t.slice(e,s+e)):("undefined"!=typeof r?(s=r,s=Math.min(s,t.length)):s=t.length,i=0,r=e,t=t.slice(0,s)),Array.prototype.splice.apply(r,[i,s].concat(t))},r.prototype.concat=function(t,e){return t.concat(e)},r.prototype.reverse=function(t){return t.reverse()},r.prototype.shorten=function(t){return t.pop(),t},r.prototype.sort=function(t,e){var r=e?t.slice(0,Math.min(e,t.length)):t,o=e?t.slice(Math.min(e,t.length)):[];return r="string"==typeof r[0]?r.sort():r.sort(function(t,e){return t-e}),r.concat(o)},r.prototype.splice=function(t,e,r){return Array.prototype.splice.apply(t,[r,0].concat(e)),t},r.prototype.subset=function(t,e,r){return"undefined"!=typeof r?t.slice(e,e+r):t.slice(e,t.length)},r}({},core),datastring_functions=function(t,e){"use strict";function r(){var t=arguments[0],e=0>t,r=e?t.toString().substring(1):t.toString(),o=r.indexOf("."),n=-1!==o?r.substring(0,o):r,i=-1!==o?r.substring(o+1):"",s=e?"-":"";if(3===arguments.length){for(var a=0;a1&&(r=r.substring(0,arguments[1]+1)),o+r}function n(){return parseFloat(arguments[0])>0?"+"+arguments[0].toString():arguments[0].toString()}function i(){return parseFloat(arguments[0])>0?" "+arguments[0].toString():arguments[0].toString()}var s=e;return s.prototype.join=function(t,e){return t.join(e)},s.prototype.match=function(t,e){return t.match(e)},s.prototype.matchAll=function(t,e){for(var r=new RegExp(e,"g"),o=r.exec(t),n=[];null!==o;)n.push(o),o=r.exec(t);return n},s.prototype.nf=function(){if(arguments[0]instanceof Array){var t=arguments[1],e=arguments[2];return arguments[0].map(function(o){return r(o,t,e)})}return r.apply(this,arguments)},s.prototype.nfc=function(){if(arguments[0]instanceof Array){var t=arguments[1];return arguments[0].map(function(e){return o(e,t)})}return o.apply(this,arguments)},s.prototype.nfp=function(){var t=this.nf(arguments);return t instanceof Array?t.map(n):n(t)},s.prototype.nfs=function(){var t=this.nf(arguments);return t instanceof Array?t.map(i):i(t)},s.prototype.split=function(t,e){return t.split(e)},s.prototype.splitTokens=function(){var t=arguments.length>0?arguments[1]:/\s/g;return arguments[0].split(t).filter(function(t){return t})},s.prototype.trim=function(t){return t instanceof Array?t.map(this.trim):t.trim()},s}({},core),environment=function(t,e,r){"use strict";function o(t){var e=document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled;if(!e)throw new Error("Fullscreen not enabled in this browser.");t.requestFullscreen?t.requestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen?t.webkitRequestFullscreen():t.msRequestFullscreen&&t.msRequestFullscreen()}function n(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}var i=e,s=r,a=[s.ARROW,s.CROSS,s.HAND,s.MOVE,s.TEXT,s.WAIT];return i.prototype._frameRate=0,i.prototype._lastFrameTime=0,i.prototype._targetFrameRate=60,i.prototype.frameCount=0,i.prototype.focused=!0,i.prototype.cursor=function(t,e,r){var o="auto",n=this._curElement.elt;if(a.indexOf(t)>-1)o=t;else if("string"==typeof t){var i="";e&&r&&"number"==typeof e&&"number"==typeof r&&(i=e+" "+r),o="http://"!==t.substring(0,6)?"url("+t+") "+i+", auto":/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(t)?"url("+t+") "+i+", auto":t}n.style.cursor=o},i.prototype.frameRate=function(t){return"undefined"==typeof t?this._frameRate:(this._setProperty("_targetFrameRate",t),this._runFrames(),this)},i.prototype.getFrameRate=function(){return this.frameRate()},i.prototype.setFrameRate=function(t){return this.frameRate(t)},i.prototype.noCursor=function(){this._curElement.elt.style.cursor="none"},i.prototype.displayWidth=screen.width,i.prototype.displayHeight=screen.height,i.prototype.windowWidth=window.innerWidth,i.prototype.windowHeight=window.innerHeight,window.addEventListener("resize",function(){this.windowWidth=window.innerWidth,this.windowHeight=window.innerHeight -}),i.prototype.width=0,i.prototype.height=0,i.prototype.fullscreen=function(t){return"undefined"==typeof t?document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement:void(t?o(document.documentElement):n())},i}({},core,constants),imageimage=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._imageMode=r.CORNER,o.prototype._tint=null,o.prototype.createImage=function(t,e){return new o.Image(t,e)},o}({},core,constants),canvas=function(t,e){var e=e;return{modeAdjust:function(t,r,o,n,i){return i===e.CORNER?{x:t,y:r,w:o,h:n}:i===e.CORNERS?{x:t,y:r,w:o-t,h:n-r}:i===e.RADIUS?{x:t-o,y:r-n,w:2*o,h:2*n}:i===e.CENTER?{x:t-.5*o,y:r-.5*n,w:o,h:n}:void 0},arcModeAdjust:function(t,r,o,n,i){return i===e.CORNER?{x:t+.5*o,y:r+.5*n,w:o,h:n}:i===e.CORNERS?{x:t,y:r,w:o+t,h:n+r}:i===e.RADIUS?{x:t,y:r,w:2*o,h:2*n}:i===e.CENTER?{x:t,y:r,w:o,h:n}:void 0}}}({},constants),imageloading_displaying=function(t,e,r,o,n){"use strict";var i=e,s=r,o=o,n=n;return i.prototype.loadImage=function(t,e){var r=new Image,o=new i.Image(1,1,this);return r.onload=function(){o.width=o.canvas.width=r.width,o.height=o.canvas.height=r.height,o.canvas.getContext("2d").drawImage(r,0,0),"undefined"!=typeof e&&e(o)},r.crossOrigin="Anonymous",r.src=t,o},i.prototype.image=function(t,e,r,n,i){var s=t.canvas?t.canvas:t.elt;void 0===n&&(n=t.width),void 0===i&&(i=t.height);var a=o.modeAdjust(e,r,n,i,this._imageMode);this._tint?this.drawingContext.drawImage(this._getTintedImageCanvas(t),a.x,a.y,a.w,a.h):this.drawingContext.drawImage(s,a.x,a.y,a.w,a.h)},i.prototype.tint=function(){var t=i.Color.getNormalizedColor.apply(this,arguments);this._tint=t},i.prototype.noTint=function(){this._tint=null},i.prototype._getTintedImageCanvas=function(t){if(!t.canvas)return t;var e=s._toPixels(t.canvas),r=document.createElement("canvas");r.width=t.canvas.width,r.height=t.canvas.height;for(var o=r.getContext("2d"),n=o.createImageData(t.canvas.width,t.canvas.height),i=n.data,a=0;athis.width||e>this.height||0>t||0>e)return[0,0,0,255];var i=this.drawingContext.getImageData(t,e,r,n),s=i.data;if(1===r&&1===n){for(var a=[],u=0;u0;)self._completeHandlers.shift()(t)}function success(resp){resp="jsonp"!==type?self.request:resp;var filteredResponse=globalSetupOptions.dataFilter(resp.responseText,type),r=filteredResponse;try{resp.responseText=r}catch(e){}if(r)switch(type){case"json":try{resp=win.JSON?win.JSON.parse(r):eval("("+r+")")}catch(err){return error(resp,"Could not parse JSON in response",err)}break;case"js":resp=eval(r);break;case"html":resp=r;break;case"xml":resp=resp.responseXML&&resp.responseXML.parseError&&resp.responseXML.parseError.errorCode&&resp.responseXML.parseError.reason?null:resp.responseXML}for(self._responseArgs.resp=resp,self._fulfilled=!0,fn(resp),self._successHandler(resp);self._fulfillmentHandlers.length>0;)resp=self._fulfillmentHandlers.shift()(resp);complete(resp)}function error(t,e,r){for(t=self.request,self._responseArgs.resp=t,self._responseArgs.msg=e,self._responseArgs.t=r,self._erred=!0;self._errorHandlers.length>0;)self._errorHandlers.shift()(t,e,r);complete(t)}this.url="string"==typeof o?o:o.url,this.timeout=null,this._fulfilled=!1,this._successHandler=function(){},this._fulfillmentHandlers=[],this._errorHandlers=[],this._completeHandlers=[],this._erred=!1,this._responseArgs={};var self=this,type=o.type||setType(this.url);fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort()},o.timeout)),o.success&&(this._successHandler=function(){o.success.apply(o,arguments)}),o.error&&this._errorHandlers.push(function(){o.error.apply(o,arguments)}),o.complete&&this._completeHandlers.push(function(){o.complete.apply(o,arguments)}),this.request=getRequest.call(this,success,error)}function reqwest(t,e){return new Reqwest(t,e)}function normalize(t){return t?t.replace(/\r?\n/g,"\r\n"):""}function serial(t,e){var r,o,n,i,s=t.name,a=t.tagName.toLowerCase(),u=function(t){t&&!t.disabled&&e(s,normalize(t.attributes.value&&t.attributes.value.specified?t.value:t.text))};if(!t.disabled&&s)switch(a){case"input":/reset|button|image|file/i.test(t.type)||(r=/checkbox/i.test(t.type),o=/radio/i.test(t.type),n=t.value,(!(r||o)||t.checked)&&e(s,normalize(r&&""===n?"on":n)));break;case"textarea":e(s,normalize(t.value));break;case"select":if("select-one"===t.type.toLowerCase())u(t.selectedIndex>=0?t.options[t.selectedIndex]:null);else for(i=0;t.length&&ie){var i=t;t=e,e=i}return r*(e-t)+t};var i,s=!1;return r.prototype.randomGaussian=function(t,e){var r,o,n,a;if(s)r=i,s=!1;else{do o=this.random(2)-1,n=this.random(2)-1,a=o*o+n*n;while(a>=1);a=Math.sqrt(-2*Math.log(a)/a),r=o*a,i=n*a,s=!0}var u=t||0,p=e||1;return r*p+u},r}({},core),mathnoise=function(t,e){"use strict";for(var r=e,o=4,n=1<g;g++)c[g]=Math.sin(g*f*h),d[g]=Math.cos(g*f*h);var y=l;y>>=1;var m;return r.prototype.noise=function(t,e,r){if(e=e||0,r=r||0,null==m){m=new Array(a+1);for(var h=0;a+1>h;h++)m[h]=Math.random()}0>t&&(t=-t),0>e&&(e=-e),0>r&&(r=-r);for(var c,f,g,w,v,_=Math.floor(t),x=Math.floor(e),b=Math.floor(r),C=t-_,R=e-x,E=r-b,S=0,M=.5,T=function(t){return.5*(1-d[Math.floor(t*y)%l])},I=0;u>I;I++){var A=_+(x<=1&&(_++,C--),R>=1&&(x++,R--),E>=1&&(b++,E--)}return S},r.prototype.noiseDetail=function(t,e){t>0&&(u=t),e>0&&(p=e)},r.prototype.noiseSeed=function(t){var e=function(){var t,e,r=4294967296,o=1664525,n=1013904223;return{setSeed:function(o){e=t=o||Math.round(Math.random()*r)},getSeed:function(){return t},rand:function(){return e=(o*e+n)%r,e/r}}}();e.setSeed(t),m=new Array(a+1);for(var r=0;a+1>r;r++)m[r]=e.rand()},r}({},core),mathtrigonometry=function(t,e,r,o){"use strict";var n=e,i=r,o=o;return n.prototype._angleMode=o.RADIANS,n.prototype.acos=function(t){return this._angleMode===o.RADIANS?Math.acos(t):i.radiansToDegrees(Math.acos(t))},n.prototype.asin=function(t){return this._angleMode===o.RADIANS?Math.asin(t):i.radiansToDegrees(Math.asin(t))},n.prototype.atan=function(t){return this._angleMode===o.RADIANS?Math.atan(t):i.radiansToDegrees(Math.atan(t))},n.prototype.atan2=function(t,e){return this._angleMode===o.RADIANS?Math.atan2(t,e):i.radiansToDegrees(Math.atan2(t,e))},n.prototype.cos=function(t){return Math.cos(this._angleMode===o.RADIANS?t:this.radians(t))},n.prototype.sin=function(t){return Math.sin(this._angleMode===o.RADIANS?t:this.radians(t))},n.prototype.tan=function(t){return Math.tan(this._angleMode===o.RADIANS?t:this.radians(t))},n.prototype.degrees=function(t){return i.radiansToDegrees(t)},n.prototype.radians=function(t){return i.degreesToRadians(t)},n.prototype.angleMode=function(t){(t===o.DEGREES||t===o.RADIANS)&&(this._angleMode=t)},n}({},core,polargeometry,constants),outputfiles=function(t,e){"use strict";function r(t){return t.split(".").pop()}function o(){var t=Object.prototype.toString.call(window.HTMLElement);return t.indexOf("Constructor")>0}function n(t){document.body.removeChild(t.target)}var i=e;return window.URL=window.URL||window.webkitURL,i.prototype._pWriters=[],i.prototype.beginRaw=function(){throw"not yet implemented"},i.prototype.beginRecord=function(){throw"not yet implemented"},i.prototype.createOutput=function(){throw"not yet implemented"},i.prototype.createWriter=function(t,e){var r;for(var o in i.prototype._pWriters)if(i.prototype._pWriters[o].name===t)return r=new i.PrintWriter(t+window.millis(),e),i.prototype._pWriters.push(r),r;return r=new i.PrintWriter(t,e),i.prototype._pWriters.push(r),r},i.prototype.endRaw=function(){throw"not yet implemented"},i.prototype.endRecord=function(){throw"not yet implemented"},i.prototype.escape=function(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")},i.PrintWriter=function(t,e){var r=this;this.name=t,this.content="",this.print=function(t){this.content+=t},this.println=function(t){this.content+=t+"\n"},this.flush=function(){this.content=""},this.close=function(){var o=[];o.push(this.content),i.prototype.writeFile(o,t,e);for(var n in i.prototype._pWriters)i.prototype._pWriters[n].name===this.name&&i.prototype._pWriters.splice(n,1);r.flush(),r={}}},i.prototype.saveBytes=function(){throw"not yet implemented"},i.prototype.saveJSON=function(t,e,r){var o;o=r?JSON.stringify(t):JSON.stringify(t,void 0,2),this.saveStrings(o.split("\n"),e,"json")},i.prototype.saveJSONObject=i.prototype.saveJSON,i.prototype.saveJSONArray=i.prototype.saveJSON,i.prototype.saveStream=function(){throw"not yet implemented"},i.prototype.saveStrings=function(t,e,r){var o=r||"txt",n=this.createWriter(e,o);for(var i in t)i"),o.println("");var h=' "),o.println(""),o.println(" "),"0"!==n[0]){o.println(" ");for(var l=0;l"+c),o.println(" ")}o.println(" ")}for(var d=0;d");for(var f=0;f"+y),o.println(" ")}o.println(" ")}o.println("
"),o.println(""),o.print("")}o.close(),o.flush()},i.prototype.writeFile=function(t,e,i){var s="",a=document.createElement("a"),u="application/octet-stream";o()&&(u="text/plain"),e?s=r(e):e="untitled",i&&s!==i&&(s=i,e=e+"."+s);var p=new Blob(t,{type:u});if(a.href=window.URL.createObjectURL(p),a.download=e,a.onclick=n,a.style.display="none",document.body.appendChild(a),o()){var h="Hello, Safari user! To download this file...\n";h+="1. Go to File --> Save As.\n",h+='2. Choose "Page Source" as the Format.\n',h+='3. Name it with this extension: ."'+s+'"',alert(h)}a.click(),p=null},i}({},core),outputimage=function(t,e){"use strict";var r=e;return r.prototype.save=function(){window.open(this._curElement.elt.toDataURL("image/png"))},r}({},core),outputtext_area=function(t,e){"use strict";var r=e;return r.prototype.print=window.console&&console.log?console.log.bind(console):function(){},r.prototype.println=r.prototype.print,r}({},core),renderingrendering=function(t,e,r){var o=e,r=r;return o.prototype.createCanvas=function(t,e,r){var n;if(r)n=document.createElement("canvas"),n.id="defaultCanvas";else if(n=document.getElementById("defaultCanvas"))n.id="";else{var i="Warning: createCanvas more than once NOT recommended.";i+=" Very unpredictable behavior may result.",console.log(i)}n.setAttribute("width",t*this._pixelDensity),n.setAttribute("height",e*this._pixelDensity),n.setAttribute("style","width:"+t+"px !important; height:"+e+"px !important;"),this._setupDone||(n.className+=" p5_hidden",n.style.visibility="hidden"),this._userNode?this._userNode.appendChild(n):document.body.appendChild(n);var s=new o.Graphics(n,this);return r&&this._elements.push(s),this.scale(this._pixelDensity,this._pixelDensity),s},o.prototype.createGraphics=function(t,e){var r=document.createElement("canvas");r.setAttribute("width",t*this._pixelDensity),r.setAttribute("height",e*this._pixelDensity),r.setAttribute("style","width:"+t+"px !important; height:"+e+"px !important;");var n=this._userNode||document.body;n.appendChild(r);var i=new o.Graphics(r);this._elements.push(i);for(var s in o.prototype)i.hasOwnProperty(s)||(i[s]="function"==typeof o.prototype[s]?o.prototype[s].bind(i):o.prototype[s]);return i.scale(this._pixelDensity,this._pixelDensity),i},o.prototype.blendMode=function(t){if(t!==r.BLEND&&t!==r.DARKEST&&t!==r.LIGHTEST&&t!==r.DIFFERENCE&&t!==r.MULTIPLY&&t!==r.EXCLUSION&&t!==r.SCREEN&&t!==r.REPLACE&&t!==r.OVERLAY&&t!==r.HARD_LIGHT&&t!==r.SOFT_LIGHT&&t!==r.DODGE&&t!==r.BURN)throw new Error("Mode "+t+" not recognized.");this.drawingContext.globalCompositeOperation=t},o}({},core,constants),shape2d_primitives=function(t,e,r,o){"use strict";var n=e,r=r,o=o;return n.prototype.arc=function(t,e,n,i,s,a,u){if(this._doStroke||this._doFill){var p=this.drawingContext,h=r.arcModeAdjust(t,e,n,i,this._ellipseMode),l=h.h>h.w?h.h/2:h.w/2,c=h.h>h.w?h.w/h.h:1,d=h.h>h.w?1:h.h/h.w;return p.scale(c,d),p.beginPath(),p.arc(h.x,h.y,l,s,a),this._doStroke&&p.stroke(),u===o.CHORD||u===o.OPEN?p.closePath():(u===o.PIE||void 0===u)&&(p.lineTo(h.x,h.y),p.closePath()),this._doFill&&p.fill(),this._doStroke&&u!==o.OPEN&&void 0!==u&&p.stroke(),this}},n.prototype.ellipse=function(t,e,o,n){if(this._doStroke||this._doFill){var i=this.drawingContext,s=r.modeAdjust(t,e,o,n,this._ellipseMode),a=.5522848,u=s.w/2*a,p=s.h/2*a,h=s.x+s.w,l=s.y+s.h,c=s.x+s.w/2,d=s.y+s.h/2;return i.beginPath(),i.moveTo(s.x,d),i.bezierCurveTo(s.x,d-p,c-u,s.y,c,s.y),i.bezierCurveTo(c+u,s.y,h,d-p,h,d),i.bezierCurveTo(h,d+p,c+u,l,c,l),i.bezierCurveTo(c-u,l,s.x,d+p,s.x,d),i.closePath(),this._doFill&&i.fill(),this._doStroke&&i.stroke(),this}},n.prototype.line=function(t,e,r,o){if(this._doStroke){var n=this.drawingContext;if("rgba(0,0,0,0)"!==n.strokeStyle)return n.beginPath(),n.moveTo(t,e),n.lineTo(r,o),n.stroke(),this}},n.prototype.point=function(t,e){if(this._doStroke){var r=this.drawingContext,n=r.strokeStyle,i=r.fillStyle;if("rgba(0,0,0,0)"!==n)return t=Math.round(t),e=Math.round(e),r.fillStyle=n,r.lineWidth>1?(r.beginPath(),r.arc(t,e,r.lineWidth/2,0,o.TWO_PI,!1),r.fill()):r.fillRect(t,e,1,1),r.fillStyle=i,this}},n.prototype.quad=function(t,e,r,o,n,i,s,a){if(this._doStroke||this._doFill){var u=this.drawingContext;return u.beginPath(),u.moveTo(t,e),u.lineTo(r,o),u.lineTo(n,i),u.lineTo(s,a),u.closePath(),this._doFill&&u.fill(),this._doStroke&&u.stroke(),this -}},n.prototype.rect=function(t,e,o,n){if(this._doStroke||this._doFill){var i=r.modeAdjust(t,e,o,n,this._rectMode),s=this.drawingContext;return this._doStroke&&s.lineWidth%2===1&&s.translate(.5,.5),s.beginPath(),s.rect(i.x,i.y,i.w,i.h),this._doFill&&s.fill(),this._doStroke&&s.stroke(),this._doStroke&&s.lineWidth%2===1&&s.translate(-.5,-.5),this}},n.prototype.triangle=function(t,e,r,o,n,i){if(this._doStroke||this._doFill){var s=this.drawingContext;return s.beginPath(),s.moveTo(t,e),s.lineTo(r,o),s.lineTo(n,i),s.closePath(),this._doFill&&s.fill(),this._doStroke&&s.stroke(),this}},n}({},core,canvas,constants),shapeattributes=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._rectMode=r.CORNER,o.prototype._ellipseMode=r.CENTER,o.prototype.ellipseMode=function(t){return(t===r.CORNER||t===r.CORNERS||t===r.RADIUS||t===r.CENTER)&&(this._ellipseMode=t),this},o.prototype.noSmooth=function(){return this.drawingContext.mozImageSmoothingEnabled=!1,this.drawingContext.webkitImageSmoothingEnabled=!1,this},o.prototype.rectMode=function(t){return(t===r.CORNER||t===r.CORNERS||t===r.RADIUS||t===r.CENTER)&&(this._rectMode=t),this},o.prototype.smooth=function(){return this.drawingContext.mozImageSmoothingEnabled=!0,this.drawingContext.webkitImageSmoothingEnabled=!0,this},o.prototype.strokeCap=function(t){return(t===r.ROUND||t===r.SQUARE||t===r.PROJECT)&&(this.drawingContext.lineCap=t),this},o.prototype.strokeJoin=function(t){return(t===r.ROUND||t===r.BEVEL||t===r.MITER)&&(this.drawingContext.lineJoin=t),this},o.prototype.strokeWeight=function(t){return this.drawingContext.lineWidth="undefined"==typeof t||0===t?1e-4:t,this},o}({},core,constants),shapecurves=function(t,e){"use strict";var r=e;return r.prototype._bezierDetail=20,r.prototype._curveDetail=20,r.prototype.bezier=function(t,e,o,n,i,s,a,u){if(this._doStroke){var p=this.drawingContext;p.beginPath(),p.moveTo(t,e);for(var h=0;h<=this._bezierDetail;h++){var l=h/parseFloat(this._bezierDetail),c=r.prototype.bezierPoint(t,o,i,a,l),d=r.prototype.bezierPoint(e,n,s,u,l);p.lineTo(c,d)}return p.stroke(),this}},r.prototype.bezierDetail=function(t){return this._setProperty("_bezierDetail",t),this},r.prototype.bezierPoint=function(t,e,r,o,n){var i=1-n;return Math.pow(i,3)*t+3*Math.pow(i,2)*n*e+3*i*Math.pow(n,2)*r+Math.pow(n,3)*o},r.prototype.bezierTangent=function(t,e,r,o,n){var i=1-n;return 3*o*Math.pow(n,2)-3*r*Math.pow(n,2)+6*r*i*n-6*e*i*n+3*e*Math.pow(i,2)-3*t*Math.pow(i,2)},r.prototype.curve=function(t,e,o,n,i,s,a,u){if(this._doStroke){var p=this.drawingContext;p.moveTo(t,e),p.beginPath();for(var h=0;h<=this._curveDetail;h++){var l=parseFloat(h/this._curveDetail),c=r.prototype.curvePoint(t,o,i,a,l),d=r.prototype.curvePoint(e,n,s,u,l);p.lineTo(c,d)}return p.stroke(),p.closePath(),this}},r.prototype.curveDetail=function(t){return this._setProperty("_curveDetail",t),this},r.prototype.curvePoint=function(t,e,r,o,n){var i=n*n*n,s=n*n,a=-.5*i+s-.5*n,u=1.5*i-2.5*s+1,p=-1.5*i+2*s+.5*n,h=.5*i-.5*s;return t*a+e*u+r*p+o*h},r.prototype.curveTangent=function(t,e,r,o,n){var i=n*n,s=-3*i/2+2*n-.5,a=9*i/2-5*n,u=-9*i/2+4*n+.5,p=3*i/2-n;return t*s+e*a+r*u+o*p},r.prototype.curveTightness=function(){throw"not yet implemented"},r}({},core),shapevertex=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._shapeKind=null,o.prototype._shapeInited=!1,o.prototype._contourInited=!1,o.prototype._contourVertices=[],o.prototype._curveVertices=[],o.prototype.beginContour=function(){return this._contourVertices=[],this._contourInited=!0,this},o.prototype.beginShape=function(t){return this._shapeKind=t===r.POINTS||t===r.LINES||t===r.TRIANGLES||t===r.TRIANGLE_FAN||t===r.TRIANGLE_STRIP||t===r.QUADS||t===r.QUAD_STRIP?t:null,this._shapeInited=!0,this.drawingContext.beginPath(),this},o.prototype.bezierVertex=function(t,e,o,n,i,s){if(this._contourInited){var a={};return a.x=t,a.y=e,a.x3=o,a.y3=n,a.x4=i,a.y4=s,a.type=r.BEZIER,this._contourVertices.push(a),this}return this.drawingContext.bezierCurveTo(t,e,o,n,i,s),this},o.prototype.curveVertex=function(t,e){var r={};return r.x=t,r.y=e,this._curveVertices.push(r),this._curveVertices.length>=4&&(this.curve(this._curveVertices[0].x,this._curveVertices[0].y,this._curveVertices[1].x,this._curveVertices[1].y,this._curveVertices[2].x,this._curveVertices[2].y,this._curveVertices[3].x,this._curveVertices[3].y),this._curveVertices.shift()),this},o.prototype.endContour=function(){this._contourVertices.reverse(),this.drawingContext.moveTo(this._contourVertices[0].x,this._contourVertices[0].y);var t=this.drawingContext;return this._contourVertices.slice(1).forEach(function(e){switch(e.type){case r.LINEAR:t.lineTo(e.x,e.y);break;case r.QUADRATIC:t.quadraticCurveTo(e.x,e.y,e.x3,e.y3);break;case r.BEZIER:t.bezierCurveTo(e.x,e.y,e.x3,e.y3,e.x4,e.y4);break;case r.CURVE:}}),this.drawingContext.closePath(),this._contourInited=!1,this},o.prototype.endShape=function(t){return t===r.CLOSE&&(this.drawingContext.closePath(),this._doFill&&this.drawingContext.fill()),this._doStroke&&this._curveVertices.length<=0?this.drawingContext.stroke():this._curveVertices=[],this},o.prototype.quadraticVertex=function(t,e,o,n){if(this._contourInited){var i={};return i.x=t,i.y=e,i.x3=o,i.y3=n,i.type=r.QUADRATIC,this._contourVertices.push(i),this}return this.drawingContext.quadraticCurveTo(t,e,o,n),this},o.prototype.vertex=function(t,e){if(this._contourInited){var o={};return o.x=t,o.y=e,o.type=r.LINEAR,this._contourVertices.push(o),this}return this._shapeInited?this.drawingContext.moveTo(t,e):this.drawingContext.lineTo(t,e),this._shapeInited=!1,this},o}({},core,constants),structure=function(t,e){"use strict";var r=e;return r.prototype.exit=function(){throw"exit() not implemented, see remove()"},r.prototype.noLoop=function(){this._loop=!1,this._drawInterval&&clearInterval(this._drawInterval)},r.prototype.loop=function(){this._loop=!0,this._draw()},r.prototype.push=function(){this.drawingContext.save(),this.styles.push({doStroke:this._doStroke,doFill:this._doFill,tint:this._tint,imageMode:this._imageMode,rectMode:this._rectMode,ellipseMode:this._ellipseMode,colorMode:this._colorMode,textFont:this.textFont,textLeading:this.textLeading,textSize:this.textSize,textStyle:this.textStyle})},r.prototype.pop=function(){this.drawingContext.restore();var t=this.styles.pop();this._doStroke=t.doStroke,this._doFill=t.doFill,this._tint=t.tint,this._imageMode=t.imageMode,this._rectMode=t.rectMode,this._ellipseMode=t.ellipseMode,this._colorMode=t.colorMode,this.textFont=t.textFont,this.textLeading=t.textLeading,this.textSize=t.textSize,this.textStyle=t.textStyle},r.prototype.pushStyle=function(){throw new Error("pushStyle() not used, see push()")},r.prototype.popStyle=function(){throw new Error("popStyle() not used, see pop()")},r.prototype.redraw=function(){var t=this._isGlobal?window:this;t.draw&&t.draw()},r.prototype.size=function(){throw"size() not implemented, see createCanvas()"},r}({},core),transform=function(t,e,r){"use strict";function o(t,e){for(var r=[],o=t.length,n=e.length,i=t[0].length,s=0;n>s;s++){r[s]=[];for(var a=0;i>a;a++){for(var u=0,p=0;o>p;p++)u+=t[p][a]*e[s][p];r[s].push(u)}}return r}var n=e,r=r;return n.prototype._matrices=[[1,0,0,1,0,0]],n.prototype.applyMatrix=function(t,e,r,n,i,s){this.drawingContext.transform(t,e,r,n,i,s);var a=this._matrices[this._matrices.length-1];return a=o(a,[t,e,r,n,i,s]),this},n.prototype.popMatrix=function(){throw new Error("popMatrix() not used, see pop()")},n.prototype.printMatrix=function(){throw new Error("printMatrix() not implemented")},n.prototype.pushMatrix=function(){throw new Error("pushMatrix() not used, see push()")},n.prototype.resetMatrix=function(){return this.drawingContext.setTransform(),this._matrices[this._matrices.length-1]=[1,0,0,1,0,0],this},n.prototype.rotate=function(t){this._angleMode===r.DEGREES&&(t=this.radians(t)),this.drawingContext.rotate(t);var e=this._matrices[this._matrices.length-1],o=Math.cos(t),n=Math.sin(t),i=e[0]*o+e[2]*n,s=e[1]*o+e[3]*n,a=e[0]*-n+e[2]*o,u=e[1]*-n+e[3]*o;return e[0]=i,e[1]=s,e[2]=a,e[3]=u,this},n.prototype.rotateX=function(){throw"not yet implemented"},n.prototype.rotateY=function(){throw"not yet implemented"},n.prototype.scale=function(){var t=1,e=1;1===arguments.length?t=e=arguments[0]:(t=arguments[0],e=arguments[1]),this.drawingContext.scale(t,e);var r=this._matrices[this._matrices.length-1];return r[0]*=t,r[1]*=t,r[2]*=e,r[3]*=e,this},n.prototype.shearX=function(t){this._angleMode===r.DEGREES&&(t=this.radians(t)),this.drawingContext.transform(1,0,this.tan(t),1,0,0);var e=this._matrices[this._matrices.length-1];return e=o(e,[1,0,this.tan(t),1,0,0]),this},n.prototype.shearY=function(t){this._angleMode===r.DEGREES&&(t=this.radians(t)),this.drawingContext.transform(1,this.tan(t),0,1,0,0);var e=this._matrices[this._matrices.length-1];return e=o(e,[1,this.tan(t),0,1,0,0]),this},n.prototype.translate=function(t,e){this.drawingContext.translate(t,e);var r=this._matrices[this._matrices.length-1];return r[4]+=r[0]*t+r[2]*e,r[5]+=r[1]*t+r[3]*e,this},n}({},core,constants,outputtext_area),typographyattributes=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._textLeading=15,o.prototype._textFont="sans-serif",o.prototype._textSize=12,o.prototype._textStyle=r.NORMAL,o.prototype.textAlign=function(t){(t===r.LEFT||t===r.RIGHT||t===r.CENTER)&&(this.drawingContext.textAlign=t)},o.prototype.textHeight=function(t){return this.drawingContext.measureText(t).height},o.prototype.textLeading=function(t){this._setProperty("_textLeading",t)},o.prototype.textSize=function(t){this._setProperty("_textSize",t)},o.prototype.textStyle=function(t){(t===r.NORMAL||t===r.ITALIC||t===r.BOLD)&&this._setProperty("_textStyle",t)},o.prototype.textWidth=function(t){return this.drawingContext.measureText(t).width},o}({},core,constants),typographyloading_displaying=function(t,e,r){"use strict";var o=e,r=r;return o.prototype.text=function(){if(this.drawingContext.font=this._textStyle+" "+this._textSize+"px "+this._textFont,3===arguments.length)this._doFill&&this.drawingContext.fillText(arguments[0],arguments[1],arguments[2]),this._doStroke&&this.drawingContext.strokeText(arguments[0],arguments[1],arguments[2]);else if(5===arguments.length){var t=arguments[0].split(" "),e="",o=r.modeAdjust(arguments[1],arguments[2],arguments[3],arguments[4],this._rectMode);o.y+=this._textLeading;for(var n=0;no.h)break;a>o.w&&n>0?(this._doFill&&this.drawingContext.fillText(e,o.x,o.y),this._doStroke&&this.drawingContext.strokeText(e,o.x,o.y),e=t[n]+" ",o.y+=this._textLeading):e=i}o.y<=o.h&&(this._doFill&&this.drawingContext.fillText(e,o.x,o.y),this._doStroke&&this.drawingContext.strokeText(e,o.x,o.y))}},o.prototype.textFont=function(t){this._setProperty("_textFont",t)},o}({},core,canvas),src_app=function(t,e){"use strict";var r=e,o=function(){window.PHANTOMJS||(window.setup&&"function"==typeof window.setup||window.draw&&"function"==typeof window.draw)&&new r};return"complete"===document.readyState?o():window.addEventListener("load",o,!1),window.p5=r,r}({},core,p5Color,p5Element,p5Graphics,p5Image,p5Vector,p5TableRow,p5Table,colorcreating_reading,colorsetting,constants,dataarray_functions,datastring_functions,environment,imageimage,imageloading_displaying,imagepixels,inputfiles,inputkeyboard,inputmouse,inputtime_date,inputtouch,mathmath,mathcalculation,mathrandom,mathnoise,mathtrigonometry,outputfiles,outputimage,outputtext_area,renderingrendering,shape2d_primitives,shapeattributes,shapecurves,shapevertex,structure,transform,typographyattributes,typographyloading_displaying); \ No newline at end of file +var shim=function(){window.requestDraw=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}()}({}),constants=function(){var t=Math.PI;return{ARROW:"default",CROSS:"crosshair",HAND:"pointer",MOVE:"move",TEXT:"text",WAIT:"wait",HALF_PI:t/2,PI:t,QUARTER_PI:t/4,TAU:2*t,TWO_PI:2*t,DEGREES:"degrees",RADIANS:"radians",CORNER:"corner",CORNERS:"corners",RADIUS:"radius",RIGHT:"right",LEFT:"left",CENTER:"center",POINTS:"points",LINES:"lines",TRIANGLES:"triangles",TRIANGLE_FAN:"triangles_fan",TRIANGLE_STRIP:"triangles_strip",QUADS:"quads",QUAD_STRIP:"quad_strip",CLOSE:"close",OPEN:"open",CHORD:"chord",PIE:"pie",PROJECT:"square",SQUARE:"butt",ROUND:"round",BEVEL:"bevel",MITER:"miter",RGB:"rgb",HSB:"hsb",AUTO:"auto",ALT:18,BACKSPACE:8,CONTROL:17,DELETE:46,DOWN_ARROW:40,ENTER:13,ESCAPE:27,LEFT_ARROW:37,OPTION:18,RETURN:13,RIGHT_ARROW:39,SHIFT:16,TAB:9,UP_ARROW:38,BLEND:"normal",ADDITIVE:"lighter",DARKEST:"darken",LIGHTEST:"lighten",DIFFERENCE:"difference",EXCLUSION:"exclusion",MULTIPLY:"multiply",SCREEN:"screen",REPLACE:"source-over",OVERLAY:"overlay",HARD_LIGHT:"hard-light",SOFT_LIGHT:"soft-light",DODGE:"color-dodge",BURN:"color-burn",NORMAL:"normal",ITALIC:"italic",BOLD:"bold",LINEAR:"linear",QUADRATIC:"quadratic",BEZIER:"bezier",CURVE:"curve"}}({}),core=function(t,e,r){"use strict";var r=r,o=function(t,e){this._setupDone=!1,this._pixelDensity=window.devicePixelRatio||1,this._startTime=(new Date).getTime(),this._userNode=e,this._curElement=null,this._elements=[],this._preloadCount=0,this._updateInterval=0,this._isGlobal=!1,this._loop=!0,this.styles=[],this._defaultCanvasSize={width:100,height:100},this._events={mousemove:null,mousedown:null,mouseup:null,click:null,mousewheel:null,mouseover:null,mouseout:null,keydown:null,keyup:null,keypress:null,touchstart:null,touchmove:null,touchend:null},this._start=function(){this._userNode&&"string"==typeof this._userNode&&(this._userNode=document.getElementById(this._userNode)),this.createCanvas(this._defaultCanvasSize.width,this._defaultCanvasSize.height,!0);var t=this.preload||window.preload,e=this._isGlobal?window:this;t?(this._preloadMethods.forEach(function(t){e[t]=function(r){return e._preload(t,r)}}),t(),0===this._preloadCount&&(this._setup(),this._runFrames(),this._draw())):(this._setup(),this._runFrames(),this._draw())}.bind(this),this._preload=function(t,e){var r=this._isGlobal?window:this;return r._setProperty("_preloadCount",r._preloadCount+1),o.prototype[t].call(r,e,function(){r._setProperty("_preloadCount",r._preloadCount-1),0===r._preloadCount&&(r._setup(),r._runFrames(),r._draw())})}.bind(this),this._setup=function(){var t=this._isGlobal?window:this;"function"==typeof t.preload&&this._preloadMethods.forEach(function(e){t[e]=o.prototype[e]}),"function"==typeof t.setup&&t.setup();for(var e=new RegExp(/(^|\s)p5_hidden(?!\S)/g),r=document.getElementsByClassName("p5_hidden"),n=0;n=3?(n=arguments[0],i=arguments[1],s=arguments[2],a="number"==typeof arguments[3]?arguments[3]:e[3]):(t?n=i=s=arguments[0]:(n=s=arguments[0],i=0),a="number"==typeof arguments[1]?arguments[1]:e[3]),n*=255/e[0],i*=255/e[1],s*=255/e[2],a*=255/e[3],[n,i,s,a]},o.Color.getRGB=function(t){var e=t[0],r=t[1],o=t[2];e/=255,r/=255,o/=255;var n=[];if(0===r)n=[Math.round(255*o),Math.round(255*o),Math.round(255*o),t[3]];else{var i=6*e;6===i&&(i=0);var s,a,u,p=Math.floor(i),h=o*(1-r),l=o*(1-r*(i-p)),c=o*(1-r*(1-(i-p)));0===p?(s=o,a=c,u=h):1===p?(s=l,a=o,u=h):2===p?(s=h,a=o,u=c):3===p?(s=h,a=l,u=o):4===p?(s=c,a=h,u=o):(s=o,a=h,u=l),n=[Math.round(255*s),Math.round(255*a),Math.round(255*u),t[3]]}return n},o.Color.getHSB=function(t){var e,r,o=t[0]/255,n=t[1]/255,i=t[2]/255,s=Math.min(o,n,i),a=Math.max(o,n,i),u=a-s,p=a;if(0===u)e=0,r=0;else{r=u/a;var h=((a-o)/6+u/2)/u,l=((a-n)/6+u/2)/u,c=((a-i)/6+u/2)/u;o===a?e=c-l:n===a?e=1/3+h-c:i===a&&(e=2/3+l-h),0>e&&(e+=1),e>1&&(e-=1)}return[Math.round(255*e),Math.round(255*r),Math.round(255*p),t[3]]},o.Color.getColorString=function(t){for(var e=0;3>e;e++)t[e]=Math.floor(t[e]);var r="undefined"!=typeof t[3]?t[3]/255:1;return"rgba("+t[0]+","+t[1]+","+t[2]+","+r+")"},o.Color.getColor=function(){if(arguments[0]instanceof o.Color)return arguments[0].colorString;if(arguments[0]instanceof Array)return o.Color.getColorString(arguments[0]);var t=o.Color.getNormalizedColor.apply(this,arguments);return this._colorMode===r.HSB&&(t=o.Color.getRGB(t)),o.Color.getColorString(t)},o.Color}({},core,constants),p5Element=function(t,e){function r(t,e,r){var o=r,n=function(t){e(t,o)};r.elt.addEventListener(t,n,!1),r._events[t]=n}var o=e;return o.Element=function(t,e){this.elt=t,this._pInst=e,this._events={},this.width=this.elt.offsetWidth,this.height=this.elt.offsetHeight},o.Element.prototype.parent=function(t){"string"==typeof t&&(t=document.getElementById(t)),t.appendChild(this.elt)},o.Element.prototype.id=function(t){this.elt.id=t},o.Element.prototype.class=function(t){this.elt.className+=" "+t},o.Element.prototype.mousePressed=function(t){r("mousedown",t,this)},o.Element.prototype.mouseWheel=function(t){r("mousewheel",t,this)},o.Element.prototype.mouseReleased=function(t){r("mouseup",t,this)},o.Element.prototype.mouseClicked=function(t){r("click",t,this)},o.Element.prototype.mouseMoved=function(t){r("mousemove",t,this)},o.Element.prototype.mouseOver=function(t){r("mouseover",t,this)},o.Element.prototype.mouseOut=function(t){r("mouseout",t,this)},o.Element.prototype._setProperty=function(t,e){this[t]=e},o.Element}({},core),p5Graphics=function(t,e,r){var o=e,r=r;return o.Graphics=function(t,e){o.Element.call(this,t,e),this.canvas=t,this.drawingContext=this.canvas.getContext("2d"),this._pInst?(this._pInst._setProperty("_curElement",this),this._pInst._setProperty("canvas",this.canvas),this._pInst._setProperty("drawingContext",this.drawingContext),this._pInst._setProperty("width",this.width),this._pInst._setProperty("height",this.height)):this.canvas.style.display="none",this.drawingContext.fillStyle="#FFFFFF",this.drawingContext.strokeStyle="#000000",this.drawingContext.lineCap=r.ROUND},o.Graphics.prototype=Object.create(o.Element.prototype),o.Graphics}({},core,constants),filters=function(){"use strict";function t(t){var e=3.5*t|0;if(e=1>e?1:248>e?e:248,o!==e){o=e,n=1+o<<1,i=new Int32Array(n),s=new Array(n);for(var r=0;n>r;r++)s[r]=new Int32Array(256);for(var a,u,p,h,l=1,c=e-1;e>l;l++){i[e+l]=i[c]=u=c*c,p=s[e+l],h=s[c--];for(var d=0;256>d;d++)p[d]=h[d]=u*d}a=i[e]=e*e,p=s[e];for(var f=0;256>f;f++)p[f]=a*f}}function e(e,a){for(var u=r._toPixels(e),p=e.width,h=e.height,l=p*h,c=new Int32Array(l),d=0;l>d;d++)c[d]=r._getARGB(u,d);var f,g,y,m,w,v,_,x,b,C=new Int32Array(l),R=new Int32Array(l),E=new Int32Array(l),S=0;t(a);var M,T,I,A;for(T=0;h>T;T++){for(M=0;p>M;M++){if(m=y=g=f=0,w=M-o,0>w)b=-w,w=0;else{if(w>=p)break;b=0}for(I=b;n>I&&!(w>=p);I++){var P=c[w+S];A=s[I],g+=A[(16711680&P)>>16],y+=A[(65280&P)>>8],m+=A[255&P],f+=i[I],w++}v=S+M,C[v]=g/f,R[v]=y/f,E[v]=m/f}S+=p}for(S=0,_=-o,x=_*p,T=0;h>T;T++){for(M=0;p>M;M++){if(m=y=g=f=0,0>_)b=v=-_,w=M;else{if(_>=h)break;b=0,v=_,w=M+x}for(I=b;n>I&&!(v>=h);I++)A=s[I],g+=A[C[w]],y+=A[R[w]],m+=A[E[w]],f+=i[I],v++,w+=p;c[M+S]=4278190080|g/f<<16|y/f<<8|m/f}S+=p,x+=p,_++}r._setPixels(u,c)}var r={};r._toPixels=function(t){return t instanceof ImageData?t.data:t.getContext("2d").getImageData(0,0,t.width,t.height).data},r._getARGB=function(t,e){var r=4*e;return t[r+3]<<24&4278190080|t[r]<<16&16711680|t[r+1]<<8&65280|255&t[r+2]},r._setPixels=function(t,e){for(var r=0,o=0,n=t.length;n>o;o++)r=4*o,t[r+0]=(16711680&e[o])>>>16,t[r+1]=(65280&e[o])>>>8,t[r+2]=255&e[o],t[r+3]=(4278190080&e[o])>>>24},r._toImageData=function(t){return t instanceof ImageData?t:t.getContext("2d").getImageData(0,0,t.width,t.height)},r._createImageData=function(t,e){return r._tmpCanvas=document.createElement("canvas"),r._tmpCtx=r._tmpCanvas.getContext("2d"),this._tmpCtx.createImageData(t,e)},r.apply=function(t,e,r){var o=t.getContext("2d"),n=o.getImageData(0,0,t.width,t.height),i=e(n,r);i instanceof ImageData?o.putImageData(i,0,0,0,0,t.width,t.height):o.putImageData(n,0,0,0,0,t.width,t.height)},r.threshold=function(t,e){var o=r._toPixels(t);void 0===e&&(e=.5);for(var n=Math.floor(255*e),i=0;i=n?255:0,o[i]=o[i+1]=o[i+2]=s}},r.gray=function(t){for(var e=r._toPixels(t),o=0;oe||e>255)throw new Error("Level must be greater than 2 and less than 255 for posterize");for(var n=e-1,i=0;i>8)/n,o[i+1]=255*(a*e>>8)/n,o[i+2]=255*(u*e>>8)/n}},r.dilate=function(t){for(var e,o,n,i,s,a,u,p,h,l,c,d,f,g,y,m,w,v=r._toPixels(t),_=0,x=v.length?v.length/4:0,b=new Int32Array(x);x>_;)for(e=_,o=_+t.width;o>_;)n=i=r._getARGB(v,_),u=_-1,a=_+1,p=_-t.width,h=_+t.width,e>u&&(u=_),a>=o&&(a=_),0>p&&(p=0),h>=x&&(h=_),d=r._getARGB(v,p),c=r._getARGB(v,u),f=r._getARGB(v,h),l=r._getARGB(v,a),s=77*(n>>16&255)+151*(n>>8&255)+28*(255&n),y=77*(c>>16&255)+151*(c>>8&255)+28*(255&c),g=77*(l>>16&255)+151*(l>>8&255)+28*(255&l),m=77*(d>>16&255)+151*(d>>8&255)+28*(255&d),w=77*(f>>16&255)+151*(f>>8&255)+28*(255&f),y>s&&(i=c,s=y),g>s&&(i=l,s=g),m>s&&(i=d,s=m),w>s&&(i=f,s=w),b[_++]=i;r._setPixels(v,b)},r.erode=function(t){for(var e,o,n,i,s,a,u,p,h,l,c,d,f,g,y,m,w,v=r._toPixels(t),_=0,x=v.length?v.length/4:0,b=new Int32Array(x);x>_;)for(e=_,o=_+t.width;o>_;)n=i=r._getARGB(v,_),u=_-1,a=_+1,p=_-t.width,h=_+t.width,e>u&&(u=_),a>=o&&(a=_),0>p&&(p=0),h>=x&&(h=_),d=r._getARGB(v,p),c=r._getARGB(v,u),f=r._getARGB(v,h),l=r._getARGB(v,a),s=77*(n>>16&255)+151*(n>>8&255)+28*(255&n),y=77*(c>>16&255)+151*(c>>8&255)+28*(255&c),g=77*(l>>16&255)+151*(l>>8&255)+28*(255&l),m=77*(d>>16&255)+151*(d>>8&255)+28*(255&d),w=77*(f>>16&255)+151*(f>>8&255)+28*(255&f),s>y&&(i=c,s=y),s>g&&(i=l,s=g),s>m&&(i=d,s=m),s>w&&(i=f,s=w),b[_++]=i;r._setPixels(v,b)};var o,n,i,s;return r.blur=function(t,r){e(t,r)},r}({}),p5Image=function(t,e,r){"use strict";var o=e,n=r;return o.Image=function(t,e){this.width=t,this.height=e,this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.drawingContext=this.canvas.getContext("2d"),this.pixels=[]},o.Image.prototype._setProperty=function(t,e){this[t]=e},o.Image.prototype.loadPixels=function(){o.prototype.loadPixels.call(this)},o.Image.prototype.updatePixels=function(t,e,r,n){o.prototype.updatePixels.call(this,t,e,r,n)},o.Image.prototype.get=function(t,e,r,n){return o.prototype.get.call(this,t,e,r,n)},o.Image.prototype.set=function(t,e,r){o.prototype.set.call(this,t,e,r)},o.Image.prototype.resize=function(t,e){var r=document.createElement("canvas");r.width=t,r.height=e,r.getContext("2d").drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,r.width,r.width),this.canvas.width=this.width=t,this.canvas.height=this.height=e,this.drawingContext.drawImage(r,0,0,t,e,0,0,t,e),this.pixels.length>0&&this.loadPixels()},o.Image.prototype.copy=function(){o.prototype.copy.apply(this,arguments)},o.Image.prototype.mask=function(t){void 0===t&&(t=this);var e=this.drawingContext.globalCompositeOperation,r=[t,0,0,t.width,t.height,0,0,this.width,this.height];this.drawingContext.globalCompositeOperation="destination-out",this.copy.apply(this,r),this.drawingContext.globalCompositeOperation=e},o.Image.prototype.filter=function(t,e){n.apply(this.canvas,n[t.toLowerCase()],e)},o.Image.prototype.blend=function(){o.prototype.blend.apply(this,arguments)},o.Image.prototype.save=function(t,e){var r;if(e)switch(e.toLowerCase()){case"png":r="image/png";break;case"jpeg":r="image/jpeg";break;case"jpg":r="image/jpeg";break;default:r="image/png"}else e="png",r="image/png";var n="image/octet-stream",i=this.canvas.toDataURL(r);i=i.replace(r,n),o.prototype.downloadFile(i,t,e)},o.Image}({},core,filters),polargeometry=function(){return{degreesToRadians:function(t){return 2*Math.PI*t/360},radiansToDegrees:function(t){return 360*t/(2*Math.PI)}}}({}),p5Vector=function(t,e,r,o){"use strict";var n=e,i=r,o=o;return n.Vector=function(){var t,e,r;arguments[0]instanceof n?(this.p5=arguments[0],t=arguments[1][0]||0,e=arguments[1][1]||0,r=arguments[1][2]||0):(t=arguments[0]||0,e=arguments[1]||0,r=arguments[2]||0),this.x=t,this.y=e,this.z=r},n.Vector.prototype.set=function(t,e,r){return t instanceof n.Vector?(this.x=t.x||0,this.y=t.y||0,this.z=t.z||0,this):t instanceof Array?(this.x=t[0]||0,this.y=t[1]||0,this.z=t[2]||0,this):(this.x=t||0,this.y=e||0,this.z=r||0,this)},n.Vector.prototype.get=function(){return this.p5?new n.Vector(this.p5,[this.x,this.y,this.z]):new n.Vector(this.x,this.y,this.z)},n.Vector.prototype.add=function(t,e,r){return t instanceof n.Vector?(this.x+=t.x||0,this.y+=t.y||0,this.z+=t.z||0,this):t instanceof Array?(this.x+=t[0]||0,this.y+=t[1]||0,this.z+=t[2]||0,this):(this.x+=t||0,this.y+=e||0,this.z+=r||0,this)},n.Vector.prototype.sub=function(t,e,r){return t instanceof n.Vector?(this.x-=t.x||0,this.y-=t.y||0,this.z-=t.z||0,this):t instanceof Array?(this.x-=t[0]||0,this.y-=t[1]||0,this.z-=t[2]||0,this):(this.x-=t||0,this.y-=e||0,this.z-=r||0,this)},n.Vector.prototype.mult=function(t){return this.x*=t||0,this.y*=t||0,this.z*=t||0,this},n.Vector.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},n.Vector.prototype.mag=function(){return Math.sqrt(this.magSq())},n.Vector.prototype.magSq=function(){var t=this.x,e=this.y,r=this.z;return t*t+e*e+r*r},n.Vector.prototype.dot=function(t,e,r){return t instanceof n.Vector?this.dot(t.x,t.y,t.z):this.x*(t||0)+this.y*(e||0)+this.z*(r||0)},n.Vector.prototype.cross=function(t){var e=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,o=this.x*t.y-this.y*t.x;return this.p5?new n.Vector(this.p5,[e,r,o]):new n.Vector(e,r,o)},n.Vector.prototype.dist=function(t){var e=t.get().sub(this);return e.mag()},n.Vector.prototype.normalize=function(){return this.div(this.mag())},n.Vector.prototype.limit=function(t){var e=this.magSq();return e>t*t&&(this.div(Math.sqrt(e)),this.mult(t)),this},n.Vector.prototype.setMag=function(t){return this.normalize().mult(t)},n.Vector.prototype.heading=function(){var t=Math.atan2(this.y,this.x);return this.p5?this.p5._angleMode===o.RADIANS?t:i.radiansToDegrees(t):t},n.Vector.prototype.rotate=function(t){this.p5&&this.p5._angleMode===o.DEGREES&&(t=i.degreesToRadians(t));var e=this.heading()+t,r=this.mag();return this.x=Math.cos(e)*r,this.y=Math.sin(e)*r,this},n.Vector.prototype.lerp=function(t,e,r,o){return t instanceof n.Vector?this.lerp(t.x,t.y,t.z,e):(this.x+=(t-this.x)*o||0,this.y+=(e-this.y)*o||0,this.z+=(r-this.z)*o||0,this)},n.Vector.prototype.array=function(){return[this.x||0,this.y||0,this.z||0]},n.Vector.fromAngle=function(t){return this.p5&&this.p5._angleMode===o.DEGREES&&(t=i.degreesToRadians(t)),this.p5?new n.Vector(this.p5,[Math.cos(t),Math.sin(t),0]):new n.Vector(Math.cos(t),Math.sin(t),0)},n.Vector.random2D=function(){var t;return t=this.p5?this.p5.random(this.p5._angleMode===o.DEGREES?360:o.TWO_PI):Math.random()*Math.PI*2,this.fromAngle(t)},n.Vector.random3D=function(){var t,e;this.p5?(t=this.p5.random(0,o.TWO_PI),e=this.p5.random(-1,1)):(t=Math.random()*Math.PI*2,e=2*Math.random()-1);var r=Math.sqrt(1-e*e)*Math.cos(t),i=Math.sqrt(1-e*e)*Math.sin(t);return this.p5?new n.Vector(this.p5,[r,i,e]):new n.Vector(r,i,e)},n.Vector.add=function(t,e){return t.get().add(e)},n.Vector.sub=function(t,e){return t.get().sub(e)},n.Vector.mult=function(t,e){return t.get().mult(e)},n.Vector.div=function(t,e){return t.get().div(e)},n.Vector.dot=function(t,e){return t.dot(e)},n.Vector.cross=function(t,e){return t.cross(e)},n.Vector.dist=function(t,e){return t.dist(e)},n.Vector.lerp=function(t,e,r){return t.get().lerp(e,r)},n.Vector.angleBetween=function(t,e){var r=Math.acos(t.dot(e)/(t.mag()*e.mag()));return this.p5&&this.p5._angleMode===o.DEGREES&&(r=i.radiansToDegrees(r)),r},n.Vector}({},core,polargeometry,constants),p5TableRow=function(t,e){"use strict";var r=e;return r.TableRow=function(t,e){var r=[],o={};t&&(e=e||",",r=t.split(e));for(var n=0;n=0))throw'This table has no column named "'+t+'"';this.obj[t]=e,this.arr[r]=e}else{if(!(ta;a++)s.push(r.prototype.lerp(t.rgba[a],e.rgba[a],o));return new r.Color(this,s)}return r.prototype.lerp(t,e,o)},r.prototype.red=function(t){if(t instanceof Array)return t[0];if(t instanceof r.Color)return t.rgba[0];throw new Error("Needs p5.Color or pixel array as argument.")},r.prototype.saturation=function(t){if(!t instanceof r.Color)throw new Error("Needs p5.Color as argument.");return t.hsba||(t.hsba=r.Color.getRGB(t.rgba),t.hsba=t.hsba.concat(t.rgba[3])),t.hsba[1]},r}({},core,p5Color),colorsetting=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._doStroke=!0,o.prototype._doFill=!0,o.prototype._colorMode=r.RGB,o.prototype._maxRGB=[255,255,255,255],o.prototype._maxHSB=[255,255,255,255],o.prototype.background=function(){if(arguments[0]instanceof o.Image)this.image(arguments[0],0,0,this.width,this.height);else{var t=this.drawingContext.fillStyle,e=this.drawingContext;e.fillStyle=o.Color.getColor.apply(this,arguments),e.fillRect(0,0,this.width,this.height),e.fillStyle=t}},o.prototype.clear=function(){this.drawingContext.clearRect(0,0,this.width,this.height)},o.prototype.colorMode=function(){if(arguments[0]===r.RGB||arguments[0]===r.HSB){this._colorMode=arguments[0];var t=this._colorMode===r.RGB,e=t?this._maxRGB:this._maxHSB;2===arguments.length?(e[0]=arguments[1],e[1]=arguments[1],e[2]=arguments[1]):arguments.length>2&&(e[0]=arguments[1],e[1]=arguments[2],e[2]=arguments[3]),5===arguments.length&&(e[3]=arguments[4])}},o.prototype.fill=function(){this._setProperty("_doFill",!0);var t=this.drawingContext;t.fillStyle=o.Color.getColor.apply(this,arguments)},o.prototype.noFill=function(){this._setProperty("_doFill",!1)},o.prototype.noStroke=function(){this._setProperty("_doStroke",!1)},o.prototype.stroke=function(){this._setProperty("_doStroke",!0);var t=this.drawingContext;t.strokeStyle=o.Color.getColor.apply(this,arguments)},o}({},core,constants,p5Color),dataarray_functions=function(t,e){"use strict";var r=e;return r.prototype.append=function(t,e){return t.push(e),t},r.prototype.arrayCopy=function(t,e,r,o,n){var i,s;"undefined"!=typeof n?(s=Math.min(n,t.length),i=o,t=t.slice(e,s+e)):("undefined"!=typeof r?(s=r,s=Math.min(s,t.length)):s=t.length,i=0,r=e,t=t.slice(0,s)),Array.prototype.splice.apply(r,[i,s].concat(t))},r.prototype.concat=function(t,e){return t.concat(e)},r.prototype.reverse=function(t){return t.reverse()},r.prototype.shorten=function(t){return t.pop(),t},r.prototype.sort=function(t,e){var r=e?t.slice(0,Math.min(e,t.length)):t,o=e?t.slice(Math.min(e,t.length)):[];return r="string"==typeof r[0]?r.sort():r.sort(function(t,e){return t-e}),r.concat(o)},r.prototype.splice=function(t,e,r){return Array.prototype.splice.apply(t,[r,0].concat(e)),t},r.prototype.subset=function(t,e,r){return"undefined"!=typeof r?t.slice(e,e+r):t.slice(e,t.length)},r}({},core),datastring_functions=function(t,e){"use strict";function r(){var t=arguments[0],e=0>t,r=e?t.toString().substring(1):t.toString(),o=r.indexOf("."),n=-1!==o?r.substring(0,o):r,i=-1!==o?r.substring(o+1):"",s=e?"-":"";if(3===arguments.length){for(var a=0;a1&&(r=r.substring(0,arguments[1]+1)),o+r}function n(){return parseFloat(arguments[0])>0?"+"+arguments[0].toString():arguments[0].toString()}function i(){return parseFloat(arguments[0])>0?" "+arguments[0].toString():arguments[0].toString()}var s=e;return s.prototype.join=function(t,e){return t.join(e)},s.prototype.match=function(t,e){return t.match(e)},s.prototype.matchAll=function(t,e){for(var r=new RegExp(e,"g"),o=r.exec(t),n=[];null!==o;)n.push(o),o=r.exec(t);return n},s.prototype.nf=function(){if(arguments[0]instanceof Array){var t=arguments[1],e=arguments[2];return arguments[0].map(function(o){return r(o,t,e)})}return r.apply(this,arguments)},s.prototype.nfc=function(){if(arguments[0]instanceof Array){var t=arguments[1];return arguments[0].map(function(e){return o(e,t)})}return o.apply(this,arguments)},s.prototype.nfp=function(){var t=this.nf(arguments);return t instanceof Array?t.map(n):n(t)},s.prototype.nfs=function(){var t=this.nf(arguments);return t instanceof Array?t.map(i):i(t)},s.prototype.split=function(t,e){return t.split(e)},s.prototype.splitTokens=function(){var t=arguments.length>0?arguments[1]:/\s/g;return arguments[0].split(t).filter(function(t){return t})},s.prototype.trim=function(t){return t instanceof Array?t.map(this.trim):t.trim()},s}({},core),environment=function(t,e,r){"use strict";function o(t){var e=document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled;if(!e)throw new Error("Fullscreen not enabled in this browser.");t.requestFullscreen?t.requestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen?t.webkitRequestFullscreen():t.msRequestFullscreen&&t.msRequestFullscreen()}function n(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}var i=e,s=r,a=[s.ARROW,s.CROSS,s.HAND,s.MOVE,s.TEXT,s.WAIT];return i.prototype._frameRate=0,i.prototype._lastFrameTime=0,i.prototype._targetFrameRate=60,i.prototype.frameCount=0,i.prototype.focused=!0,i.prototype.cursor=function(t,e,r){var o="auto",n=this._curElement.elt;if(a.indexOf(t)>-1)o=t;else if("string"==typeof t){var i="";e&&r&&"number"==typeof e&&"number"==typeof r&&(i=e+" "+r),o="http://"!==t.substring(0,6)?"url("+t+") "+i+", auto":/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(t)?"url("+t+") "+i+", auto":t}n.style.cursor=o},i.prototype.frameRate=function(t){return"undefined"==typeof t?this._frameRate:(this._setProperty("_targetFrameRate",t),this._runFrames(),this)},i.prototype.getFrameRate=function(){return this.frameRate() +},i.prototype.setFrameRate=function(t){return this.frameRate(t)},i.prototype.noCursor=function(){this._curElement.elt.style.cursor="none"},i.prototype.displayWidth=screen.width,i.prototype.displayHeight=screen.height,i.prototype.windowWidth=window.innerWidth,i.prototype.windowHeight=window.innerHeight,window.addEventListener("resize",function(){this.windowWidth=window.innerWidth,this.windowHeight=window.innerHeight}),i.prototype.width=0,i.prototype.height=0,i.prototype.fullscreen=function(t){return"undefined"==typeof t?document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement:void(t?o(document.documentElement):n())},i}({},core,constants),imageimage=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._imageMode=r.CORNER,o.prototype._tint=null,o.prototype.createImage=function(t,e){return new o.Image(t,e)},o}({},core,constants),canvas=function(t,e){var e=e;return{modeAdjust:function(t,r,o,n,i){return i===e.CORNER?{x:t,y:r,w:o,h:n}:i===e.CORNERS?{x:t,y:r,w:o-t,h:n-r}:i===e.RADIUS?{x:t-o,y:r-n,w:2*o,h:2*n}:i===e.CENTER?{x:t-.5*o,y:r-.5*n,w:o,h:n}:void 0},arcModeAdjust:function(t,r,o,n,i){return i===e.CORNER?{x:t+.5*o,y:r+.5*n,w:o,h:n}:i===e.CORNERS?{x:t,y:r,w:o+t,h:n+r}:i===e.RADIUS?{x:t,y:r,w:2*o,h:2*n}:i===e.CENTER?{x:t,y:r,w:o,h:n}:void 0}}}({},constants),imageloading_displaying=function(t,e,r,o,n){"use strict";var i=e,s=r,o=o,n=n;return i.prototype.loadImage=function(t,e){var r=new Image,o=new i.Image(1,1,this);return r.onload=function(){o.width=o.canvas.width=r.width,o.height=o.canvas.height=r.height,o.canvas.getContext("2d").drawImage(r,0,0),"undefined"!=typeof e&&e(o)},r.crossOrigin="Anonymous",r.src=t,o},i.prototype.image=function(t,e,r,n,i){var s=t.canvas?t.canvas:t.elt;void 0===n&&(n=t.width),void 0===i&&(i=t.height);var a=o.modeAdjust(e,r,n,i,this._imageMode);this._tint?this.drawingContext.drawImage(this._getTintedImageCanvas(t),a.x,a.y,a.w,a.h):this.drawingContext.drawImage(s,a.x,a.y,a.w,a.h)},i.prototype.tint=function(){var t=i.Color.getNormalizedColor.apply(this,arguments);this._tint=t},i.prototype.noTint=function(){this._tint=null},i.prototype._getTintedImageCanvas=function(t){if(!t.canvas)return t;var e=s._toPixels(t.canvas),r=document.createElement("canvas");r.width=t.canvas.width,r.height=t.canvas.height;for(var o=r.getContext("2d"),n=o.createImageData(t.canvas.width,t.canvas.height),i=n.data,a=0;athis.width||e>this.height||0>t||0>e)return[0,0,0,255];var i=this.drawingContext.getImageData(t,e,r,n),s=i.data;if(1===r&&1===n){for(var a=[],u=0;u0;)self._completeHandlers.shift()(t)}function success(resp){resp="jsonp"!==type?self.request:resp;var filteredResponse=globalSetupOptions.dataFilter(resp.responseText,type),r=filteredResponse;try{resp.responseText=r}catch(e){}if(r)switch(type){case"json":try{resp=win.JSON?win.JSON.parse(r):eval("("+r+")")}catch(err){return error(resp,"Could not parse JSON in response",err)}break;case"js":resp=eval(r);break;case"html":resp=r;break;case"xml":resp=resp.responseXML&&resp.responseXML.parseError&&resp.responseXML.parseError.errorCode&&resp.responseXML.parseError.reason?null:resp.responseXML}for(self._responseArgs.resp=resp,self._fulfilled=!0,fn(resp),self._successHandler(resp);self._fulfillmentHandlers.length>0;)resp=self._fulfillmentHandlers.shift()(resp);complete(resp)}function error(t,e,r){for(t=self.request,self._responseArgs.resp=t,self._responseArgs.msg=e,self._responseArgs.t=r,self._erred=!0;self._errorHandlers.length>0;)self._errorHandlers.shift()(t,e,r);complete(t)}this.url="string"==typeof o?o:o.url,this.timeout=null,this._fulfilled=!1,this._successHandler=function(){},this._fulfillmentHandlers=[],this._errorHandlers=[],this._completeHandlers=[],this._erred=!1,this._responseArgs={};var self=this,type=o.type||setType(this.url);fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort()},o.timeout)),o.success&&(this._successHandler=function(){o.success.apply(o,arguments)}),o.error&&this._errorHandlers.push(function(){o.error.apply(o,arguments)}),o.complete&&this._completeHandlers.push(function(){o.complete.apply(o,arguments)}),this.request=getRequest.call(this,success,error)}function reqwest(t,e){return new Reqwest(t,e)}function normalize(t){return t?t.replace(/\r?\n/g,"\r\n"):""}function serial(t,e){var r,o,n,i,s=t.name,a=t.tagName.toLowerCase(),u=function(t){t&&!t.disabled&&e(s,normalize(t.attributes.value&&t.attributes.value.specified?t.value:t.text))};if(!t.disabled&&s)switch(a){case"input":/reset|button|image|file/i.test(t.type)||(r=/checkbox/i.test(t.type),o=/radio/i.test(t.type),n=t.value,(!(r||o)||t.checked)&&e(s,normalize(r&&""===n?"on":n)));break;case"textarea":e(s,normalize(t.value));break;case"select":if("select-one"===t.type.toLowerCase())u(t.selectedIndex>=0?t.options[t.selectedIndex]:null);else for(i=0;t.length&&ie){var i=t;t=e,e=i}return r*(e-t)+t};var i,s=!1;return r.prototype.randomGaussian=function(t,e){var r,o,n,a;if(s)r=i,s=!1;else{do o=this.random(2)-1,n=this.random(2)-1,a=o*o+n*n;while(a>=1);a=Math.sqrt(-2*Math.log(a)/a),r=o*a,i=n*a,s=!0}var u=t||0,p=e||1;return r*p+u},r}({},core),mathnoise=function(t,e){"use strict";for(var r=e,o=4,n=1<g;g++)c[g]=Math.sin(g*f*h),d[g]=Math.cos(g*f*h);var y=l;y>>=1;var m;return r.prototype.noise=function(t,e,r){if(e=e||0,r=r||0,null==m){m=new Array(a+1);for(var h=0;a+1>h;h++)m[h]=Math.random()}0>t&&(t=-t),0>e&&(e=-e),0>r&&(r=-r);for(var c,f,g,w,v,_=Math.floor(t),x=Math.floor(e),b=Math.floor(r),C=t-_,R=e-x,E=r-b,S=0,M=.5,T=function(t){return.5*(1-d[Math.floor(t*y)%l])},I=0;u>I;I++){var A=_+(x<=1&&(_++,C--),R>=1&&(x++,R--),E>=1&&(b++,E--)}return S},r.prototype.noiseDetail=function(t,e){t>0&&(u=t),e>0&&(p=e)},r.prototype.noiseSeed=function(t){var e=function(){var t,e,r=4294967296,o=1664525,n=1013904223;return{setSeed:function(o){e=t=o||Math.round(Math.random()*r)},getSeed:function(){return t},rand:function(){return e=(o*e+n)%r,e/r}}}();e.setSeed(t),m=new Array(a+1);for(var r=0;a+1>r;r++)m[r]=e.rand()},r}({},core),mathtrigonometry=function(t,e,r,o){"use strict";var n=e,i=r,o=o;return n.prototype._angleMode=o.RADIANS,n.prototype.acos=function(t){return this._angleMode===o.RADIANS?Math.acos(t):i.radiansToDegrees(Math.acos(t))},n.prototype.asin=function(t){return this._angleMode===o.RADIANS?Math.asin(t):i.radiansToDegrees(Math.asin(t))},n.prototype.atan=function(t){return this._angleMode===o.RADIANS?Math.atan(t):i.radiansToDegrees(Math.atan(t))},n.prototype.atan2=function(t,e){return this._angleMode===o.RADIANS?Math.atan2(t,e):i.radiansToDegrees(Math.atan2(t,e))},n.prototype.cos=function(t){return Math.cos(this._angleMode===o.RADIANS?t:this.radians(t))},n.prototype.sin=function(t){return Math.sin(this._angleMode===o.RADIANS?t:this.radians(t))},n.prototype.tan=function(t){return Math.tan(this._angleMode===o.RADIANS?t:this.radians(t))},n.prototype.degrees=function(t){return i.radiansToDegrees(t)},n.prototype.radians=function(t){return i.degreesToRadians(t)},n.prototype.angleMode=function(t){(t===o.DEGREES||t===o.RADIANS)&&(this._angleMode=t)},n}({},core,polargeometry,constants),outputfiles=function(t,e){"use strict";function r(t,e){e||(e="");var r="";return t?r=t.split(".").pop():t="untitled",e&&r!==e&&(r=e,t=t+"."+r),[t,r]}function o(t){document.body.removeChild(t.target)}var n=e;return window.URL=window.URL||window.webkitURL,n.prototype._pWriters=[],n.prototype.beginRaw=function(){throw"not yet implemented"},n.prototype.beginRecord=function(){throw"not yet implemented"},n.prototype.createOutput=function(){throw"not yet implemented"},n.prototype.createWriter=function(t,e){var r;for(var o in n.prototype._pWriters)if(n.prototype._pWriters[o].name===t)return r=new n.PrintWriter(t+window.millis(),e),n.prototype._pWriters.push(r),r;return r=new n.PrintWriter(t,e),n.prototype._pWriters.push(r),r},n.prototype.endRaw=function(){throw"not yet implemented"},n.prototype.endRecord=function(){throw"not yet implemented"},n.prototype.escape=function(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")},n.PrintWriter=function(t,e){var r=this;this.name=t,this.content="",this.print=function(t){this.content+=t},this.println=function(t){this.content+=t+"\n"},this.flush=function(){this.content=""},this.close=function(){var o=[];o.push(this.content),n.prototype.writeFile(o,t,e);for(var i in n.prototype._pWriters)n.prototype._pWriters[i].name===this.name&&n.prototype._pWriters.splice(i,1);r.flush(),r={}}},n.prototype.saveBytes=function(){throw"not yet implemented"},n.prototype.save=function(){var t=arguments,e=this._curElement.elt;if(0===t.length)return void n.prototype.saveCanvas(null,null,e);if("string"==typeof t[0])return void("object"==typeof t[2]?n.prototype.saveCanvas(t[0],t[1],t[2]):"string"==typeof t[1]?n.prototype.saveCanvas(t[0],t[1],e):n.prototype.saveCanvas(t[0],null,e));var o=r(t[1],t[2])[1];switch(o){case"json":n.prototype.saveJSON(t[0],t[1],t[2]);break;case"txt":n.prototype.saveStrings(t[0],t[1],t[2]);break;default:t[0]instanceof Array?n.prototype.saveStrings(t[0],t[1],t[2]):t[0]instanceof n.Table?n.prototype.saveTable(t[0],t[1],t[2],t[3]):t[0]instanceof n.Image?n.prototype.saveCanvas(t[1],t[2],t[0].canvas):t[0]instanceof n.SoundFile?n.prototype.saveSound(t[0],t[1],t[2],t[3]):t[0]instanceof Object&&n.prototype.saveJSON(t[0],t[1],t[2])}},n.prototype.saveJSON=function(t,e,r){var o;o=r?JSON.stringify(t):JSON.stringify(t,void 0,2),this.saveStrings(o.split("\n"),e,"json")},n.prototype.saveJSONObject=n.prototype.saveJSON,n.prototype.saveJSONArray=n.prototype.saveJSON,n.prototype.saveStream=function(){throw"not yet implemented"},n.prototype.saveStrings=function(t,e,r){var o=r||"txt",n=this.createWriter(e,o);for(var i in t)i"),o.println("");var h=' "),o.println(""),o.println(" "),"0"!==i[0]){o.println(" ");for(var l=0;l"+c),o.println(" ")}o.println(" ")}for(var d=0;d");for(var f=0;f"+y),o.println(" ")}o.println(" ")}o.println("
"),o.println(""),o.print("")}o.close(),o.flush()},n.prototype.writeFile=function(t,e,r){var o="application/octet-stream";n.prototype._isSafari()&&(o="text/plain");var i=new Blob(t,{type:o}),s=window.URL.createObjectURL(i);n.prototype.downloadFile(s,e,r)},n.prototype.downloadFile=function(t,e,i){var s=r(e,i),a=s[0],u=s[1],p=document.createElement("a");if(p.href=t,p.download=a,p.onclick=o,p.style.display="none",document.body.appendChild(p),n.prototype._isSafari()){var h="Hello, Safari user! To download this file...\n";h+="1. Go to File --> Save As.\n",h+='2. Choose "Page Source" as the Format.\n',h+='3. Name it with this extension: ."'+u+'"',alert(h)}p.click(),t=null},n.prototype._isSafari=function(){var t=Object.prototype.toString.call(window.HTMLElement);return t.indexOf("Constructor")>0},n}({},core),outputimage=function(t,e){"use strict";var r=e,o=[];return r.prototype.saveCanvas=function(t,e,o){var n;if(o?n=o:this._curElement&&this._curElement.elt&&(n=this._curElement.elt),r.prototype._isSafari()){var i="Hello, Safari user!\n";i+="Now capturing a screenshot...\n",i+="To save this image,\n",i+="go to File --> Save As.\n",alert(i),window.location.href=n.toDataURL()}else{var s;if(e)switch(e.toLowerCase()){case"png":s="image/png";break;case"jpeg":s="image/jpeg";break;case"jpg":s="image/jpeg";break;default:s="image/png"}else e="png",s="image/png";var a="image/octet-stream",u=n.toDataURL(s);u=u.replace(s,a),r.prototype.downloadFile(u,t,e)}},r.prototype.saveFrames=function(t,e,n,i,s){var a=n||3;a=r.prototype.constrain(a,0,15),a=1e3*a;var u=i||15;u=r.prototype.constrain(u,0,22);var p=0,h=r.prototype._makeFrame,l=this._curElement.elt,c=setInterval(function(){h(t+p,e,l),p++},1e3/u);setTimeout(function(){if(clearInterval(c),s)s(o);else for(var t=0;th.w?h.h/2:h.w/2,c=h.h>h.w?h.w/h.h:1,d=h.h>h.w?1:h.h/h.w;return p.scale(c,d),p.beginPath(),p.arc(h.x,h.y,l,s,a),this._doStroke&&p.stroke(),u===o.CHORD||u===o.OPEN?p.closePath():(u===o.PIE||void 0===u)&&(p.lineTo(h.x,h.y),p.closePath()),this._doFill&&p.fill(),this._doStroke&&u!==o.OPEN&&void 0!==u&&p.stroke(),this}},n.prototype.ellipse=function(t,e,o,n){if(this._doStroke||this._doFill){var i=this.drawingContext,s=r.modeAdjust(t,e,o,n,this._ellipseMode),a=.5522848,u=s.w/2*a,p=s.h/2*a,h=s.x+s.w,l=s.y+s.h,c=s.x+s.w/2,d=s.y+s.h/2;return i.beginPath(),i.moveTo(s.x,d),i.bezierCurveTo(s.x,d-p,c-u,s.y,c,s.y),i.bezierCurveTo(c+u,s.y,h,d-p,h,d),i.bezierCurveTo(h,d+p,c+u,l,c,l),i.bezierCurveTo(c-u,l,s.x,d+p,s.x,d),i.closePath(),this._doFill&&i.fill(),this._doStroke&&i.stroke(),this}},n.prototype.line=function(t,e,r,o){if(this._doStroke){var n=this.drawingContext;if("rgba(0,0,0,0)"!==n.strokeStyle)return n.beginPath(),n.moveTo(t,e),n.lineTo(r,o),n.stroke(),this}},n.prototype.point=function(t,e){if(this._doStroke){var r=this.drawingContext,n=r.strokeStyle,i=r.fillStyle;if("rgba(0,0,0,0)"!==n)return t=Math.round(t),e=Math.round(e),r.fillStyle=n,r.lineWidth>1?(r.beginPath(),r.arc(t,e,r.lineWidth/2,0,o.TWO_PI,!1),r.fill()):r.fillRect(t,e,1,1),r.fillStyle=i,this}},n.prototype.quad=function(t,e,r,o,n,i,s,a){if(this._doStroke||this._doFill){var u=this.drawingContext;return u.beginPath(),u.moveTo(t,e),u.lineTo(r,o),u.lineTo(n,i),u.lineTo(s,a),u.closePath(),this._doFill&&u.fill(),this._doStroke&&u.stroke(),this}},n.prototype.rect=function(t,e,o,n){if(this._doStroke||this._doFill){var i=r.modeAdjust(t,e,o,n,this._rectMode),s=this.drawingContext;return this._doStroke&&s.lineWidth%2===1&&s.translate(.5,.5),s.beginPath(),s.rect(i.x,i.y,i.w,i.h),this._doFill&&s.fill(),this._doStroke&&s.stroke(),this._doStroke&&s.lineWidth%2===1&&s.translate(-.5,-.5),this}},n.prototype.triangle=function(t,e,r,o,n,i){if(this._doStroke||this._doFill){var s=this.drawingContext;return s.beginPath(),s.moveTo(t,e),s.lineTo(r,o),s.lineTo(n,i),s.closePath(),this._doFill&&s.fill(),this._doStroke&&s.stroke(),this}},n}({},core,canvas,constants),shapeattributes=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._rectMode=r.CORNER,o.prototype._ellipseMode=r.CENTER,o.prototype.ellipseMode=function(t){return(t===r.CORNER||t===r.CORNERS||t===r.RADIUS||t===r.CENTER)&&(this._ellipseMode=t),this},o.prototype.noSmooth=function(){return this.drawingContext.mozImageSmoothingEnabled=!1,this.drawingContext.webkitImageSmoothingEnabled=!1,this},o.prototype.rectMode=function(t){return(t===r.CORNER||t===r.CORNERS||t===r.RADIUS||t===r.CENTER)&&(this._rectMode=t),this},o.prototype.smooth=function(){return this.drawingContext.mozImageSmoothingEnabled=!0,this.drawingContext.webkitImageSmoothingEnabled=!0,this},o.prototype.strokeCap=function(t){return(t===r.ROUND||t===r.SQUARE||t===r.PROJECT)&&(this.drawingContext.lineCap=t),this},o.prototype.strokeJoin=function(t){return(t===r.ROUND||t===r.BEVEL||t===r.MITER)&&(this.drawingContext.lineJoin=t),this},o.prototype.strokeWeight=function(t){return this.drawingContext.lineWidth="undefined"==typeof t||0===t?1e-4:t,this},o}({},core,constants),shapecurves=function(t,e){"use strict";var r=e;return r.prototype._bezierDetail=20,r.prototype._curveDetail=20,r.prototype.bezier=function(t,e,o,n,i,s,a,u){if(this._doStroke){var p=this.drawingContext;p.beginPath(),p.moveTo(t,e);for(var h=0;h<=this._bezierDetail;h++){var l=h/parseFloat(this._bezierDetail),c=r.prototype.bezierPoint(t,o,i,a,l),d=r.prototype.bezierPoint(e,n,s,u,l);p.lineTo(c,d)}return p.stroke(),this}},r.prototype.bezierDetail=function(t){return this._setProperty("_bezierDetail",t),this},r.prototype.bezierPoint=function(t,e,r,o,n){var i=1-n;return Math.pow(i,3)*t+3*Math.pow(i,2)*n*e+3*i*Math.pow(n,2)*r+Math.pow(n,3)*o},r.prototype.bezierTangent=function(t,e,r,o,n){var i=1-n;return 3*o*Math.pow(n,2)-3*r*Math.pow(n,2)+6*r*i*n-6*e*i*n+3*e*Math.pow(i,2)-3*t*Math.pow(i,2)},r.prototype.curve=function(t,e,o,n,i,s,a,u){if(this._doStroke){var p=this.drawingContext;p.moveTo(t,e),p.beginPath();for(var h=0;h<=this._curveDetail;h++){var l=parseFloat(h/this._curveDetail),c=r.prototype.curvePoint(t,o,i,a,l),d=r.prototype.curvePoint(e,n,s,u,l);p.lineTo(c,d)}return p.stroke(),p.closePath(),this}},r.prototype.curveDetail=function(t){return this._setProperty("_curveDetail",t),this},r.prototype.curvePoint=function(t,e,r,o,n){var i=n*n*n,s=n*n,a=-.5*i+s-.5*n,u=1.5*i-2.5*s+1,p=-1.5*i+2*s+.5*n,h=.5*i-.5*s;return t*a+e*u+r*p+o*h},r.prototype.curveTangent=function(t,e,r,o,n){var i=n*n,s=-3*i/2+2*n-.5,a=9*i/2-5*n,u=-9*i/2+4*n+.5,p=3*i/2-n;return t*s+e*a+r*u+o*p},r.prototype.curveTightness=function(){throw"not yet implemented"},r}({},core),shapevertex=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._shapeKind=null,o.prototype._shapeInited=!1,o.prototype._contourInited=!1,o.prototype._contourVertices=[],o.prototype._curveVertices=[],o.prototype.beginContour=function(){return this._contourVertices=[],this._contourInited=!0,this},o.prototype.beginShape=function(t){return this._shapeKind=t===r.POINTS||t===r.LINES||t===r.TRIANGLES||t===r.TRIANGLE_FAN||t===r.TRIANGLE_STRIP||t===r.QUADS||t===r.QUAD_STRIP?t:null,this._shapeInited=!0,this.drawingContext.beginPath(),this},o.prototype.bezierVertex=function(t,e,o,n,i,s){if(this._contourInited){var a={};return a.x=t,a.y=e,a.x3=o,a.y3=n,a.x4=i,a.y4=s,a.type=r.BEZIER,this._contourVertices.push(a),this}return this.drawingContext.bezierCurveTo(t,e,o,n,i,s),this},o.prototype.curveVertex=function(t,e){var r={};return r.x=t,r.y=e,this._curveVertices.push(r),this._curveVertices.length>=4&&(this.curve(this._curveVertices[0].x,this._curveVertices[0].y,this._curveVertices[1].x,this._curveVertices[1].y,this._curveVertices[2].x,this._curveVertices[2].y,this._curveVertices[3].x,this._curveVertices[3].y),this._curveVertices.shift()),this},o.prototype.endContour=function(){this._contourVertices.reverse(),this.drawingContext.moveTo(this._contourVertices[0].x,this._contourVertices[0].y);var t=this.drawingContext;return this._contourVertices.slice(1).forEach(function(e){switch(e.type){case r.LINEAR:t.lineTo(e.x,e.y);break;case r.QUADRATIC:t.quadraticCurveTo(e.x,e.y,e.x3,e.y3);break;case r.BEZIER:t.bezierCurveTo(e.x,e.y,e.x3,e.y3,e.x4,e.y4);break;case r.CURVE:}}),this.drawingContext.closePath(),this._contourInited=!1,this},o.prototype.endShape=function(t){return t===r.CLOSE&&(this.drawingContext.closePath(),this._doFill&&this.drawingContext.fill()),this._doStroke&&this._curveVertices.length<=0?this.drawingContext.stroke():this._curveVertices=[],this},o.prototype.quadraticVertex=function(t,e,o,n){if(this._contourInited){var i={};return i.x=t,i.y=e,i.x3=o,i.y3=n,i.type=r.QUADRATIC,this._contourVertices.push(i),this}return this.drawingContext.quadraticCurveTo(t,e,o,n),this},o.prototype.vertex=function(t,e){if(this._contourInited){var o={};return o.x=t,o.y=e,o.type=r.LINEAR,this._contourVertices.push(o),this}return this._shapeInited?this.drawingContext.moveTo(t,e):this.drawingContext.lineTo(t,e),this._shapeInited=!1,this},o}({},core,constants),structure=function(t,e){"use strict";var r=e;return r.prototype.exit=function(){throw"exit() not implemented, see remove()"},r.prototype.noLoop=function(){this._loop=!1,this._drawInterval&&clearInterval(this._drawInterval)},r.prototype.loop=function(){this._loop=!0,this._draw()},r.prototype.push=function(){this.drawingContext.save(),this.styles.push({doStroke:this._doStroke,doFill:this._doFill,tint:this._tint,imageMode:this._imageMode,rectMode:this._rectMode,ellipseMode:this._ellipseMode,colorMode:this._colorMode,textFont:this.textFont,textLeading:this.textLeading,textSize:this.textSize,textStyle:this.textStyle})},r.prototype.pop=function(){this.drawingContext.restore();var t=this.styles.pop();this._doStroke=t.doStroke,this._doFill=t.doFill,this._tint=t.tint,this._imageMode=t.imageMode,this._rectMode=t.rectMode,this._ellipseMode=t.ellipseMode,this._colorMode=t.colorMode,this.textFont=t.textFont,this.textLeading=t.textLeading,this.textSize=t.textSize,this.textStyle=t.textStyle},r.prototype.pushStyle=function(){throw new Error("pushStyle() not used, see push()")},r.prototype.popStyle=function(){throw new Error("popStyle() not used, see pop()")},r.prototype.redraw=function(){var t=this._isGlobal?window:this;t.draw&&t.draw()},r.prototype.size=function(){throw"size() not implemented, see createCanvas()"},r}({},core),transform=function(t,e,r){"use strict";var o=e,r=r;return o.prototype.applyMatrix=function(t,e,r,o,n,i){return this.drawingContext.transform(t,e,r,o,n,i),this},o.prototype.popMatrix=function(){throw new Error("popMatrix() not used, see pop()")},o.prototype.printMatrix=function(){throw new Error("printMatrix() not implemented")},o.prototype.pushMatrix=function(){throw new Error("pushMatrix() not used, see push()")},o.prototype.resetMatrix=function(){return this.drawingContext.setTransform(),this},o.prototype.rotate=function(t){return this._angleMode===r.DEGREES&&(t=this.radians(t)),this.drawingContext.rotate(t),this},o.prototype.rotateX=function(){throw"not yet implemented"},o.prototype.rotateY=function(){throw"not yet implemented"},o.prototype.scale=function(){var t=1,e=1;return 1===arguments.length?t=e=arguments[0]:(t=arguments[0],e=arguments[1]),this.drawingContext.scale(t,e),this},o.prototype.shearX=function(t){return this._angleMode===r.DEGREES&&(t=this.radians(t)),this.drawingContext.transform(1,0,this.tan(t),1,0,0),this},o.prototype.shearY=function(t){return this._angleMode===r.DEGREES&&(t=this.radians(t)),this.drawingContext.transform(1,this.tan(t),0,1,0,0),this},o.prototype.translate=function(t,e){return this.drawingContext.translate(t,e),this},o}({},core,constants,outputtext_area),typographyattributes=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._textLeading=15,o.prototype._textFont="sans-serif",o.prototype._textSize=12,o.prototype._textStyle=r.NORMAL,o.prototype.textAlign=function(t){(t===r.LEFT||t===r.RIGHT||t===r.CENTER)&&(this.drawingContext.textAlign=t)},o.prototype.textHeight=function(t){return this.drawingContext.measureText(t).height},o.prototype.textLeading=function(t){this._setProperty("_textLeading",t)},o.prototype.textSize=function(t){this._setProperty("_textSize",t)},o.prototype.textStyle=function(t){(t===r.NORMAL||t===r.ITALIC||t===r.BOLD)&&this._setProperty("_textStyle",t)},o.prototype.textWidth=function(t){return this.drawingContext.measureText(t).width},o}({},core,constants),typographyloading_displaying=function(t,e,r){"use strict";var o=e,r=r;return o.prototype.text=function(){if(this.drawingContext.font=this._textStyle+" "+this._textSize+"px "+this._textFont,3===arguments.length)this._doFill&&this.drawingContext.fillText(arguments[0],arguments[1],arguments[2]),this._doStroke&&this.drawingContext.strokeText(arguments[0],arguments[1],arguments[2]);else if(5===arguments.length){var t=arguments[0].split(" "),e="",o=r.modeAdjust(arguments[1],arguments[2],arguments[3],arguments[4],this._rectMode);o.y+=this._textLeading;for(var n=0;no.h)break;a>o.w&&n>0?(this._doFill&&this.drawingContext.fillText(e,o.x,o.y),this._doStroke&&this.drawingContext.strokeText(e,o.x,o.y),e=t[n]+" ",o.y+=this._textLeading):e=i}o.y<=o.h&&(this._doFill&&this.drawingContext.fillText(e,o.x,o.y),this._doStroke&&this.drawingContext.strokeText(e,o.x,o.y))}},o.prototype.textFont=function(t){this._setProperty("_textFont",t)},o}({},core,canvas),src_app=function(t,e){"use strict";var r=e,o=function(){window.PHANTOMJS||(window.setup&&"function"==typeof window.setup||window.draw&&"function"==typeof window.draw)&&new r};return"complete"===document.readyState?o():window.addEventListener("load",o,!1),window.p5=r,r}({},core,p5Color,p5Element,p5Graphics,p5Image,p5Vector,p5TableRow,p5Table,colorcreating_reading,colorsetting,constants,dataarray_functions,datastring_functions,environment,imageimage,imageloading_displaying,imagepixels,inputfiles,inputkeyboard,inputmouse,inputtime_date,inputtouch,mathmath,mathcalculation,mathrandom,mathnoise,mathtrigonometry,outputfiles,outputimage,outputtext_area,renderingrendering,shape2d_primitives,shapeattributes,shapecurves,shapevertex,structure,transform,typographyattributes,typographyloading_displaying); \ No newline at end of file diff --git a/lib/p5.sound.js b/lib/p5.sound.js index a9f2b373..7f72f950 100644 --- a/lib/p5.sound.js +++ b/lib/p5.sound.js @@ -1,4 +1,4 @@ -/*! p5.sound.js v0.14 2014-08-20 */ +/*! p5.sound.js v0.14 2014-08-22 */ /** * p5.sound extends p5 with Web Audio functionality including audio input, @@ -28,7 +28,7 @@ * p5.Convolver: Extends * p5.Reverb to simulate the sound of real * physical spaces through convolution.
- * p5.SoundRecorder: Record sound for playback + * p5.SoundRecorder: Record sound for playback * / save the .wav file. *

* p5.sound is on GitHub. @@ -1892,14 +1892,8 @@ signal = function () { p5.Signal = function (value) { // scales the constant output to desired output this.scalar = ac.createGain(); - this.scalar.gain.maxValue = 10000; - this.scalar.gain.minValue = -10000; this.input = ac.createGain(); - this.input.gain.maxValue = 10000; - this.input.gain.minValue = -10000; this.output = ac.createGain(); - this.output.gain.maxValue = 10000; - this.output.gain.minValue = -10000; // the ratio of this value to the control signal this._syncRatio = 1; // connect the constant output to the scalar @@ -2103,8 +2097,6 @@ signal = function () { p5.SignalMult = function (num, _input) { var mult = new p5.Signal(); mult.output = mult.input; - mult.input.gain.maxValue = 10000; - mult.input.gain.minValue = -10000; mult.setValue = function (value) { if (typeof value === 'number') { this.input.gain.value = value; @@ -4755,7 +4747,7 @@ soundRecorder = function () { * * else if (state === 2) { * soundFile.play(); // play the result! - * saveSound(soundFile, 'mySound.wav'); + * save(soundFile, 'mySound.wav'); * state++; * } * } @@ -4971,9 +4963,64 @@ soundRecorder = function () { } } }(sndcore, master); +var metro; +metro = function () { + 'use strict'; + var p5sound = master; + var ac = p5sound.audiocontext; + var upTick = false; + var tatums = 4; + // lowest possible division of a beat + // Oscillator + Script Processor to keep time. + // inspired by Tone.js library's Transport (MIT license, Yotam Mann) + // https://github.com/TONEnoTONE/Tone.js/blob/master/Tone/core/Transport.js + p5.Metro = function () { + this.metroTicks = 0; + /** + * watch this.oscillator for timing ticks + */ + this._jsNode = p5sound.audiocontext.createScriptProcessor(this.bufferSize, 1, 1); + this._jsNode.onaudioprocess = this._processBuffer.bind(this); + this._jsNode.connect(p5.soundOut._silentNode); + this.oscillator = ac.createOscillator(); + this.oscillator.type = 'square'; + this.oscillator.connect(this._jsNode); + this.oscillator.start(); + this.oscillator.frequency.value = 1; + this.lastTick = 0; + }; + p5.Metro.prototype._processBuffer = function (event) { + var now = ac.currentTime; + var incomingBuffer = event.inputBuffer.getChannelData(0); + var bufferSize = this._jsNode.bufferSize; + for (var i = 0; i < bufferSize; i++) { + var sample = incomingBuffer[i]; + if (sample > 0 && !upTick) { + upTick = true; + this._processTick(now + i / ac.sampleRate); + } else if (sample < 0 && upTick) { + upTick = false; + } + } + }; + p5.Metro.prototype._processTick = function (tickTime) { + this.metroTicks += 1; + console.log('interval: ' + (tickTime - this.lastTick)); + this.lastTick = tickTime; + }; + p5.Metro.prototype.setBPM = function (bpm, rampTime) { + // var tatumFreq = this.secondsToFrequency(this.notationToSeconds(tatum.toString() + "n", bpm, transportTimeSignature)); + var freq = bpm / 60 / 2 * tatums; + var ramp = rampTime || 0; + this.oscillator.frequency.linearRampToValueAtTime(freq, ramp); + }; + p5.Metro.prototype.getBPM = function (tempo) { + return this.oscillator.frequency.value * 60 * 2; + }; +}(master); var src_app; src_app = function () { 'use strict'; var p5SOUND = sndcore; return p5SOUND; -}(sndcore, master, helpers, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, delay, reverb, looper, soundRecorder); +}(sndcore, master, helpers, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, delay, reverb, looper, soundRecorder, metro); diff --git a/lib/p5.sound.min.js b/lib/p5.sound.min.js index 68ab46a4..4626035f 100644 --- a/lib/p5.sound.min.js +++ b/lib/p5.sound.min.js @@ -1,4 +1,4 @@ -/*! p5.sound.min.js v0.14 2014-08-20 */ +/*! p5.sound.min.js v0.14 2014-08-22 */ -var sndcore;sndcore=function(){"use strict";window.AudioContext=window.AudioContext||window.webkitAudioContext;var t=new window.AudioContext;p5.prototype.getAudioContext=function(){return t},"function"!=typeof t.createGain&&(window.audioContext.createGain=window.audioContext.createGainNode),"function"!=typeof t.createDelay&&(window.audioContext.createDelay=window.audioContext.createDelayNode),"function"!=typeof window.AudioBufferSourceNode.prototype.start&&(window.AudioBufferSourceNode.prototype.start=window.AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof window.AudioBufferSourceNode.prototype.stop&&(window.AudioBufferSourceNode.prototype.stop=window.AudioBufferSourceNode.prototype.noteOff),"function"!=typeof window.OscillatorNode.prototype.start&&(window.OscillatorNode.prototype.start=window.OscillatorNode.prototype.noteOn),"function"!=typeof window.OscillatorNode.prototype.stop&&(window.OscillatorNode.prototype.stop=window.OscillatorNode.prototype.noteOff),window.AudioContext.prototype.hasOwnProperty("createScriptProcessor")||(window.AudioContext.prototype.createScriptProcessor=window.AudioContext.prototype.createJavaScriptNode),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var e=document.createElement("audio");p5.prototype.isSupported=function(){return!!e.canPlayType};var i=function(){return!!e.canPlayType&&e.canPlayType('audio/ogg; codecs="vorbis"')},o=function(){return!!e.canPlayType&&e.canPlayType("audio/mpeg;")},n=function(){return!!e.canPlayType&&e.canPlayType('audio/wav; codecs="1"')},s=function(){return!!e.canPlayType&&(e.canPlayType("audio/x-m4a;")||e.canPlayType("audio/aac;"))},r=function(){return!!e.canPlayType&&e.canPlayType("audio/x-aiff;")};p5.prototype.isFileSupported=function(t){switch(t.toLowerCase()){case"mp3":return o();case"wav":return n();case"ogg":return i();case"mp4":return s();case"aiff":return r();default:return!1}};var a=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1;a&&window.addEventListener("touchstart",function(){var e=t.createBuffer(1,1,22050),i=t.createBufferSource();i.buffer=e,i.connect(t.destination),i.start(0)},!1)}();var master;master=function(){"use strict";var t=function(){var t=p5.prototype.getAudioContext();this.input=t.createGain(),this.output=t.createGain(),this.limiter=t.createDynamicsCompressor(),this.limiter.threshold.value=0,this.limiter.ratio.value=100,this.audiocontext=t,this.output.disconnect(this.audiocontext.destination),this.inputSources=[],this.input.connect(this.limiter),this.limiter.connect(this.output),this.meter=t.createGain(),this.output.connect(this.meter),this.output.connect(this.audiocontext.destination),this.soundArray=[],this.extensions=[]},e=new t;return p5.soundOut=e,p5.soundOut._silentNode=e.audiocontext.createGain(),p5.soundOut._silentNode.gain.value=0,p5.soundOut._silentNode.connect(e.audiocontext.destination),e}(sndcore);var helpers;helpers=function(){"use strict";var t=master;p5.prototype.masterVolume=function(e){t.output.gain.value=e},p5.prototype.sampleRate=function(){return t.audiocontext.sampleRate},p5.prototype.getMasterVolume=function(){return t.output.gain.value},p5.prototype.freqToMidi=function(t){var e=Math.log(t/440)/Math.log(2),i=Math.round(12*e)+57;return i},p5.prototype.midiToFreq=function(t){return 440*Math.pow(2,(t-69)/12)},p5.prototype.soundFormats=function(){t.extensions=[];for(var e=0;e-1))throw arguments[e]+" is not a valid sound format!";t.extensions.push(arguments[e])}},p5.prototype.disposeSound=function(){for(var e=0;e-1){var n=p5.prototype.isFileSupported(o);if(n)i=i;else for(var s=i.split("."),r=s[s.length-1],a=0;a-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var i=new p5.SoundFile(t,e);return i},p5.SoundFile.prototype.load=function(t){var e=new XMLHttpRequest;e.open("GET",this.url,!0),e.responseType="arraybuffer";var i=this;e.onload=function(){var o=p5.prototype.getAudioContext();o.decodeAudioData(e.response,function(e){i.buffer=e,t&&t(i)})},e.send()},p5.SoundFile.prototype.isLoaded=function(){return this.buffer?!0:!1},p5.SoundFile.prototype.play=function(e,i,o,n){var s=t.audiocontext.currentTime;if(!this.buffer)throw"not ready to play file, buffer has yet to load. Try preload()";if("restart"===this.mode&&this.buffer&&this.source){var s=t.audiocontext.currentTime;this.source.stop(s)}if(o){if(!(o>=0&&o=0&&n<=this.buffer.duration))throw"end time out of range";this.endTime=n}else this.endTime=this.buffer.duration;if(this.source=t.audiocontext.createBufferSource(),this.source.buffer=this.buffer,this.source.loop=this.looping,this.source.loop===!0&&(this.source.loopStart=this.startTime,this.source.loopEnd=this.endTime),this.source.onended=function(){},this.source.gain)this.source.gain.value=i||1,this.source.connect(this.output);else{this.source.gain=t.audiocontext.createGain(),this.source.connect(this.source.gain);var r=i||1;this.source.gain.gain.setValueAtTime(r,t.audiocontext.currentTime),this.source.gain.connect(this.output)}this.source.playbackRate.cancelScheduledValues(s),e=e||Math.abs(this.playbackRate),this.source.playbackRate.setValueAtTime(e,s),this.paused&&(this.wasUnpaused=!0),this.paused&&this.wasUnpaused?this.source.start(0,this.pauseTime,this.endTime):(this.wasUnpaused=!1,this.pauseTime=0,this.source.start(0,this.startTime,this.endTime)),this.startSeconds=s,this.playing=!0,this.paused=!1,this.sources.push(this.source)},p5.SoundFile.prototype.playMode=function(e){var i=e.toLowerCase();if("restart"===i&&this.buffer&&this.source)for(var o=0;o90&&(i=180-i);var o=Math.sin(e*(Math.PI/180)),n=Math.sin(i*(Math.PI/180));this.panner.setPosition(o,0,n)},p5.SoundFile.prototype.getPan=function(){return this.panPosition},p5.SoundFile.prototype.rate=function(e){if(this.playbackRate!==e||!this.source||this.source.playbackRate.value!==e){this.playbackRate=e;var i=e;if(0===this.playbackRate&&this.playing&&this.pause(),this.playbackRate<0&&!this.reversed){{var o=this.currentTime();this.source.playbackRate.value}this.pause(),this.reverseBuffer(),i=Math.abs(e);var n=(o-this.duration())/i;this.pauseTime=n,this.play()}else this.playbackRate>0&&this.reversed&&this.reverseBuffer();if(this.source){var s=t.audiocontext.currentTime;this.source.playbackRate.cancelScheduledValues(s),this.source.playbackRate.linearRampToValueAtTime(Math.abs(i),s)}}},p5.SoundFile.prototype.getPlaybackRate=function(){return this.playbackRate},p5.SoundFile.prototype.duration=function(){return this.buffer?this.buffer.duration:0},p5.SoundFile.prototype.currentTime=function(){var e;if(this.isPlaying()){var i=t.audiocontext.currentTime-this.startSeconds+this.startTime+this.pauseTime;return e=i*this.playbackRate%(this.duration()*this.playbackRate)}return this.paused?this.pauseTime:this.startTime},p5.SoundFile.prototype.jump=function(e,i){if(0>e||e>this.buffer.duration)throw"jump time out of range";if(e>i||i>this.buffer.duration)throw"end time out of range";if(this.startTime=e||0,this.endTime=i?i:this.buffer.duration,this.isPlaying()){var o=t.audiocontext.currentTime;this.stop(o),this.play(e,this.endTime)}},p5.SoundFile.prototype.channels=function(){return this.buffer.numberOfChannels},p5.SoundFile.prototype.sampleRate=function(){return this.buffer.sampleRate},p5.SoundFile.prototype.frames=function(){return this.buffer.length},p5.SoundFile.prototype.getPeaks=function(t){if(!this.buffer)throw"Cannot load peaks yet, buffer is not loaded";if(t||(t=5*window.width),this.buffer){for(var e=this.buffer,i=e.length/t,o=~~(i/10)||1,n=e.numberOfChannels,s=new Float32Array(t),r=0;n>r;r++)for(var a=e.getChannelData(r),u=0;t>u;u++){for(var c=~~(u*i),p=~~(c+i),l=0,h=c;p>h;h+=o){var d=a[h];d>l?l=d:-d>l&&(l=d)}(0===r||l>s[u])&&(s[u]=l)}return s}},p5.SoundFile.prototype.reverseBuffer=function(){if(!this.buffer)throw"SoundFile is not done loading";Array.prototype.reverse.call(this.buffer.getChannelData(0)),Array.prototype.reverse.call(this.buffer.getChannelData(1)),this.reversed=!this.reversed},p5.SoundFile.prototype._onEnded=function(e){e.onended=function(e){var i=t.audiocontext.currentTime;e.stop(i)}},p5.SoundFile.prototype.add=function(){},p5.SoundFile.prototype.dispose=function(){if(this.buffer&&this.source)for(var e=0;er;r++)e=i[r],this.normalize?(n+=Math.max(Math.min(e/this.volMax,1),-1),s+=Math.max(Math.min(e/this.volMax,1),-1)*Math.max(Math.min(e/this.volMax,1),-1)):(n+=e,s+=e*e);var a=Math.sqrt(s/o);this.volume=Math.max(a,this.volume*this.smoothing),this.volMax=Math.max(this.volume,this.volMax),this.volNorm=Math.max(Math.min(this.volume/this.volMax,1),0)},p5.Amplitude.prototype.getLevel=function(){return this.normalize?this.volNorm:this.volume},p5.Amplitude.prototype.toggleNormalize=function(t){this.normalize="boolean"==typeof t?t:!this.normalize},p5.Amplitude.prototype.smooth=function(t){t>=0&&1>t?this.smoothing=t:console.log("Error: smoothing must be between 0 and 1")}}(master);var fft;fft=function(){"use strict";var t=master;p5.FFT=function(e,i){var o=e||.8;0===e&&(o=e);var n=2*i||2048;this.analyser=t.audiocontext.createAnalyser(),t.output.connect(this.analyser),this.analyser.smoothingTimeConstant=o,this.analyser.fftSize=n,this.freqDomain=new Uint8Array(this.analyser.frequencyBinCount),this.timeDomain=new Uint8Array(this.analyser.frequencyBinCount),this.bass=[20,140],this.lowMid=[140,400],this.mid=[400,2600],this.highMid=[2600,5200],this.treble=[5200,14e3]},p5.FFT.prototype.setInput=function(t,e){e&&(this.analyser.fftSize=2*e),t.output?t.output.connect(this.analyser):t.connect(this.analyser)},p5.FFT.prototype.waveform=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteTimeDomainData(this.timeDomain);var e=Array.apply([],this.timeDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.analyze=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteFrequencyData(this.freqDomain);var e=Array.apply([],this.freqDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.getEnergy=function(e,i){var o=t.audiocontext.sampleRate/2;if("bass"===e?(e=this.bass[0],i=this.bass[1]):"lowMid"===e?(e=this.lowMid[0],i=this.lowMid[1]):"mid"===e?(e=this.mid[0],i=this.mid[1]):"highMid"===e?(e=this.highMid[0],i=this.highMid[1]):"treble"===e&&(e=this.treble[0],i=this.treble[1]),"number"!=typeof e)throw"invalid input for getEnergy()";if(i){if(e&&i){if(e>i){var n=i;i=e,e=n}for(var s=Math.round(e/o*this.freqDomain.length),r=Math.round(i/o*this.freqDomain.length),a=0,u=0,c=s;r>=c;c++)a+=this.freqDomain[c],u+=1;var p=a/u;return p}throw"invalid input for getEnergy()"}var l=Math.round(e/o*this.freqDomain.length);return this.freqDomain[l]},p5.FFT.prototype.getFreq=function(t,e){console.log("getFreq() is deprecated. Please use getEnergy() instead.");var i=this.getEnergy(t,e);return i},p5.FFT.prototype.smooth=function(t){this.analyser.smoothingTimeConstant=t}}(master);var signal;signal=function(){"use strict";var t=master,e=t.audiocontext,i=e.createOscillator(),o=e.createWaveShaper();!function(){for(var t=8,e=new Float32Array(t),i=0;t>i;i++)e[i]=1;o.curve=e}(),i.connect(o),i.start(0),i.connect(p5.soundOut._silentNode),p5.Signal=function(i){this.scalar=e.createGain(),this.scalar.gain.maxValue=1e4,this.scalar.gain.minValue=-1e4,this.input=e.createGain(),this.input.gain.maxValue=1e4,this.input.gain.minValue=-1e4,this.output=e.createGain(),this.output.gain.maxValue=1e4,this.output.gain.minValue=-1e4,this._syncRatio=1,o.connect(this.scalar),this.scalar.connect(this.output),this.input.connect(this.output);var i=i||0;this.setValue(i),t.soundArray.push(this)},p5.Signal.prototype.getValue=function(){return this.scalar.gain.value},p5.Signal.prototype.setValue=function(t){"number"==typeof t?(0===this._syncRatio?t=0:t*=this._syncRatio,this.scalar.gain.setValueAtTime(t,e.currentTime)):t.connect(this._syncRatio)},p5.Signal.prototype.setValueAtTime=function(t,e){t*=this._syncRatio;var i=e||0;this.scalar.gain.setValueAtTime(t,i)},p5.Signal.prototype.setCurrentValueNow=function(){var t=e.currentTime,i=this.getValue();return this.cancelScheduledValues(t),this.scalar.gain.linearRampToValueAtTime(i,t),i},p5.Signal.prototype.cancelScheduledValues=function(t){var e=t||0;this.scalar.gain.cancelScheduledValues(e)},p5.Signal.prototype.linearRampToValueAtTime=function(t,e){var i=e||0;t*=this._syncRatio,this.scalar.gain.linearRampToValueAtTime(t,i)},p5.Signal.prototype.exponentialRampToValueAtTime=function(t,e){var i=e||0;t*=this._syncRatio,this.scalar.gain.exponentialRampToValueAtTime(t,i)},p5.Signal.prototype.fade=function(t,i){var o=i||0,n=e.currentTime+o+.01;t*=this._syncRatio,this.scalar.gain.linearRampToValueAtTime(t,n)},p5.Signal.prototype.dispose=function(){this.output&&this.output.disconnect(),this.scalar&&this.scalar.disconnect(),this.output=null,this.scalar=null},p5.Signal.prototype.setInput=function(t){t.connect(this.input)},p5.Signal.prototype.connect=function(t){t instanceof p5.Signal?t.setValue(0):t instanceof AudioParam&&t.setValueAtTime(0,e.currentTime),this.output.connect(t)},p5.Signal.prototype.disconnect=function(){this.output.disconnect(node)},p5.Signal.prototype.add=function(t){var e=new p5.SignalAdd(t);return e.setInput(this),e},p5.Signal.prototype.mult=function(t){var e=new p5.SignalMult(t);return e.setInput(this),e},p5.Signal.prototype.scale=function(t,e,i,o){var n=new p5.SignalScale(t,e,i,o);return n.setInput(this),n},p5.SignalAdd=function(t){var e=new p5.Signal(t);return e},p5.SignalMult=function(t,e){var i=new p5.Signal;return i.output=i.input,i.input.gain.maxValue=1e4,i.input.gain.minValue=-1e4,i.setValue=function(t){"number"==typeof t?this.input.gain.value=t:t.connect(this.input.gain)},t&&i.setValue(t),e&&i.setInput(e),i},p5.SignalScale=function(t,e,i,o){var n=new p5.Signal;return n.scalar.disconnect(),n.input.disconnect(),2==arguments.length&&(i=t,o=e,t=-1,e=1),n._plusInput=new p5.SignalAdd(-t),n._scale=new p5.SignalMult((o-i)/(e-t)),n._plusOutput=new p5.SignalAdd(i),n._plusInput.setInput(n.input),n._scale.setInput(n._plusInput.output),n._plusOutput.setInput(n._scale.output),n._plusOutput.connect(n.output),n}}(master);var oscillator;oscillator=function(){"use strict";var t=master;p5.Oscillator=function(e,i){if("string"==typeof e){var o=i;i=e,e=o}if("number"==typeof i){var o=i;i=e,e=o}this.started=!1,t=t,this.oscillator=t.audiocontext.createOscillator(),this.f=e||440,this.oscillator.frequency.setValueAtTime(this.f,t.audiocontext.currentTime),this.oscillator.type=i||"sine";this.oscillator;this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this._freqMods=[],this.output.gain.value=0,this.output.gain.setValueAtTime(0,t.audiocontext.currentTime),this.panPosition=0,this.panner=t.audiocontext.createPanner(),this.panner.panningModel="equalpower",this.panner.distanceModel="linear",this.panner.setPosition(0,0,0),this.oscillator.connect(this.output),this.output.connect(this.panner),this.panner.connect(t.input),this.connection=t.input,t.soundArray.push(this)},p5.Oscillator.prototype.start=function(e,i){if(this.started){var o=t.audiocontext.currentTime;this.stop(o)}if(!this.started){var n=i||this.f,s=this.oscillator.type;this.oscillator=t.audiocontext.createOscillator(),this.oscillator.frequency.exponentialRampToValueAtTime(Math.abs(n),t.audiocontext.currentTime),this.oscillator.type=s,this.oscillator.connect(this.output),e=e||0,this.oscillator.start(e+t.audiocontext.currentTime),this.freqNode=this.oscillator.frequency;for(var r in this._freqMods)this._freqMods[r].connect(this.oscillator.frequency);this.started=!0}},p5.Oscillator.prototype.stop=function(e){if(this.started){var i=e||0,o=t.audiocontext.currentTime;this.oscillator.stop(i+o),this.started=!1}},p5.Oscillator.prototype.amp=function(e,i,o){if("number"==typeof e){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o),this.output.gain.linearRampToValueAtTime(e,n+o+i)}else{if(!e)return this.output.gain;e.connect(this.output.gain)}},p5.Oscillator.prototype.fade=p5.Oscillator.prototype.amp,p5.Oscillator.prototype.getAmp=function(){return this.output.gain.value},p5.Oscillator.prototype.freq=function(e,i,o){if("number"==typeof e){this.f=e;var n=t.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),e>0?this.oscillator.frequency.exponentialRampToValueAtTime(e,o+i+n):this.oscillator.frequency.linearRampToValueAtTime(e,o+i+n)}else{if(!e)return this.oscillator.frequency;e.connect(this.oscillator.frequency),this._freqMods.push(e)}},p5.Oscillator.prototype.getFreq=function(){return this.oscillator.frequency.value},p5.Oscillator.prototype.setType=function(t){this.oscillator.type=t},p5.Oscillator.prototype.getType=function(){return this.oscillator.type},p5.Oscillator.prototype.connect=function(e){e?e.hasOwnProperty("input")?(this.panner.connect(e.input),this.connection=e.input):(this.panner.connect(e),this.connection=e):this.panner.connect(t.input)},p5.Oscillator.prototype.disconnect=function(t){this.panner.disconnect(t),this.oscMods=[]},p5.Oscillator.prototype.pan=function(t){t||(t=0),this.panPosition=t,t=90*t;var e=parseInt(t),i=e+90;i>90&&(i=180-i);var o=Math.sin(e*(Math.PI/180)),n=Math.sin(i*(Math.PI/180));this.panner.setPosition(o,0,n)},p5.Oscillator.prototype.getPan=function(){return this.panPosition},p5.Oscillator.prototype.dispose=function(){if(this.oscillator){var e=t.audiocontext.currentTime;this.stop(e),this.disconnect(),this.oscillator.disconnect(),this.panner=null,this.oscillator=null}this.osc2&&this.osc2.dispose()},p5.Oscillator.prototype.phase=function(e){this.dNode||(this.dNode=t.audiocontext.createDelay(),this.output.disconnect(),this.output.connect(this.dNode),this.dNode.connect(this.panner));var i=t.audiocontext.currentTime;this.dNode.delayTime.linearRampToValueAtTime(p5.prototype.map(e,0,1,0,1/this.oscillator.frequency.value),i)},p5.Oscillator.prototype.add=function(t){var e=new p5.SignalAdd(t);return e.setInput(this),e},p5.Oscillator.prototype.mult=function(t){var e=new p5.SignalMult(t);return e.setInput(this),e},p5.Oscillator.prototype.scale=function(t,e,i,o){var n=new p5.SignalScale(t,e,i,o);return n.setInput(this),n},p5.SinOsc=function(t){p5.Oscillator.call(this,t,"sine")},p5.SinOsc.prototype=Object.create(p5.Oscillator.prototype),p5.TriOsc=function(t){p5.Oscillator.call(this,t,"triangle")},p5.TriOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SawOsc=function(t){p5.Oscillator.call(this,t,"sawtooth")},p5.SawOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SqrOsc=function(t){p5.Oscillator.call(this,t,"square")},p5.SqrOsc.prototype=Object.create(p5.Oscillator.prototype)}(master);var env;env=function(){"use strict";var t=master;p5.Env=function(e,i,o,n,s,r,a,u){this.aTime=e,this.aLevel=i,this.dTime=o||0,this.dLevel=n||0,this.sTime=s||0,this.sLevel=r||0,this.rTime=a||0,this.rLevel=u||0,this.output=t.audiocontext.createGain(),this.control=new p5.Signal,this.control.connect(this.output),this.timeoutID=null,this.connection=null},p5.Env.prototype.set=function(t,e,i,o,n,s,r,a){this.aTime=t,this.aLevel=e,this.dTime=i||0,this.dLevel=o||0,this.sTime=n||0,this.sLevel=s||0,this.rTime=r||0,this.rLevel=a||0},p5.Env.prototype.setInput=function(t){this.connect(t)},p5.Env.prototype.ctrl=function(t){this.connect(t)},p5.Env.prototype.play=function(e,i){function o(){this.connection&&this.connection.hasOwnProperty("oscillator")&&e.started&&(this.connection.amp(0),this.connection.stop())}var n=t.audiocontext.currentTime,s=i||0,r=n+s+.001;"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID);this.control.getValue();if(this.control.cancelScheduledValues(r),this.control.fade(0,r),e&&this.connection!==e&&this.connect(e),this.connection instanceof p5.Oscillator&&(this.connection.stop(),this.connection.amp(0)),this.control.linearRampToValueAtTime(this.aLevel,r+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,r+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,r+this.aTime+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,r+this.aTime+this.dTime+this.sTime+this.rTime),this.connection&&this.connection.hasOwnProperty("oscillator")){var a=1e3*(r+this.aTime+this.dTime+this.sTime+this.rTime);this.timeoutID=window.setTimeout(o,a),this.connection.start()}},p5.Env.prototype.triggerAttack=function(e,i){var o=t.audiocontext.currentTime,n=i||0,s=o+n;this.lastAttack=s,"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID);var r=this.control.getValue();this.control.cancelScheduledValues(s),this.control.fade(r),e&&this.connection!==e&&this.connect(e),this.connection&&this.connection instanceof p5.Oscillator&&this.connection.started&&this.connection.stop(),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,s+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,s+this.aTime+this.dTime+this.sTime),this.connection&&this.connection instanceof p5.Oscillator&&(this.connection.started||this.connection.start())},p5.Env.prototype.triggerRelease=function(e,i){function o(){this.connection.hasOwnProperty("oscillator")&&e.started&&(this.connection.amp(0),this.connection.stop())}var n,s=t.audiocontext.currentTime+.001,r=i||0,a=s+r;e&&this.connection!==e&&this.connect(e);var u=this.control.getValue();if(this.control.cancelScheduledValues(a),this.control.fade(u),s-this.lastAttack>this.aTime+this.dTime+this.sTime+this.rTime?(this.control.linearRampToValueAtTime(this.sLevel,a+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+this.sTime+this.rTime),n=a+this.rTime):s-this.lastAttack>this.aTime+this.dTime?(this.control.linearRampToValueAtTime(this.dLevel,a+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,a+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+this.dTime+this.sTime+this.rTime),n=a+this.sTime+this.rTime):s-this.lastAttack>this.aTime&&(this.control.linearRampToValueAtTime(this.dLevel,a+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,a+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+this.dTime+this.sTime+this.rTime),n=a+this.dTime+this.sTime+this.rTime),this.connection.hasOwnProperty("oscillator")){var c=1e3*n;this.timeoutID=window.setTimeout(o,c)}},p5.Env.prototype.connect=function(e){this.disconnect(),this.connection=e,(e instanceof p5.Oscillator||e instanceof p5.SoundFile||e instanceof p5.AudioIn||e instanceof p5.Reverb||e instanceof p5.Noise||e instanceof p5.Filter||e instanceof p5.Delay)&&(e=e.output.gain),e instanceof AudioParam&&e.setValueAtTime(0,t.audiocontext.currentTime),e instanceof p5.Signal&&e.setValue(0),this.output.connect(e)},p5.Env.prototype.disconnect=function(){this.output.disconnect()},p5.Env.prototype.add=function(t){var e=new p5.SignalAdd(t);return e.setInput(this.control),e},p5.Env.prototype.mult=function(t){var e=new p5.SignalMult(t);return e.setInput(this.control),e},p5.Env.prototype.scale=function(t,e,i,o){var n=new p5.SignalScale(t,e,i,o);return n.setInput(this.control),n}}(master);var pulse;pulse=function(){"use strict";function t(){for(var t=e.audiocontext,i=t.createBuffer(1,2048,t.sampleRate),o=i.getChannelData(0),n=0;2048>n;n++)o[n]=1;var s=t.createBufferSource();return s.buffer=i,s.loop=!0,s}var e=master;p5.Pulse=function(i,o){p5.Oscillator.call(this,i,"sawtooth"),this.w=o||0,this.osc2=new p5.SawOsc(i),this.dNode=e.audiocontext.createDelay(),this.dcOffset=t(),this.dcGain=e.audiocontext.createGain(),this.dcOffset.connect(this.dcGain),this.dcGain.connect(this.output),this.f=i||440;var n=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=n,this.dcGain.gain.value=1.7*(.5-this.w),this.osc2.disconnect(),this.osc2.output.gain.minValue=-10,this.osc2.output.gain.maxValue=10,this.osc2.panner.disconnect(),this.osc2.amp(-1),this.osc2.output.connect(this.dNode),this.dNode.connect(this.output),this.output.gain.value=1,this.output.connect(this.panner)},p5.Pulse.prototype=Object.create(p5.Oscillator.prototype),p5.Pulse.prototype.width=function(t){if("number"==typeof t){if(1>=t&&t>=0){this.w=t;var e=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=e}this.dcGain.gain.value=1.7*(.5-this.w)}else{t.connect(this.dNode.delayTime);var i=new p5.SignalAdd(-.5);i.setInput(t),i=i.mult(-1),i=i.mult(1.7),i.connect(this.dcGain.gain)}},p5.Pulse.prototype.start=function(i,o){var n=e.audiocontext.currentTime,s=o||0;if(!this.started){var r=i||this.f,a=this.oscillator.type;this.oscillator=e.audiocontext.createOscillator(),this.oscillator.frequency.setValueAtTime(r,n),this.oscillator.type=a,this.oscillator.connect(this.output),this.oscillator.start(s+n),this.osc2.oscillator=e.audiocontext.createOscillator(),this.osc2.oscillator.frequency.setValueAtTime(r,s+n),this.osc2.oscillator.type=a,this.osc2.oscillator.connect(this.osc2.output),this.osc2.start(s+n),this.freqNode=[this.oscillator.frequency,this.osc2.oscillator.frequency],this.dcOffset=t(),this.dcOffset.connect(this.dcGain),this.dcOffset.start(s+n),void 0!==this.mods&&void 0!==this.mods.frequency&&(this.mods.frequency.connect(this.freqNode[0]),this.mods.frequency.connect(this.freqNode[1])),this.started=!0,this.osc2.started=!0}},p5.Pulse.prototype.stop=function(t){if(this.started){var i=t||0,o=e.audiocontext.currentTime;this.oscillator.stop(i+o),this.osc2.oscillator.stop(i+o),this.dcOffset.stop(i+o),this.started=!1,this.osc2.started=!1}},p5.Pulse.prototype.freq=function(t,i,o){if("number"==typeof t){this.f=t;var n=e.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),this.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.osc2.oscillator.frequency.cancelScheduledValues(n),this.osc2.oscillator.frequency.setValueAtTime(s,n+o),this.osc2.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.freqMod&&(this.freqMod.output.disconnect(),this.freqMod=null) -}else t.output&&(t.output.disconnect(),t.output.connect(this.oscillator.frequency),t.output.connect(this.osc2.oscillator.frequency),this.freqMod=t)}}(master,oscillator);var noise;noise=function(){"use strict";var t=master;p5.Noise=function(){this.started=!1,this.buffer=e,this.output=t.audiocontext.createGain(),this.output.gain.value=.5,this.panPosition=0,this.panner=t.audiocontext.createPanner(),this.panner.panningModel="equalpower",this.panner.distanceModel="linear",this.panner.setPosition(0,0,0),this.output.connect(this.panner),this.panner.connect(t.input),t.soundArray.push(this)};var e=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0;e>n;n++)o[n]=2*Math.random()-1;return i}(),i=function(){var e,i,o,n,s,r,a,u=2*t.audiocontext.sampleRate,c=t.audiocontext.createBuffer(1,u,t.audiocontext.sampleRate),p=c.getChannelData(0);e=i=o=n=s=r=a=0;for(var l=0;u>l;l++){var h=2*Math.random()-1;e=.99886*e+.0555179*h,i=.99332*i+.0750759*h,o=.969*o+.153852*h,n=.8665*n+.3104856*h,s=.55*s+.5329522*h,r=-.7616*r-.016898*h,p[l]=e+i+o+n+s+r+a+.5362*h,p[l]*=.11,a=.115926*h}return c}(),o=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0,s=0;e>s;s++){var r=2*Math.random()-1;o[s]=(n+.02*r)/1.02,n=o[s],o[s]*=3.5}return i}();p5.Noise.prototype.ampMod=function(e){e.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.connect(e.output.gain)},p5.Noise.prototype.setType=function(n){switch(n){case"white":this.buffer=e;break;case"pink":this.buffer=i;break;case"brown":this.buffer=o;break;default:this.buffer=e}if(this.started){var s=t.audiocontext.currentTime;this.stop(s),this.start(s+.01)}},p5.Noise.prototype.start=function(){this.started&&this.stop(),this.noise=t.audiocontext.createBufferSource(),this.noise.buffer=this.buffer,this.noise.loop=!0,this.noise.connect(this.output);var e=t.audiocontext.currentTime;this.noise.start(e),this.started=!0},p5.Noise.prototype.stop=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.stop(e),this.started=!1)},p5.Noise.prototype.pan=function(t){this.panPosition=t,t=90*t;var e=parseInt(t),i=e+90;i>90&&(i=180-i);var o=Math.sin(e*(Math.PI/180)),n=Math.sin(i*(Math.PI/180));this.panner.setPosition(o,0,n)},p5.Noise.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Noise.prototype.connect=function(e){this.panner.connect(e?e.hasOwnProperty("input")?e.input:e:t.input)},p5.Noise.prototype.disconnect=function(){this.output.disconnect(),this.panner.disconnect(),this.output.connect(this.panner)},p5.Noise.prototype.dispose=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.disconnect(),this.stop(e)),this.output&&this.output.disconnect(),this.panner&&this.panner.disconnect(),this.output=null,this.panner=null,this.buffer=null,this.noise=null}}(master);var audioin;audioin=function(){"use strict";var t=master;p5.AudioIn=function(){this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.stream=null,this.mediaStream=null,this.currentSource=0,this.enabled=!1,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),"undefined"==typeof window.MediaStreamTrack?window.alert("This browser does not support MediaStreamTrack"):"undefined"!=typeof window.MediaStreamTrack.getSources&&window.MediaStreamTrack.getSources(this._gotSources),t.soundArray.push(this)},p5.AudioIn.prototype.start=function(){var e=this;if(t.inputSources[e.currentSource]){var i=t.inputSources[e.currentSource].id,o={audio:{optional:[{sourceId:i}]}};navigator.getUserMedia(o,this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})}else window.navigator.getUserMedia({audio:!0},this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})},p5.AudioIn.prototype.stop=function(){this.stream&&this.stream.stop()},p5.AudioIn.prototype.connect=function(e){this.output.connect(e?e.hasOwnProperty("input")?e.input:e.hasOwnProperty("analyser")?e.analyser:e:t.input)},p5.AudioIn.prototype.disconnect=function(t){this.output.disconnect(t),this.output.connect(this.amplitude.input)},p5.AudioIn.prototype.getLevel=function(t){return t&&(this.amplitude.smoothing=t),this.amplitude.getLevel()},p5.AudioIn.prototype._gotSources=function(e){for(var i=0;i!==e.length;i++){var o=e[i];"audio"===o.kind&&t.inputSources.push(o)}},p5.AudioIn.prototype.amp=function(e,i){if(i){var o=i||0,n=this.output.gain.value;this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(n,t.audiocontext.currentTime),this.output.gain.linearRampToValueAtTime(e,o+t.audiocontext.currentTime)}else this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(e,t.audiocontext.currentTime)},p5.AudioIn.prototype.listSources=function(){return console.log("input sources: "),console.log(t.inputSources),t.inputSources.length>0?t.inputSources:"This browser does not support MediaStreamTrack.getSources()"},p5.AudioIn.prototype.setSource=function(e){var i=this;t.inputSources.length>0&&e=1)throw new Error("Feedback value will force a positive feedback loop.");if(s>=this._maxDelay)throw new Error("Delay Time exceeds maximum delay time of "+this._maxDelay+" second.");t.connect(this.input),this.leftDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this.rightDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this._leftGain.gain.setValueAtTime(n,this.ac.currentTime),this._rightGain.gain.setValueAtTime(n,this.ac.currentTime),o&&(this._leftFilter.freq(o),this._rightFilter.freq(o))},p5.Delay.prototype.delayTime=function(t){"number"!=typeof t?(t.connect(this.leftDelay.delayTime),t.connect(this.rightDelay.delayTime)):(this.leftDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.rightDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.leftDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime),this.rightDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime))},p5.Delay.prototype.feedback=function(t){if("number"!=typeof t)t.connect(this._leftGain.gain),t.connect(this._rightGain.gain);else{if(t>=1)throw new Error("Feedback value will force a positive feedback loop.");this._leftGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime),this._rightGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime)}},p5.Delay.prototype.filter=function(t,e){this._leftFilter.set(t,e),this._rightFilter.set(t,e)},p5.Delay.prototype.setType=function(t){switch(1===t&&(t="pingPong"),this._split.disconnect(),this._leftFilter.disconnect(),this._rightFilter.disconnect(),this._split.connect(this.leftDelay,0),this._split.connect(this.rightDelay,1),t){case"pingPong":this._rightFilter.setType(this._leftFilter.biquad.type),this._leftFilter.output.connect(this._merge,0,0),this._rightFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.rightDelay),this._rightFilter.output.connect(this.leftDelay);break;default:this._leftFilter.output.connect(this._merge,0,0),this._leftFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.leftDelay),this._leftFilter.output.connect(this.rightDelay)}},p5.Delay.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Delay.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e)},p5.Delay.prototype.disconnect=function(){this.output.disconnect()}}(master,filter);var reverb;reverb=function(){"use strict";var t=master;p5.Reverb=function(){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse(),this.connect(),t.soundArray.push(this)},p5.Reverb.prototype.process=function(t,e,i,o){t.connect(this.input);var n=!1;e&&(this._seconds=e,n=!0),i&&(this._decay=i),o&&(this._reverse=o),n&&this._buildImpulse()},p5.Reverb.prototype.set=function(t,e,i){var o=!1;t&&(this._seconds=t,o=!0),e&&(this._decay=e),i&&(this._reverse=i),o&&this._buildImpulse()},p5.Reverb.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Reverb.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e.input?e.input:e)},p5.Reverb.prototype.disconnect=function(){this.output.disconnect()},p5.Reverb.prototype._buildImpulse=function(){var t,e,i=this.ac.sampleRate,o=i*this._seconds,n=this._decay,s=this.ac.createBuffer(2,o,i),r=s.getChannelData(0),a=s.getChannelData(1);for(e=0;o>e;e++)t=this.reverse?o-e:e,r[e]=(2*Math.random()-1)*Math.pow(1-t/o,n),a[e]=(2*Math.random()-1)*Math.pow(1-t/o,n);this.convolverNode.buffer=s},p5.Reverb.prototype.dispose=function(){this.convolverNode.buffer=null,this.convolverNode=null,"undefined"!=typeof this.output&&(this.output.disconnect(),this.output=null),"undefined"!=typeof this.panner&&(this.panner.disconnect(),this.panner=null)},p5.Convolver=function(e,i){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),e?(this.impulses=[],this._loadBuffer(e,i)):(this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse()),this.connect(),t.soundArray.push(this)},p5.Convolver.prototype=Object.create(p5.Reverb.prototype),p5.prototype.registerPreloadMethod("createConvolver"),p5.prototype.createConvolver=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var i=new p5.Convolver(t,e);return i.impulses=[],i},p5.Convolver.prototype._loadBuffer=function(t,e){t=p5.prototype._checkFileFormats(t);var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var n=p5.prototype.getAudioContext();n.decodeAudioData(i.response,function(i){var n={},s=t.split("/");n.name=s[s.length-1],n.audioBuffer=i,o.impulses.push(n),o.convolverNode.buffer=n.audioBuffer,e&&e(n)})},i.send()},p5.Convolver.prototype.set=null,p5.Convolver.prototype.process=function(t){t.connect(this.input)},p5.Convolver.prototype.impulses=[],p5.Convolver.prototype.addImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this._loadBuffer(t,e)},p5.Convolver.prototype.resetImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this.impulses=[],this._loadBuffer(t,e)},p5.Convolver.prototype.toggleImpulse=function(t){if("number"==typeof t&&t=f.length?(p=0,d.onended()):(p=0,f[m].start())}var e,i,o,n=master,s=10,r=0,a=.1,u=0,c=[],p=0,l=120,h=function(){};p5.prototype.setBPM=function(t){l=t},p5.Part=function(t,i){this.length=t||16,e=4*i||.5,this.noteResolution=0,this.isPlaying=!1,this.parts=[],this.onended=function(){this.stop()}},p5.Part.prototype.start=function(){p=0,this.isPlaying=!0,o=this,"score"!==i&&(r=n.audiocontext.currentTime),g()},p5.Part.prototype.loop=function(){this.onended=function(){p=0},this.start()},p5.Part.prototype.noLoop=function(){this.onended=function(){this.stop()}},p5.Part.prototype.stop=function(){this.isPlaying=!1,p=0},p5.Part.prototype.pause=function(){this.isPlaying=!1},p5.Part.prototype.addPhrase=function(t,e,i){this.parts.push({name:t,callback:e,array:i})},p5.Part.prototype.removePhrase=function(t){for(var e in this.parts)this.parts[e].name===t&&this.parts.split(e,1)},p5.Part.prototype.getPhrase=function(t){for(var e in this.parts)if(this.parts[e]===t)return this.parts[e]},p5.Part.prototype.onStep=function(t){h=t};var d,f,m,y=function(){var t=60/l;r+=e*t,p++,p>=o.length&&(p=0,o.onended())},v=function(t,e){if(c.push({note:t,time:e}),h(),o)for(var i=0;is;)o[s++]=t[n],o[s++]=e[n],n++;return o}function e(t,e,i){for(var o=i.length,n=0;o>n;n++)t.setUint8(e+n,i.charCodeAt(n))}var i=master,o=i.audiocontext;p5.SoundRecorder=function(){this.input=o.createGain(),this.output=o.createGain(),this.recording=!1,this.bufferSize=1024,this._channels=2,this._clear(),this._jsNode=o.createScriptProcessor(this.bufferSize,this._channels,2),this._jsNode.onaudioprocess=this._audioprocess.bind(this),this._callback=function(){},this._jsNode.connect(p5.soundOut._silentNode),this.setInput(),i.soundArray.push(this)},p5.SoundRecorder.prototype.setInput=function(t){this.input.disconnect(),this.input=null,this.input=o.createGain(),this.input.connect(this._jsNode),this.input.connect(this.output),t?t.connect(this.input):p5.soundOut.output.connect(this.input)},p5.SoundRecorder.prototype.record=function(t,e,i){this.recording=!0,e&&(this.sampleLimit=Math.round(e*o.sampleRate)),t&&i?this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer),i()}:t&&(this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer)})},p5.SoundRecorder.prototype.stop=function(){this.recording=!1,this._callback(),this._clear()},p5.SoundRecorder.prototype._clear=function(){this._leftBuffers=[],this._rightBuffers=[],this.recordedSamples=0,this.sampleLimit=null},p5.SoundRecorder.prototype._audioprocess=function(t){if(this.recording!==!1&&this.recording===!0)if(this.sampleLimit&&this.recordedSamples>=this.sampleLimit)this.stop();else{var e=t.inputBuffer.getChannelData(0),i=t.inputBuffer.getChannelData(1);this._leftBuffers.push(new Float32Array(e)),this._rightBuffers.push(new Float32Array(i)),this.recordedSamples+=this.bufferSize}},p5.SoundRecorder.prototype._getBuffer=function(){var t=[];return t.push(this._mergeBuffers(this._leftBuffers)),t.push(this._mergeBuffers(this._rightBuffers)),t},p5.SoundRecorder.prototype._mergeBuffers=function(t){for(var e=new Float32Array(this.recordedSamples),i=0,o=t.length,n=0;o>n;n++){var s=t[n];e.set(s,i),i+=s.length}return e},p5.SoundRecorder.prototype.dispose=function(){this._clear(),this._callback=function(){},this.input&&this.input.disconnect(),this.input=null,this._jsNode=null},p5.prototype.saveSound=function(i,o){var n=i.buffer.getChannelData(0),s=i.buffer.getChannelData(1),r=t(n,s),a=new ArrayBuffer(44+2*r.length),u=new DataView(a);e(u,0,"RIFF"),u.setUint32(4,44+2*r.length,!0),e(u,8,"WAVE"),e(u,12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,2,!0),u.setUint32(24,44100,!0),u.setUint32(28,176400,!0),u.setUint16(32,4,!0),u.setUint16(34,16,!0),e(u,36,"data"),u.setUint32(40,2*r.length,!0);for(var c=r.length,p=44,l=1,h=0;c>h;h++)u.setInt16(p,32767*r[h]*l,!0),p+=2;p5.prototype.writeFile([u],o,"wav")}}(sndcore,master);var src_app;src_app=function(){"use strict";var t=sndcore;return t}(sndcore,master,helpers,soundfile,amplitude,fft,signal,oscillator,env,pulse,noise,audioin,filter,delay,reverb,looper,soundRecorder); \ No newline at end of file +var sndcore;sndcore=function(){"use strict";window.AudioContext=window.AudioContext||window.webkitAudioContext;var t=new window.AudioContext;p5.prototype.getAudioContext=function(){return t},"function"!=typeof t.createGain&&(window.audioContext.createGain=window.audioContext.createGainNode),"function"!=typeof t.createDelay&&(window.audioContext.createDelay=window.audioContext.createDelayNode),"function"!=typeof window.AudioBufferSourceNode.prototype.start&&(window.AudioBufferSourceNode.prototype.start=window.AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof window.AudioBufferSourceNode.prototype.stop&&(window.AudioBufferSourceNode.prototype.stop=window.AudioBufferSourceNode.prototype.noteOff),"function"!=typeof window.OscillatorNode.prototype.start&&(window.OscillatorNode.prototype.start=window.OscillatorNode.prototype.noteOn),"function"!=typeof window.OscillatorNode.prototype.stop&&(window.OscillatorNode.prototype.stop=window.OscillatorNode.prototype.noteOff),window.AudioContext.prototype.hasOwnProperty("createScriptProcessor")||(window.AudioContext.prototype.createScriptProcessor=window.AudioContext.prototype.createJavaScriptNode),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var e=document.createElement("audio");p5.prototype.isSupported=function(){return!!e.canPlayType};var i=function(){return!!e.canPlayType&&e.canPlayType('audio/ogg; codecs="vorbis"')},o=function(){return!!e.canPlayType&&e.canPlayType("audio/mpeg;")},n=function(){return!!e.canPlayType&&e.canPlayType('audio/wav; codecs="1"')},s=function(){return!!e.canPlayType&&(e.canPlayType("audio/x-m4a;")||e.canPlayType("audio/aac;"))},r=function(){return!!e.canPlayType&&e.canPlayType("audio/x-aiff;")};p5.prototype.isFileSupported=function(t){switch(t.toLowerCase()){case"mp3":return o();case"wav":return n();case"ogg":return i();case"mp4":return s();case"aiff":return r();default:return!1}};var a=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1;a&&window.addEventListener("touchstart",function(){var e=t.createBuffer(1,1,22050),i=t.createBufferSource();i.buffer=e,i.connect(t.destination),i.start(0)},!1)}();var master;master=function(){"use strict";var t=function(){var t=p5.prototype.getAudioContext();this.input=t.createGain(),this.output=t.createGain(),this.limiter=t.createDynamicsCompressor(),this.limiter.threshold.value=0,this.limiter.ratio.value=100,this.audiocontext=t,this.output.disconnect(this.audiocontext.destination),this.inputSources=[],this.input.connect(this.limiter),this.limiter.connect(this.output),this.meter=t.createGain(),this.output.connect(this.meter),this.output.connect(this.audiocontext.destination),this.soundArray=[],this.extensions=[]},e=new t;return p5.soundOut=e,p5.soundOut._silentNode=e.audiocontext.createGain(),p5.soundOut._silentNode.gain.value=0,p5.soundOut._silentNode.connect(e.audiocontext.destination),e}(sndcore);var helpers;helpers=function(){"use strict";var t=master;p5.prototype.masterVolume=function(e){t.output.gain.value=e},p5.prototype.sampleRate=function(){return t.audiocontext.sampleRate},p5.prototype.getMasterVolume=function(){return t.output.gain.value},p5.prototype.freqToMidi=function(t){var e=Math.log(t/440)/Math.log(2),i=Math.round(12*e)+57;return i},p5.prototype.midiToFreq=function(t){return 440*Math.pow(2,(t-69)/12)},p5.prototype.soundFormats=function(){t.extensions=[];for(var e=0;e-1))throw arguments[e]+" is not a valid sound format!";t.extensions.push(arguments[e])}},p5.prototype.disposeSound=function(){for(var e=0;e-1){var n=p5.prototype.isFileSupported(o);if(n)i=i;else for(var s=i.split("."),r=s[s.length-1],a=0;a-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var i=new p5.SoundFile(t,e);return i},p5.SoundFile.prototype.load=function(t){var e=new XMLHttpRequest;e.open("GET",this.url,!0),e.responseType="arraybuffer";var i=this;e.onload=function(){var o=p5.prototype.getAudioContext();o.decodeAudioData(e.response,function(e){i.buffer=e,t&&t(i)})},e.send()},p5.SoundFile.prototype.isLoaded=function(){return this.buffer?!0:!1},p5.SoundFile.prototype.play=function(e,i,o,n){var s=t.audiocontext.currentTime;if(!this.buffer)throw"not ready to play file, buffer has yet to load. Try preload()";if("restart"===this.mode&&this.buffer&&this.source){var s=t.audiocontext.currentTime;this.source.stop(s)}if(o){if(!(o>=0&&o=0&&n<=this.buffer.duration))throw"end time out of range";this.endTime=n}else this.endTime=this.buffer.duration;if(this.source=t.audiocontext.createBufferSource(),this.source.buffer=this.buffer,this.source.loop=this.looping,this.source.loop===!0&&(this.source.loopStart=this.startTime,this.source.loopEnd=this.endTime),this.source.onended=function(){},this.source.gain)this.source.gain.value=i||1,this.source.connect(this.output);else{this.source.gain=t.audiocontext.createGain(),this.source.connect(this.source.gain);var r=i||1;this.source.gain.gain.setValueAtTime(r,t.audiocontext.currentTime),this.source.gain.connect(this.output)}this.source.playbackRate.cancelScheduledValues(s),e=e||Math.abs(this.playbackRate),this.source.playbackRate.setValueAtTime(e,s),this.paused&&(this.wasUnpaused=!0),this.paused&&this.wasUnpaused?this.source.start(0,this.pauseTime,this.endTime):(this.wasUnpaused=!1,this.pauseTime=0,this.source.start(0,this.startTime,this.endTime)),this.startSeconds=s,this.playing=!0,this.paused=!1,this.sources.push(this.source)},p5.SoundFile.prototype.playMode=function(e){var i=e.toLowerCase();if("restart"===i&&this.buffer&&this.source)for(var o=0;o90&&(i=180-i);var o=Math.sin(e*(Math.PI/180)),n=Math.sin(i*(Math.PI/180));this.panner.setPosition(o,0,n)},p5.SoundFile.prototype.getPan=function(){return this.panPosition},p5.SoundFile.prototype.rate=function(e){if(this.playbackRate!==e||!this.source||this.source.playbackRate.value!==e){this.playbackRate=e;var i=e;if(0===this.playbackRate&&this.playing&&this.pause(),this.playbackRate<0&&!this.reversed){{var o=this.currentTime();this.source.playbackRate.value}this.pause(),this.reverseBuffer(),i=Math.abs(e);var n=(o-this.duration())/i;this.pauseTime=n,this.play()}else this.playbackRate>0&&this.reversed&&this.reverseBuffer();if(this.source){var s=t.audiocontext.currentTime;this.source.playbackRate.cancelScheduledValues(s),this.source.playbackRate.linearRampToValueAtTime(Math.abs(i),s)}}},p5.SoundFile.prototype.getPlaybackRate=function(){return this.playbackRate},p5.SoundFile.prototype.duration=function(){return this.buffer?this.buffer.duration:0},p5.SoundFile.prototype.currentTime=function(){var e;if(this.isPlaying()){var i=t.audiocontext.currentTime-this.startSeconds+this.startTime+this.pauseTime;return e=i*this.playbackRate%(this.duration()*this.playbackRate)}return this.paused?this.pauseTime:this.startTime},p5.SoundFile.prototype.jump=function(e,i){if(0>e||e>this.buffer.duration)throw"jump time out of range";if(e>i||i>this.buffer.duration)throw"end time out of range";if(this.startTime=e||0,this.endTime=i?i:this.buffer.duration,this.isPlaying()){var o=t.audiocontext.currentTime;this.stop(o),this.play(e,this.endTime)}},p5.SoundFile.prototype.channels=function(){return this.buffer.numberOfChannels},p5.SoundFile.prototype.sampleRate=function(){return this.buffer.sampleRate},p5.SoundFile.prototype.frames=function(){return this.buffer.length},p5.SoundFile.prototype.getPeaks=function(t){if(!this.buffer)throw"Cannot load peaks yet, buffer is not loaded";if(t||(t=5*window.width),this.buffer){for(var e=this.buffer,i=e.length/t,o=~~(i/10)||1,n=e.numberOfChannels,s=new Float32Array(t),r=0;n>r;r++)for(var a=e.getChannelData(r),u=0;t>u;u++){for(var c=~~(u*i),p=~~(c+i),l=0,h=c;p>h;h+=o){var d=a[h];d>l?l=d:-d>l&&(l=d)}(0===r||l>s[u])&&(s[u]=l)}return s}},p5.SoundFile.prototype.reverseBuffer=function(){if(!this.buffer)throw"SoundFile is not done loading";Array.prototype.reverse.call(this.buffer.getChannelData(0)),Array.prototype.reverse.call(this.buffer.getChannelData(1)),this.reversed=!this.reversed},p5.SoundFile.prototype._onEnded=function(e){e.onended=function(e){var i=t.audiocontext.currentTime;e.stop(i)}},p5.SoundFile.prototype.add=function(){},p5.SoundFile.prototype.dispose=function(){if(this.buffer&&this.source)for(var e=0;er;r++)e=i[r],this.normalize?(n+=Math.max(Math.min(e/this.volMax,1),-1),s+=Math.max(Math.min(e/this.volMax,1),-1)*Math.max(Math.min(e/this.volMax,1),-1)):(n+=e,s+=e*e);var a=Math.sqrt(s/o);this.volume=Math.max(a,this.volume*this.smoothing),this.volMax=Math.max(this.volume,this.volMax),this.volNorm=Math.max(Math.min(this.volume/this.volMax,1),0)},p5.Amplitude.prototype.getLevel=function(){return this.normalize?this.volNorm:this.volume},p5.Amplitude.prototype.toggleNormalize=function(t){this.normalize="boolean"==typeof t?t:!this.normalize},p5.Amplitude.prototype.smooth=function(t){t>=0&&1>t?this.smoothing=t:console.log("Error: smoothing must be between 0 and 1")}}(master);var fft;fft=function(){"use strict";var t=master;p5.FFT=function(e,i){var o=e||.8;0===e&&(o=e);var n=2*i||2048;this.analyser=t.audiocontext.createAnalyser(),t.output.connect(this.analyser),this.analyser.smoothingTimeConstant=o,this.analyser.fftSize=n,this.freqDomain=new Uint8Array(this.analyser.frequencyBinCount),this.timeDomain=new Uint8Array(this.analyser.frequencyBinCount),this.bass=[20,140],this.lowMid=[140,400],this.mid=[400,2600],this.highMid=[2600,5200],this.treble=[5200,14e3]},p5.FFT.prototype.setInput=function(t,e){e&&(this.analyser.fftSize=2*e),t.output?t.output.connect(this.analyser):t.connect(this.analyser)},p5.FFT.prototype.waveform=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteTimeDomainData(this.timeDomain);var e=Array.apply([],this.timeDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.analyze=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteFrequencyData(this.freqDomain);var e=Array.apply([],this.freqDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.getEnergy=function(e,i){var o=t.audiocontext.sampleRate/2;if("bass"===e?(e=this.bass[0],i=this.bass[1]):"lowMid"===e?(e=this.lowMid[0],i=this.lowMid[1]):"mid"===e?(e=this.mid[0],i=this.mid[1]):"highMid"===e?(e=this.highMid[0],i=this.highMid[1]):"treble"===e&&(e=this.treble[0],i=this.treble[1]),"number"!=typeof e)throw"invalid input for getEnergy()";if(i){if(e&&i){if(e>i){var n=i;i=e,e=n}for(var s=Math.round(e/o*this.freqDomain.length),r=Math.round(i/o*this.freqDomain.length),a=0,u=0,c=s;r>=c;c++)a+=this.freqDomain[c],u+=1;var p=a/u;return p}throw"invalid input for getEnergy()"}var l=Math.round(e/o*this.freqDomain.length);return this.freqDomain[l]},p5.FFT.prototype.getFreq=function(t,e){console.log("getFreq() is deprecated. Please use getEnergy() instead.");var i=this.getEnergy(t,e);return i},p5.FFT.prototype.smooth=function(t){this.analyser.smoothingTimeConstant=t}}(master);var signal;signal=function(){"use strict";var t=master,e=t.audiocontext,i=e.createOscillator(),o=e.createWaveShaper();!function(){for(var t=8,e=new Float32Array(t),i=0;t>i;i++)e[i]=1;o.curve=e}(),i.connect(o),i.start(0),i.connect(p5.soundOut._silentNode),p5.Signal=function(i){this.scalar=e.createGain(),this.input=e.createGain(),this.output=e.createGain(),this._syncRatio=1,o.connect(this.scalar),this.scalar.connect(this.output),this.input.connect(this.output);var i=i||0;this.setValue(i),t.soundArray.push(this)},p5.Signal.prototype.getValue=function(){return this.scalar.gain.value},p5.Signal.prototype.setValue=function(t){"number"==typeof t?(0===this._syncRatio?t=0:t*=this._syncRatio,this.scalar.gain.setValueAtTime(t,e.currentTime)):t.connect(this._syncRatio)},p5.Signal.prototype.setValueAtTime=function(t,e){t*=this._syncRatio;var i=e||0;this.scalar.gain.setValueAtTime(t,i)},p5.Signal.prototype.setCurrentValueNow=function(){var t=e.currentTime,i=this.getValue();return this.cancelScheduledValues(t),this.scalar.gain.linearRampToValueAtTime(i,t),i},p5.Signal.prototype.cancelScheduledValues=function(t){var e=t||0;this.scalar.gain.cancelScheduledValues(e)},p5.Signal.prototype.linearRampToValueAtTime=function(t,e){var i=e||0;t*=this._syncRatio,this.scalar.gain.linearRampToValueAtTime(t,i)},p5.Signal.prototype.exponentialRampToValueAtTime=function(t,e){var i=e||0;t*=this._syncRatio,this.scalar.gain.exponentialRampToValueAtTime(t,i)},p5.Signal.prototype.fade=function(t,i){var o=i||0,n=e.currentTime+o+.01;t*=this._syncRatio,this.scalar.gain.linearRampToValueAtTime(t,n)},p5.Signal.prototype.dispose=function(){this.output&&this.output.disconnect(),this.scalar&&this.scalar.disconnect(),this.output=null,this.scalar=null},p5.Signal.prototype.setInput=function(t){t.connect(this.input)},p5.Signal.prototype.connect=function(t){t instanceof p5.Signal?t.setValue(0):t instanceof AudioParam&&t.setValueAtTime(0,e.currentTime),this.output.connect(t)},p5.Signal.prototype.disconnect=function(){this.output.disconnect(node)},p5.Signal.prototype.add=function(t){var e=new p5.SignalAdd(t);return e.setInput(this),e},p5.Signal.prototype.mult=function(t){var e=new p5.SignalMult(t);return e.setInput(this),e},p5.Signal.prototype.scale=function(t,e,i,o){var n=new p5.SignalScale(t,e,i,o);return n.setInput(this),n},p5.SignalAdd=function(t){var e=new p5.Signal(t);return e},p5.SignalMult=function(t,e){var i=new p5.Signal;return i.output=i.input,i.setValue=function(t){"number"==typeof t?this.input.gain.value=t:t.connect(this.input.gain)},t&&i.setValue(t),e&&i.setInput(e),i},p5.SignalScale=function(t,e,i,o){var n=new p5.Signal;return n.scalar.disconnect(),n.input.disconnect(),2==arguments.length&&(i=t,o=e,t=-1,e=1),n._plusInput=new p5.SignalAdd(-t),n._scale=new p5.SignalMult((o-i)/(e-t)),n._plusOutput=new p5.SignalAdd(i),n._plusInput.setInput(n.input),n._scale.setInput(n._plusInput.output),n._plusOutput.setInput(n._scale.output),n._plusOutput.connect(n.output),n}}(master);var oscillator;oscillator=function(){"use strict";var t=master;p5.Oscillator=function(e,i){if("string"==typeof e){var o=i;i=e,e=o}if("number"==typeof i){var o=i;i=e,e=o}this.started=!1,t=t,this.oscillator=t.audiocontext.createOscillator(),this.f=e||440,this.oscillator.frequency.setValueAtTime(this.f,t.audiocontext.currentTime),this.oscillator.type=i||"sine";this.oscillator;this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this._freqMods=[],this.output.gain.value=0,this.output.gain.setValueAtTime(0,t.audiocontext.currentTime),this.panPosition=0,this.panner=t.audiocontext.createPanner(),this.panner.panningModel="equalpower",this.panner.distanceModel="linear",this.panner.setPosition(0,0,0),this.oscillator.connect(this.output),this.output.connect(this.panner),this.panner.connect(t.input),this.connection=t.input,t.soundArray.push(this)},p5.Oscillator.prototype.start=function(e,i){if(this.started){var o=t.audiocontext.currentTime;this.stop(o)}if(!this.started){var n=i||this.f,s=this.oscillator.type;this.oscillator=t.audiocontext.createOscillator(),this.oscillator.frequency.exponentialRampToValueAtTime(Math.abs(n),t.audiocontext.currentTime),this.oscillator.type=s,this.oscillator.connect(this.output),e=e||0,this.oscillator.start(e+t.audiocontext.currentTime),this.freqNode=this.oscillator.frequency;for(var r in this._freqMods)this._freqMods[r].connect(this.oscillator.frequency);this.started=!0}},p5.Oscillator.prototype.stop=function(e){if(this.started){var i=e||0,o=t.audiocontext.currentTime;this.oscillator.stop(i+o),this.started=!1}},p5.Oscillator.prototype.amp=function(e,i,o){if("number"==typeof e){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o),this.output.gain.linearRampToValueAtTime(e,n+o+i)}else{if(!e)return this.output.gain;e.connect(this.output.gain)}},p5.Oscillator.prototype.fade=p5.Oscillator.prototype.amp,p5.Oscillator.prototype.getAmp=function(){return this.output.gain.value},p5.Oscillator.prototype.freq=function(e,i,o){if("number"==typeof e){this.f=e;var n=t.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),e>0?this.oscillator.frequency.exponentialRampToValueAtTime(e,o+i+n):this.oscillator.frequency.linearRampToValueAtTime(e,o+i+n)}else{if(!e)return this.oscillator.frequency;e.connect(this.oscillator.frequency),this._freqMods.push(e)}},p5.Oscillator.prototype.getFreq=function(){return this.oscillator.frequency.value},p5.Oscillator.prototype.setType=function(t){this.oscillator.type=t},p5.Oscillator.prototype.getType=function(){return this.oscillator.type},p5.Oscillator.prototype.connect=function(e){e?e.hasOwnProperty("input")?(this.panner.connect(e.input),this.connection=e.input):(this.panner.connect(e),this.connection=e):this.panner.connect(t.input)},p5.Oscillator.prototype.disconnect=function(t){this.panner.disconnect(t),this.oscMods=[]},p5.Oscillator.prototype.pan=function(t){t||(t=0),this.panPosition=t,t=90*t;var e=parseInt(t),i=e+90;i>90&&(i=180-i);var o=Math.sin(e*(Math.PI/180)),n=Math.sin(i*(Math.PI/180));this.panner.setPosition(o,0,n)},p5.Oscillator.prototype.getPan=function(){return this.panPosition},p5.Oscillator.prototype.dispose=function(){if(this.oscillator){var e=t.audiocontext.currentTime;this.stop(e),this.disconnect(),this.oscillator.disconnect(),this.panner=null,this.oscillator=null}this.osc2&&this.osc2.dispose()},p5.Oscillator.prototype.phase=function(e){this.dNode||(this.dNode=t.audiocontext.createDelay(),this.output.disconnect(),this.output.connect(this.dNode),this.dNode.connect(this.panner));var i=t.audiocontext.currentTime;this.dNode.delayTime.linearRampToValueAtTime(p5.prototype.map(e,0,1,0,1/this.oscillator.frequency.value),i)},p5.Oscillator.prototype.add=function(t){var e=new p5.SignalAdd(t);return e.setInput(this),e},p5.Oscillator.prototype.mult=function(t){var e=new p5.SignalMult(t);return e.setInput(this),e},p5.Oscillator.prototype.scale=function(t,e,i,o){var n=new p5.SignalScale(t,e,i,o);return n.setInput(this),n},p5.SinOsc=function(t){p5.Oscillator.call(this,t,"sine")},p5.SinOsc.prototype=Object.create(p5.Oscillator.prototype),p5.TriOsc=function(t){p5.Oscillator.call(this,t,"triangle")},p5.TriOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SawOsc=function(t){p5.Oscillator.call(this,t,"sawtooth")},p5.SawOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SqrOsc=function(t){p5.Oscillator.call(this,t,"square")},p5.SqrOsc.prototype=Object.create(p5.Oscillator.prototype)}(master);var env;env=function(){"use strict";var t=master;p5.Env=function(e,i,o,n,s,r,a,u){this.aTime=e,this.aLevel=i,this.dTime=o||0,this.dLevel=n||0,this.sTime=s||0,this.sLevel=r||0,this.rTime=a||0,this.rLevel=u||0,this.output=t.audiocontext.createGain(),this.control=new p5.Signal,this.control.connect(this.output),this.timeoutID=null,this.connection=null},p5.Env.prototype.set=function(t,e,i,o,n,s,r,a){this.aTime=t,this.aLevel=e,this.dTime=i||0,this.dLevel=o||0,this.sTime=n||0,this.sLevel=s||0,this.rTime=r||0,this.rLevel=a||0},p5.Env.prototype.setInput=function(t){this.connect(t)},p5.Env.prototype.ctrl=function(t){this.connect(t)},p5.Env.prototype.play=function(e,i){function o(){this.connection&&this.connection.hasOwnProperty("oscillator")&&e.started&&(this.connection.amp(0),this.connection.stop())}var n=t.audiocontext.currentTime,s=i||0,r=n+s+.001;"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID);this.control.getValue();if(this.control.cancelScheduledValues(r),this.control.fade(0,r),e&&this.connection!==e&&this.connect(e),this.connection instanceof p5.Oscillator&&(this.connection.stop(),this.connection.amp(0)),this.control.linearRampToValueAtTime(this.aLevel,r+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,r+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,r+this.aTime+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,r+this.aTime+this.dTime+this.sTime+this.rTime),this.connection&&this.connection.hasOwnProperty("oscillator")){var a=1e3*(r+this.aTime+this.dTime+this.sTime+this.rTime);this.timeoutID=window.setTimeout(o,a),this.connection.start()}},p5.Env.prototype.triggerAttack=function(e,i){var o=t.audiocontext.currentTime,n=i||0,s=o+n;this.lastAttack=s,"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID);var r=this.control.getValue();this.control.cancelScheduledValues(s),this.control.fade(r),e&&this.connection!==e&&this.connect(e),this.connection&&this.connection instanceof p5.Oscillator&&this.connection.started&&this.connection.stop(),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,s+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,s+this.aTime+this.dTime+this.sTime),this.connection&&this.connection instanceof p5.Oscillator&&(this.connection.started||this.connection.start())},p5.Env.prototype.triggerRelease=function(e,i){function o(){this.connection.hasOwnProperty("oscillator")&&e.started&&(this.connection.amp(0),this.connection.stop())}var n,s=t.audiocontext.currentTime+.001,r=i||0,a=s+r;e&&this.connection!==e&&this.connect(e);var u=this.control.getValue();if(this.control.cancelScheduledValues(a),this.control.fade(u),s-this.lastAttack>this.aTime+this.dTime+this.sTime+this.rTime?(this.control.linearRampToValueAtTime(this.sLevel,a+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+this.sTime+this.rTime),n=a+this.rTime):s-this.lastAttack>this.aTime+this.dTime?(this.control.linearRampToValueAtTime(this.dLevel,a+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,a+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+this.dTime+this.sTime+this.rTime),n=a+this.sTime+this.rTime):s-this.lastAttack>this.aTime&&(this.control.linearRampToValueAtTime(this.dLevel,a+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,a+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+this.dTime+this.sTime+this.rTime),n=a+this.dTime+this.sTime+this.rTime),this.connection.hasOwnProperty("oscillator")){var c=1e3*n;this.timeoutID=window.setTimeout(o,c)}},p5.Env.prototype.connect=function(e){this.disconnect(),this.connection=e,(e instanceof p5.Oscillator||e instanceof p5.SoundFile||e instanceof p5.AudioIn||e instanceof p5.Reverb||e instanceof p5.Noise||e instanceof p5.Filter||e instanceof p5.Delay)&&(e=e.output.gain),e instanceof AudioParam&&e.setValueAtTime(0,t.audiocontext.currentTime),e instanceof p5.Signal&&e.setValue(0),this.output.connect(e)},p5.Env.prototype.disconnect=function(){this.output.disconnect()},p5.Env.prototype.add=function(t){var e=new p5.SignalAdd(t);return e.setInput(this.control),e},p5.Env.prototype.mult=function(t){var e=new p5.SignalMult(t);return e.setInput(this.control),e},p5.Env.prototype.scale=function(t,e,i,o){var n=new p5.SignalScale(t,e,i,o);return n.setInput(this.control),n}}(master);var pulse;pulse=function(){"use strict";function t(){for(var t=e.audiocontext,i=t.createBuffer(1,2048,t.sampleRate),o=i.getChannelData(0),n=0;2048>n;n++)o[n]=1;var s=t.createBufferSource();return s.buffer=i,s.loop=!0,s}var e=master;p5.Pulse=function(i,o){p5.Oscillator.call(this,i,"sawtooth"),this.w=o||0,this.osc2=new p5.SawOsc(i),this.dNode=e.audiocontext.createDelay(),this.dcOffset=t(),this.dcGain=e.audiocontext.createGain(),this.dcOffset.connect(this.dcGain),this.dcGain.connect(this.output),this.f=i||440;var n=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=n,this.dcGain.gain.value=1.7*(.5-this.w),this.osc2.disconnect(),this.osc2.output.gain.minValue=-10,this.osc2.output.gain.maxValue=10,this.osc2.panner.disconnect(),this.osc2.amp(-1),this.osc2.output.connect(this.dNode),this.dNode.connect(this.output),this.output.gain.value=1,this.output.connect(this.panner)},p5.Pulse.prototype=Object.create(p5.Oscillator.prototype),p5.Pulse.prototype.width=function(t){if("number"==typeof t){if(1>=t&&t>=0){this.w=t;var e=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=e}this.dcGain.gain.value=1.7*(.5-this.w)}else{t.connect(this.dNode.delayTime);var i=new p5.SignalAdd(-.5);i.setInput(t),i=i.mult(-1),i=i.mult(1.7),i.connect(this.dcGain.gain)}},p5.Pulse.prototype.start=function(i,o){var n=e.audiocontext.currentTime,s=o||0;if(!this.started){var r=i||this.f,a=this.oscillator.type;this.oscillator=e.audiocontext.createOscillator(),this.oscillator.frequency.setValueAtTime(r,n),this.oscillator.type=a,this.oscillator.connect(this.output),this.oscillator.start(s+n),this.osc2.oscillator=e.audiocontext.createOscillator(),this.osc2.oscillator.frequency.setValueAtTime(r,s+n),this.osc2.oscillator.type=a,this.osc2.oscillator.connect(this.osc2.output),this.osc2.start(s+n),this.freqNode=[this.oscillator.frequency,this.osc2.oscillator.frequency],this.dcOffset=t(),this.dcOffset.connect(this.dcGain),this.dcOffset.start(s+n),void 0!==this.mods&&void 0!==this.mods.frequency&&(this.mods.frequency.connect(this.freqNode[0]),this.mods.frequency.connect(this.freqNode[1])),this.started=!0,this.osc2.started=!0}},p5.Pulse.prototype.stop=function(t){if(this.started){var i=t||0,o=e.audiocontext.currentTime;this.oscillator.stop(i+o),this.osc2.oscillator.stop(i+o),this.dcOffset.stop(i+o),this.started=!1,this.osc2.started=!1}},p5.Pulse.prototype.freq=function(t,i,o){if("number"==typeof t){this.f=t;var n=e.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),this.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.osc2.oscillator.frequency.cancelScheduledValues(n),this.osc2.oscillator.frequency.setValueAtTime(s,n+o),this.osc2.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.freqMod&&(this.freqMod.output.disconnect(),this.freqMod=null) +}else t.output&&(t.output.disconnect(),t.output.connect(this.oscillator.frequency),t.output.connect(this.osc2.oscillator.frequency),this.freqMod=t)}}(master,oscillator);var noise;noise=function(){"use strict";var t=master;p5.Noise=function(){this.started=!1,this.buffer=e,this.output=t.audiocontext.createGain(),this.output.gain.value=.5,this.panPosition=0,this.panner=t.audiocontext.createPanner(),this.panner.panningModel="equalpower",this.panner.distanceModel="linear",this.panner.setPosition(0,0,0),this.output.connect(this.panner),this.panner.connect(t.input),t.soundArray.push(this)};var e=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0;e>n;n++)o[n]=2*Math.random()-1;return i}(),i=function(){var e,i,o,n,s,r,a,u=2*t.audiocontext.sampleRate,c=t.audiocontext.createBuffer(1,u,t.audiocontext.sampleRate),p=c.getChannelData(0);e=i=o=n=s=r=a=0;for(var l=0;u>l;l++){var h=2*Math.random()-1;e=.99886*e+.0555179*h,i=.99332*i+.0750759*h,o=.969*o+.153852*h,n=.8665*n+.3104856*h,s=.55*s+.5329522*h,r=-.7616*r-.016898*h,p[l]=e+i+o+n+s+r+a+.5362*h,p[l]*=.11,a=.115926*h}return c}(),o=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0,s=0;e>s;s++){var r=2*Math.random()-1;o[s]=(n+.02*r)/1.02,n=o[s],o[s]*=3.5}return i}();p5.Noise.prototype.ampMod=function(e){e.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.connect(e.output.gain)},p5.Noise.prototype.setType=function(n){switch(n){case"white":this.buffer=e;break;case"pink":this.buffer=i;break;case"brown":this.buffer=o;break;default:this.buffer=e}if(this.started){var s=t.audiocontext.currentTime;this.stop(s),this.start(s+.01)}},p5.Noise.prototype.start=function(){this.started&&this.stop(),this.noise=t.audiocontext.createBufferSource(),this.noise.buffer=this.buffer,this.noise.loop=!0,this.noise.connect(this.output);var e=t.audiocontext.currentTime;this.noise.start(e),this.started=!0},p5.Noise.prototype.stop=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.stop(e),this.started=!1)},p5.Noise.prototype.pan=function(t){this.panPosition=t,t=90*t;var e=parseInt(t),i=e+90;i>90&&(i=180-i);var o=Math.sin(e*(Math.PI/180)),n=Math.sin(i*(Math.PI/180));this.panner.setPosition(o,0,n)},p5.Noise.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Noise.prototype.connect=function(e){this.panner.connect(e?e.hasOwnProperty("input")?e.input:e:t.input)},p5.Noise.prototype.disconnect=function(){this.output.disconnect(),this.panner.disconnect(),this.output.connect(this.panner)},p5.Noise.prototype.dispose=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.disconnect(),this.stop(e)),this.output&&this.output.disconnect(),this.panner&&this.panner.disconnect(),this.output=null,this.panner=null,this.buffer=null,this.noise=null}}(master);var audioin;audioin=function(){"use strict";var t=master;p5.AudioIn=function(){this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.stream=null,this.mediaStream=null,this.currentSource=0,this.enabled=!1,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),"undefined"==typeof window.MediaStreamTrack?window.alert("This browser does not support MediaStreamTrack"):"undefined"!=typeof window.MediaStreamTrack.getSources&&window.MediaStreamTrack.getSources(this._gotSources),t.soundArray.push(this)},p5.AudioIn.prototype.start=function(){var e=this;if(t.inputSources[e.currentSource]){var i=t.inputSources[e.currentSource].id,o={audio:{optional:[{sourceId:i}]}};navigator.getUserMedia(o,this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})}else window.navigator.getUserMedia({audio:!0},this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})},p5.AudioIn.prototype.stop=function(){this.stream&&this.stream.stop()},p5.AudioIn.prototype.connect=function(e){this.output.connect(e?e.hasOwnProperty("input")?e.input:e.hasOwnProperty("analyser")?e.analyser:e:t.input)},p5.AudioIn.prototype.disconnect=function(t){this.output.disconnect(t),this.output.connect(this.amplitude.input)},p5.AudioIn.prototype.getLevel=function(t){return t&&(this.amplitude.smoothing=t),this.amplitude.getLevel()},p5.AudioIn.prototype._gotSources=function(e){for(var i=0;i!==e.length;i++){var o=e[i];"audio"===o.kind&&t.inputSources.push(o)}},p5.AudioIn.prototype.amp=function(e,i){if(i){var o=i||0,n=this.output.gain.value;this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(n,t.audiocontext.currentTime),this.output.gain.linearRampToValueAtTime(e,o+t.audiocontext.currentTime)}else this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(e,t.audiocontext.currentTime)},p5.AudioIn.prototype.listSources=function(){return console.log("input sources: "),console.log(t.inputSources),t.inputSources.length>0?t.inputSources:"This browser does not support MediaStreamTrack.getSources()"},p5.AudioIn.prototype.setSource=function(e){var i=this;t.inputSources.length>0&&e=1)throw new Error("Feedback value will force a positive feedback loop.");if(s>=this._maxDelay)throw new Error("Delay Time exceeds maximum delay time of "+this._maxDelay+" second.");t.connect(this.input),this.leftDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this.rightDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this._leftGain.gain.setValueAtTime(n,this.ac.currentTime),this._rightGain.gain.setValueAtTime(n,this.ac.currentTime),o&&(this._leftFilter.freq(o),this._rightFilter.freq(o))},p5.Delay.prototype.delayTime=function(t){"number"!=typeof t?(t.connect(this.leftDelay.delayTime),t.connect(this.rightDelay.delayTime)):(this.leftDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.rightDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.leftDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime),this.rightDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime))},p5.Delay.prototype.feedback=function(t){if("number"!=typeof t)t.connect(this._leftGain.gain),t.connect(this._rightGain.gain);else{if(t>=1)throw new Error("Feedback value will force a positive feedback loop.");this._leftGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime),this._rightGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime)}},p5.Delay.prototype.filter=function(t,e){this._leftFilter.set(t,e),this._rightFilter.set(t,e)},p5.Delay.prototype.setType=function(t){switch(1===t&&(t="pingPong"),this._split.disconnect(),this._leftFilter.disconnect(),this._rightFilter.disconnect(),this._split.connect(this.leftDelay,0),this._split.connect(this.rightDelay,1),t){case"pingPong":this._rightFilter.setType(this._leftFilter.biquad.type),this._leftFilter.output.connect(this._merge,0,0),this._rightFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.rightDelay),this._rightFilter.output.connect(this.leftDelay);break;default:this._leftFilter.output.connect(this._merge,0,0),this._leftFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.leftDelay),this._leftFilter.output.connect(this.rightDelay)}},p5.Delay.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Delay.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e)},p5.Delay.prototype.disconnect=function(){this.output.disconnect()}}(master,filter);var reverb;reverb=function(){"use strict";var t=master;p5.Reverb=function(){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse(),this.connect(),t.soundArray.push(this)},p5.Reverb.prototype.process=function(t,e,i,o){t.connect(this.input);var n=!1;e&&(this._seconds=e,n=!0),i&&(this._decay=i),o&&(this._reverse=o),n&&this._buildImpulse()},p5.Reverb.prototype.set=function(t,e,i){var o=!1;t&&(this._seconds=t,o=!0),e&&(this._decay=e),i&&(this._reverse=i),o&&this._buildImpulse()},p5.Reverb.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Reverb.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e.input?e.input:e)},p5.Reverb.prototype.disconnect=function(){this.output.disconnect()},p5.Reverb.prototype._buildImpulse=function(){var t,e,i=this.ac.sampleRate,o=i*this._seconds,n=this._decay,s=this.ac.createBuffer(2,o,i),r=s.getChannelData(0),a=s.getChannelData(1);for(e=0;o>e;e++)t=this.reverse?o-e:e,r[e]=(2*Math.random()-1)*Math.pow(1-t/o,n),a[e]=(2*Math.random()-1)*Math.pow(1-t/o,n);this.convolverNode.buffer=s},p5.Reverb.prototype.dispose=function(){this.convolverNode.buffer=null,this.convolverNode=null,"undefined"!=typeof this.output&&(this.output.disconnect(),this.output=null),"undefined"!=typeof this.panner&&(this.panner.disconnect(),this.panner=null)},p5.Convolver=function(e,i){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),e?(this.impulses=[],this._loadBuffer(e,i)):(this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse()),this.connect(),t.soundArray.push(this)},p5.Convolver.prototype=Object.create(p5.Reverb.prototype),p5.prototype.registerPreloadMethod("createConvolver"),p5.prototype.createConvolver=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var i=new p5.Convolver(t,e);return i.impulses=[],i},p5.Convolver.prototype._loadBuffer=function(t,e){t=p5.prototype._checkFileFormats(t);var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var n=p5.prototype.getAudioContext();n.decodeAudioData(i.response,function(i){var n={},s=t.split("/");n.name=s[s.length-1],n.audioBuffer=i,o.impulses.push(n),o.convolverNode.buffer=n.audioBuffer,e&&e(n)})},i.send()},p5.Convolver.prototype.set=null,p5.Convolver.prototype.process=function(t){t.connect(this.input)},p5.Convolver.prototype.impulses=[],p5.Convolver.prototype.addImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this._loadBuffer(t,e)},p5.Convolver.prototype.resetImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this.impulses=[],this._loadBuffer(t,e)},p5.Convolver.prototype.toggleImpulse=function(t){if("number"==typeof t&&t=f.length?(p=0,d.onended()):(p=0,f[m].start())}var e,i,o,n=master,s=10,r=0,a=.1,u=0,c=[],p=0,l=120,h=function(){};p5.prototype.setBPM=function(t){l=t},p5.Part=function(t,i){this.length=t||16,e=4*i||.5,this.noteResolution=0,this.isPlaying=!1,this.parts=[],this.onended=function(){this.stop()}},p5.Part.prototype.start=function(){p=0,this.isPlaying=!0,o=this,"score"!==i&&(r=n.audiocontext.currentTime),g()},p5.Part.prototype.loop=function(){this.onended=function(){p=0},this.start()},p5.Part.prototype.noLoop=function(){this.onended=function(){this.stop()}},p5.Part.prototype.stop=function(){this.isPlaying=!1,p=0},p5.Part.prototype.pause=function(){this.isPlaying=!1},p5.Part.prototype.addPhrase=function(t,e,i){this.parts.push({name:t,callback:e,array:i})},p5.Part.prototype.removePhrase=function(t){for(var e in this.parts)this.parts[e].name===t&&this.parts.split(e,1)},p5.Part.prototype.getPhrase=function(t){for(var e in this.parts)if(this.parts[e]===t)return this.parts[e]},p5.Part.prototype.onStep=function(t){h=t};var d,f,m,y=function(){var t=60/l;r+=e*t,p++,p>=o.length&&(p=0,o.onended())},v=function(t,e){if(c.push({note:t,time:e}),h(),o)for(var i=0;is;)o[s++]=t[n],o[s++]=e[n],n++;return o}function e(t,e,i){for(var o=i.length,n=0;o>n;n++)t.setUint8(e+n,i.charCodeAt(n))}var i=master,o=i.audiocontext;p5.SoundRecorder=function(){this.input=o.createGain(),this.output=o.createGain(),this.recording=!1,this.bufferSize=1024,this._channels=2,this._clear(),this._jsNode=o.createScriptProcessor(this.bufferSize,this._channels,2),this._jsNode.onaudioprocess=this._audioprocess.bind(this),this._callback=function(){},this._jsNode.connect(p5.soundOut._silentNode),this.setInput(),i.soundArray.push(this)},p5.SoundRecorder.prototype.setInput=function(t){this.input.disconnect(),this.input=null,this.input=o.createGain(),this.input.connect(this._jsNode),this.input.connect(this.output),t?t.connect(this.input):p5.soundOut.output.connect(this.input)},p5.SoundRecorder.prototype.record=function(t,e,i){this.recording=!0,e&&(this.sampleLimit=Math.round(e*o.sampleRate)),t&&i?this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer),i()}:t&&(this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer)})},p5.SoundRecorder.prototype.stop=function(){this.recording=!1,this._callback(),this._clear()},p5.SoundRecorder.prototype._clear=function(){this._leftBuffers=[],this._rightBuffers=[],this.recordedSamples=0,this.sampleLimit=null},p5.SoundRecorder.prototype._audioprocess=function(t){if(this.recording!==!1&&this.recording===!0)if(this.sampleLimit&&this.recordedSamples>=this.sampleLimit)this.stop();else{var e=t.inputBuffer.getChannelData(0),i=t.inputBuffer.getChannelData(1);this._leftBuffers.push(new Float32Array(e)),this._rightBuffers.push(new Float32Array(i)),this.recordedSamples+=this.bufferSize}},p5.SoundRecorder.prototype._getBuffer=function(){var t=[];return t.push(this._mergeBuffers(this._leftBuffers)),t.push(this._mergeBuffers(this._rightBuffers)),t},p5.SoundRecorder.prototype._mergeBuffers=function(t){for(var e=new Float32Array(this.recordedSamples),i=0,o=t.length,n=0;o>n;n++){var s=t[n];e.set(s,i),i+=s.length}return e},p5.SoundRecorder.prototype.dispose=function(){this._clear(),this._callback=function(){},this.input&&this.input.disconnect(),this.input=null,this._jsNode=null},p5.prototype.saveSound=function(i,o){var n=i.buffer.getChannelData(0),s=i.buffer.getChannelData(1),r=t(n,s),a=new ArrayBuffer(44+2*r.length),u=new DataView(a);e(u,0,"RIFF"),u.setUint32(4,44+2*r.length,!0),e(u,8,"WAVE"),e(u,12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,2,!0),u.setUint32(24,44100,!0),u.setUint32(28,176400,!0),u.setUint16(32,4,!0),u.setUint16(34,16,!0),e(u,36,"data"),u.setUint32(40,2*r.length,!0);for(var c=r.length,p=44,l=1,h=0;c>h;h++)u.setInt16(p,32767*r[h]*l,!0),p+=2;p5.prototype.writeFile([u],o,"wav")}}(sndcore,master);var metro;metro=function(){"use strict";var t=master,e=t.audiocontext,i=!1,o=4;p5.Metro=function(){this.metroTicks=0,this._jsNode=t.audiocontext.createScriptProcessor(this.bufferSize,1,1),this._jsNode.onaudioprocess=this._processBuffer.bind(this),this._jsNode.connect(p5.soundOut._silentNode),this.oscillator=e.createOscillator(),this.oscillator.type="square",this.oscillator.connect(this._jsNode),this.oscillator.start(),this.oscillator.frequency.value=1,this.lastTick=0},p5.Metro.prototype._processBuffer=function(t){for(var o=e.currentTime,n=t.inputBuffer.getChannelData(0),s=this._jsNode.bufferSize,r=0;s>r;r++){var a=n[r];a>0&&!i?(i=!0,this._processTick(o+r/e.sampleRate)):0>a&&i&&(i=!1)}},p5.Metro.prototype._processTick=function(t){this.metroTicks+=1,console.log("interval: "+(t-this.lastTick)),this.lastTick=t},p5.Metro.prototype.setBPM=function(t,e){var i=t/60/2*o,n=e||0;this.oscillator.frequency.linearRampToValueAtTime(i,n)},p5.Metro.prototype.getBPM=function(){return 60*this.oscillator.frequency.value*2}}(master);var src_app;src_app=function(){"use strict";var t=sndcore;return t}(sndcore,master,helpers,soundfile,amplitude,fft,signal,oscillator,env,pulse,noise,audioin,filter,delay,reverb,looper,soundRecorder,metro); \ No newline at end of file diff --git a/src/app.js b/src/app.js index 00d6ffbc..793f3e69 100644 --- a/src/app.js +++ b/src/app.js @@ -19,6 +19,7 @@ define(function (require) { require('reverb'); require('looper'); require('soundRecorder'); + require('metro'); return p5SOUND; diff --git a/src/signal.js b/src/signal.js index 2433cdc0..97072839 100644 --- a/src/signal.js +++ b/src/signal.js @@ -69,14 +69,9 @@ define(function (require) { p5.Signal = function(value) { // scales the constant output to desired output this.scalar = ac.createGain(); - this.scalar.gain.maxValue = 10000; - this.scalar.gain.minValue = -10000; + this.input = ac.createGain(); - this.input.gain.maxValue = 10000; - this.input.gain.minValue = -10000; this.output = ac.createGain(); - this.output.gain.maxValue = 10000; - this.output.gain.minValue = -10000; // the ratio of this value to the control signal this._syncRatio = 1; @@ -305,8 +300,6 @@ define(function (require) { p5.SignalMult = function(num, _input) { var mult = new p5.Signal(); mult.output = mult.input; - mult.input.gain.maxValue = 10000; - mult.input.gain.minValue = -10000; mult.setValue = function(value) { if (typeof(value) === 'number') { this.input.gain.value = value; diff --git a/src/soundRecorder.js b/src/soundRecorder.js index ccdf61b3..3f99b736 100644 --- a/src/soundRecorder.js +++ b/src/soundRecorder.js @@ -68,7 +68,7 @@ define(function (require) { * * else if (state === 2) { * soundFile.play(); // play the result! - * saveSound(soundFile, 'mySound.wav'); + * save(soundFile, 'mySound.wav'); * state++; * } * }