/*! p5.js v0.4.6 June 24, 2015 */ (function (root, factory) { if (typeof define === 'function' && define.amd) define('p5', [], function () { return (root.returnExportsGlobal = factory());}); else if (typeof exports === 'object') module.exports = factory(); else root['p5'] = factory(); }(this, function () { var amdclean = {}; amdclean['core_shim'] = function (require) { window.requestAnimationFrame = function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) { window.setTimeout(callback, 1000 / 60); }; }(); window.performance = window.performance || {}; window.performance.now = function () { var load_date = Date.now(); return window.performance.now || window.performance.mozNow || window.performance.msNow || window.performance.oNow || window.performance.webkitNow || function () { return Date.now() - load_date; }; }(); (function () { 'use strict'; if (typeof Uint8ClampedArray !== 'undefined') { Uint8ClampedArray.prototype.slice = Array.prototype.slice; } }()); }({}); amdclean['core_constants'] = function (require) { var PI = Math.PI; return { P2D: 'p2d', WEBGL: 'webgl', ARROW: 'default', CROSS: 'crosshair', HAND: 'pointer', MOVE: 'move', TEXT: 'text', WAIT: 'wait', HALF_PI: PI / 2, PI: PI, QUARTER_PI: PI / 4, TAU: PI * 2, TWO_PI: PI * 2, DEGREES: 'degrees', RADIANS: 'radians', CORNER: 'corner', CORNERS: 'corners', RADIUS: 'radius', RIGHT: 'right', LEFT: 'left', CENTER: 'center', TOP: 'top', BOTTOM: 'bottom', BASELINE: 'alphabetic', 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', HSL: 'hsl', 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', ADD: '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', THRESHOLD: 'threshold', GRAY: 'gray', OPAQUE: 'opaque', INVERT: 'invert', POSTERIZE: 'posterize', DILATE: 'dilate', ERODE: 'erode', BLUR: 'blur', NORMAL: 'normal', ITALIC: 'italic', BOLD: 'bold', _DEFAULT_TEXT_FILL: '#000000', _DEFAULT_LEADMULT: 1.25, _CTX_MIDDLE: 'middle', LINEAR: 'linear', QUADRATIC: 'quadratic', BEZIER: 'bezier', CURVE: 'curve', _DEFAULT_STROKE: '#000000', _DEFAULT_FILL: '#FFFFFF' }; }({}); amdclean['core_core'] = function (require, core_shim, core_constants) { 'use strict'; var constants = core_constants; var p5 = function (sketch, node, sync) { if (arguments.length === 2 && typeof node === 'boolean') { sync = node; node = undefined; } this._setupDone = false; this.pixelDensity = window.devicePixelRatio || 1; this._userNode = node; this._curElement = null; this._elements = []; this._preloadCount = 0; this._updateInterval = 0; this._isGlobal = false; this._loop = true; this._styles = []; this._defaultCanvasSize = { width: 100, height: 100 }; this._events = { 'mousemove': null, 'mousedown': null, 'mouseup': null, 'click': null, 'mouseover': null, 'mouseout': null, 'keydown': null, 'keyup': null, 'keypress': null, 'touchstart': null, 'touchmove': null, 'touchend': null, 'resize': null, 'blur': null }; if (window.DeviceOrientationEvent) { this._events.deviceorientation = null; } else if (window.DeviceMotionEvent) { this._events.devicemotion = null; } else { this._events.MozOrientation = null; } if (/Firefox/i.test(navigator.userAgent)) { this._events.DOMMouseScroll = null; } else { this._events.mousewheel = null; } this._loadingScreenId = 'p5_loading'; this._start = function () { if (this._userNode) { if (typeof this._userNode === 'string') { this._userNode = document.getElementById(this._userNode); } } this._loadingScreen = document.getElementById(this._loadingScreenId); if (!this._loadingScreen) { this._loadingScreen = document.createElement('loadingDiv'); this._loadingScreen.innerHTML = 'loading...'; this._loadingScreen.style.position = 'absolute'; var node = this._userNode || document.body; node.appendChild(this._loadingScreen); } this.createCanvas(this._defaultCanvasSize.width, this._defaultCanvasSize.height, 'p2d', true); var userPreload = this.preload || window.preload; var context = this._isGlobal ? window : this; if (userPreload) { this._preloadMethods.forEach(function (f) { context[f] = function () { var argsArray = Array.prototype.slice.call(arguments); return context._preload(f, argsArray); }; }); userPreload(); if (this._preloadCount === 0) { this._setup(); this._runFrames(); this._draw(); } } else { this._setup(); this._runFrames(); this._draw(); } }.bind(this); this._preload = function (func, args) { var context = this._isGlobal ? window : this; context._setProperty('_preloadCount', context._preloadCount + 1); var preloadCallback = function (resp) { context._setProperty('_preloadCount', context._preloadCount - 1); if (context._preloadCount === 0) { context._setup(); context._runFrames(); context._draw(); } }; args.push(preloadCallback); return p5.prototype[func].apply(context, args); }.bind(this); this._setup = function () { var context = this._isGlobal ? window : this; if (typeof context.preload === 'function') { this._preloadMethods.forEach(function (f) { context[f] = p5.prototype[f]; }); } if (typeof context.setup === 'function') { context.setup(); } var reg = new RegExp(/(^|\s)p5_hidden(?!\S)/g); var canvases = document.getElementsByClassName('p5_hidden'); for (var i = 0; i < canvases.length; i++) { var k = canvases[i]; k.style.visibility = ''; k.className = k.className.replace(reg, ''); } this._setupDone = true; this._loadingScreen.parentNode.removeChild(this._loadingScreen); }.bind(this); this._draw = function () { var now = window.performance.now(); var time_since_last = now - this._lastFrameTime; var target_time_between_frames = 1000 / this._targetFrameRate; var epsilon = 5; if (!this.loop || time_since_last >= target_time_between_frames - epsilon) { this._setProperty('frameCount', this.frameCount + 1); this.redraw(); this._updatePAccelerations(); this._updatePMouseCoords(); this._updatePTouchCoords(); this._frameRate = 1000 / (now - this._lastFrameTime); this._lastFrameTime = now; } if (this._loop) { window.requestAnimationFrame(this._draw); } }.bind(this); this._runFrames = function () { if (this._updateInterval) { clearInterval(this._updateInterval); } }.bind(this); this._setProperty = function (prop, value) { this[prop] = value; if (this._isGlobal) { window[prop] = value; } }.bind(this); this.remove = function () { if (this._curElement) { this._loop = false; if (this._updateInterval) { clearTimeout(this._updateInterval); } for (var ev in this._events) { window.removeEventListener(ev, this._events[ev]); } for (var i = 0; i < this._elements.length; i++) { var e = this._elements[i]; if (e.elt.parentNode) { e.elt.parentNode.removeChild(e.elt); } for (var elt_ev in e._events) { e.elt.removeEventListener(elt_ev, e._events[elt_ev]); } } var self = this; this._registeredMethods.remove.forEach(function (f) { if (typeof f !== 'undefined') { f.call(self); } }); if (this._isGlobal) { for (var p in p5.prototype) { try { delete window[p]; } catch (x) { window[p] = undefined; } } for (var p2 in this) { if (this.hasOwnProperty(p2)) { try { delete window[p2]; } catch (x) { window[p2] = undefined; } } } } } }.bind(this); for (var k in constants) { p5.prototype[k] = constants[k]; } if (!sketch) { this._isGlobal = true; for (var p in p5.prototype) { if (typeof p5.prototype[p] === 'function') { var ev = p.substring(2); if (!this._events.hasOwnProperty(ev)) { window[p] = p5.prototype[p].bind(this); } } else { window[p] = p5.prototype[p]; } } for (var p2 in this) { if (this.hasOwnProperty(p2)) { window[p2] = this[p2]; } } } else { sketch(this); } for (var e in this._events) { var f = this['_on' + e]; if (f) { var m = f.bind(this); window.addEventListener(e, m); this._events[e] = m; } } var self = this; window.addEventListener('focus', function () { self._setProperty('focused', true); }); window.addEventListener('blur', function () { self._setProperty('focused', false); }); if (sync) { this._start(); } else { if (document.readyState === 'complete') { this._start(); } else { window.addEventListener('load', this._start.bind(this), false); } } }; p5.prototype._preloadMethods = [ 'loadJSON', 'loadImage', 'loadStrings', 'loadXML', 'loadShape', 'loadTable', 'loadFont' ]; p5.prototype._registeredMethods = { pre: [], post: [], remove: [] }; p5.prototype.registerPreloadMethod = function (m) { p5.prototype._preloadMethods.push(m); }.bind(this); p5.prototype.registerMethod = function (name, m) { if (!p5.prototype._registeredMethods.hasOwnProperty(name)) { p5.prototype._registeredMethods[name] = []; } p5.prototype._registeredMethods[name].push(m); }.bind(this); return p5; }({}, amdclean['core_shim'], amdclean['core_constants']); amdclean['color_color_utils'] = function (require, core_core) { var p5 = core_core; p5.ColorUtils = {}; p5.ColorUtils.hsbaToRGBA = function (hsba, maxes) { var h = hsba[0]; var s = hsba[1]; var v = hsba[2]; var a = hsba[3] || maxes[3]; h /= maxes[0]; s /= maxes[1]; v /= maxes[2]; a /= maxes[3]; var RGBA = []; if (s === 0) { RGBA = [ Math.round(v * 255), Math.round(v * 255), Math.round(v * 255), a * 255 ]; } else { var var_h = h * 6; if (var_h === 6) { var_h = 0; } var var_i = Math.floor(var_h); var var_1 = v * (1 - s); var var_2 = v * (1 - s * (var_h - var_i)); var var_3 = v * (1 - s * (1 - (var_h - var_i))); var r; var g; var b; if (var_i === 0) { r = v; g = var_3; b = var_1; } else if (var_i === 1) { r = var_2; g = v; b = var_1; } else if (var_i === 2) { r = var_1; g = v; b = var_3; } else if (var_i === 3) { r = var_1; g = var_2; b = v; } else if (var_i === 4) { r = var_3; g = var_1; b = v; } else { r = v; g = var_1; b = var_2; } RGBA = [ Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a * 255 ]; } return RGBA; }; p5.ColorUtils.rgbaToHSBA = function (rgba, maxes) { var r = rgba[0] / maxes[0]; var g = rgba[1] / maxes[1]; var b = rgba[2] / maxes[2]; var a = rgba[3] / maxes[3]; var min = Math.min(r, g, b); var max = Math.max(r, g, b); var delta_max = max - min; var h; var s; var v = max; if (delta_max === 0) { h = 0; s = 0; } else { s = delta_max / max; var delta_r = ((max - r) / 6 + delta_max / 2) / delta_max; var delta_g = ((max - g) / 6 + delta_max / 2) / delta_max; var delta_b = ((max - b) / 6 + delta_max / 2) / delta_max; if (r === max) { h = delta_b - delta_g; } else if (g === max) { h = 1 / 3 + delta_r - delta_b; } else if (b === max) { h = 2 / 3 + delta_g - delta_r; } if (h < 0) { h += 1; } if (h > 1) { h -= 1; } } return [ Math.round(h * 360), Math.round(s * 100), Math.round(v * 100), a * 1 ]; }; p5.ColorUtils.hslaToRGBA = function (hsla, maxes) { var h = hsla[0]; var s = hsla[1]; var l = hsla[2]; var a = hsla[3] || maxes[3]; h /= maxes[0]; s /= maxes[1]; l /= maxes[2]; a /= maxes[3]; var rgba = []; if (s === 0) { rgba = [ Math.round(l * 255), Math.round(l * 255), Math.round(l * 255), a ]; } else { var m, n, r, g, b; n = l < 0.5 ? l * (1 + s) : l + s - s * l; m = 2 * l - n; var convert = function (x, y, hue) { if (hue < 0) { hue += 1; } else if (hue > 1) { hue -= 1; } if (6 * hue < 1) { return x + (y - x) * 6 * hue; } else if (2 * hue < 1) { return y; } else if (3 * hue < 2) { return x + (y - x) * (2 / 3 - hue) * 6; } else { return x; } }; r = convert(m, n, h + 1 / 3); g = convert(m, n, h); b = convert(m, n, h - 1 / 3); rgba = [ Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), Math.round(a * 255) ]; } return rgba; }; p5.ColorUtils.rgbaToHSLA = function (rgba, maxes) { var r = rgba[0] / maxes[0]; var g = rgba[1] / maxes[1]; var b = rgba[2] / maxes[2]; var a = rgba[3] / maxes[3]; var min = Math.min(r, g, b); var max = Math.max(r, g, b); var delta_max = max - min; var h; var s; var l = (max + min) / 2; var delta_r; var delta_g; var delta_b; if (delta_max === 0) { h = 0; s = 0; } else { delta_r = ((max - r) / 6 + delta_max / 2) / delta_max; delta_g = ((max - g) / 6 + delta_max / 2) / delta_max; delta_b = ((max - b) / 6 + delta_max / 2) / delta_max; if (r === max) { h = delta_b - delta_g; } else if (g === max) { h = 1 / 3 + delta_r - delta_b; } else if (b === max) { h = 2 / 3 + delta_g - delta_r; } if (h < 0) { h += 1; } if (h > 1) { h -= 1; } if (l < 0.5) { s = delta_max / (max + min); } else { s = delta_max / (2 - max - min); } } return [ Math.round(h * 360), Math.round(s * 100), Math.round(l * 100), a * 1 ]; }; return p5.ColorUtils; }({}, amdclean['core_core']); amdclean['color_p5Color'] = function (require, core_core, color_color_utils, core_constants) { var p5 = core_core; var color_utils = color_color_utils; var constants = core_constants; p5.Color = function (pInst, vals) { this.maxArr = pInst._colorMaxes[pInst._colorMode]; this.color_array = p5.Color._getFormattedColor.apply(pInst, vals); var isHSB = pInst._colorMode === constants.HSB, isRGB = pInst._colorMode === constants.RGB, isHSL = pInst._colorMode === constants.HSL; if (isRGB) { this.rgba = this.color_array; } else if (isHSL) { this.hsla = this.color_array; this.rgba = color_utils.hslaToRGBA(this.color_array, this.maxArr); } else if (isHSB) { this.hsba = this.color_array; this.rgba = color_utils.hsbaToRGBA(this.color_array, this.maxArr); } else { throw new Error(pInst._colorMode + 'is an invalid colorMode.'); } return this; }; p5.Color.prototype.getHue = function () { if (this.hsla || this.hsba) { return this.hsla ? this.hsla[0] : this.hsba[0]; } else { this.hsla = color_utils.rgbaToHSLA(this.color_array, this.maxArr); return this.hsla[0]; } }; p5.Color.prototype.getSaturation = function () { if (this.hsla) { return this.hsla[1]; } else if (this.hsba) { return this.hsba[1]; } else { this.hsla = color_utils.rgbaToHSLA(this.color_array, this.maxArr); return this.hsla[1]; } }; p5.Color.prototype.getBrightness = function () { if (this.hsba) { return this.hsba[2]; } else { this.hsba = color_utils.rgbaToHSBA(this.color_array, this.maxArr); return this.hsba[2]; } }; p5.Color.prototype.getLightness = function () { if (this.hsla) { return this.hsla[2]; } else { this.hsla = color_utils.rgbaToHSLA(this.color_array, this.maxArr); return this.hsla[2]; } }; p5.Color.prototype.getRed = function () { return this.rgba[0]; }; p5.Color.prototype.getGreen = function () { return this.rgba[1]; }; p5.Color.prototype.getBlue = function () { return this.rgba[2]; }; p5.Color.prototype.getAlpha = function () { if (this.hsba || this.hsla) { return this.hsla ? this.hsla[3] : this.hsba[3]; } else { return this.rgba[3]; } }; p5.Color.prototype.toString = function () { var a = this.rgba; for (var i = 0; i < 3; i++) { a[i] = Math.floor(a[i]); } var alpha = typeof a[3] !== 'undefined' ? a[3] / 255 : 1; return 'rgba(' + a[0] + ',' + a[1] + ',' + a[2] + ',' + alpha + ')'; }; var WHITESPACE = /\s*/; var INTEGER = /(\d{1,3})/; var DECIMAL = /((?:\d+(?:\.\d+)?)|(?:\.\d+))/; var PERCENT = new RegExp(DECIMAL.source + '%'); var namedColors = { aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc', bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00', chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff', darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9', darkgreen: '#006400', darkgrey: '#a9a9a9', darkkhaki: '#bdb76b', darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000', darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f', darkslategrey: '#2f4f4f', darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493', deepskyblue: '#00bfff', dimgray: '#696969', dimgrey: '#696969', dodgerblue: '#1e90ff', firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff', gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080', green: '#008000', greenyellow: '#adff2f', grey: '#808080', honeydew: '#f0fff0', hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa', lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff', lightgoldenrodyellow: '#fafad2', lightgray: '#d3d3d3', lightgreen: '#90ee90', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a', lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899', lightsteelblue: '#b0c4de', lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000', mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee', mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585', midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23', orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98', paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9', peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd', powderblue: '#b0e0e6', purple: '#800080', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1', saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d', silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090', slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f', steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee', wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32' }; var colorPatterns = { HEX3: /^#([a-f0-9])([a-f0-9])([a-f0-9])$/i, HEX6: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i, RGB: new RegExp([ '^rgb\\(', INTEGER.source, ',', INTEGER.source, ',', INTEGER.source, '\\)$' ].join(WHITESPACE.source), 'i'), RGB_PERCENT: new RegExp([ '^rgb\\(', PERCENT.source, ',', PERCENT.source, ',', PERCENT.source, '\\)$' ].join(WHITESPACE.source), 'i'), RGBA: new RegExp([ '^rgba\\(', INTEGER.source, ',', INTEGER.source, ',', INTEGER.source, ',', DECIMAL.source, '\\)$' ].join(WHITESPACE.source), 'i'), RGBA_PERCENT: new RegExp([ '^rgba\\(', PERCENT.source, ',', PERCENT.source, ',', PERCENT.source, ',', DECIMAL.source, '\\)$' ].join(WHITESPACE.source), 'i'), HSL: new RegExp([ '^hsl\\(', INTEGER.source, ',', PERCENT.source, ',', PERCENT.source, '\\)$' ].join(WHITESPACE.source), 'i'), HSLA: new RegExp([ '^hsla\\(', INTEGER.source, ',', PERCENT.source, ',', PERCENT.source, ',', DECIMAL.source, '\\)$' ].join(WHITESPACE.source), 'i') }; p5.Color._getFormattedColor = function () { var numArgs = arguments.length, mode = this._colorMode, first, second, third, alpha, str, vals; if (numArgs >= 3) { first = arguments[0]; second = arguments[1]; third = arguments[2]; alpha = typeof arguments[3] === 'number' ? arguments[3] : this._colorMaxes[mode][3]; } else if (numArgs === 1 && typeof arguments[0] === 'string') { str = arguments[0].trim().toLowerCase(); if (namedColors[str]) { return p5.Color._getFormattedColor.apply(this, [namedColors[str]]); } if (colorPatterns.HEX3.test(str)) { vals = colorPatterns.HEX3.exec(str).slice(1).map(function (color) { return parseInt(color + color, 16); }); } else if (colorPatterns.HEX6.test(str)) { vals = colorPatterns.HEX6.exec(str).slice(1).map(function (color) { return parseInt(color, 16); }); } else if (colorPatterns.RGB.test(str)) { vals = colorPatterns.RGB.exec(str).slice(1).map(function (color) { return parseInt(color, 10); }); } else if (colorPatterns.RGB_PERCENT.test(str)) { vals = colorPatterns.RGB_PERCENT.exec(str).slice(1).map(function (color) { return parseInt(parseFloat(color) / 100 * 255, 10); }); } else if (colorPatterns.RGBA.test(str)) { vals = colorPatterns.RGBA.exec(str).slice(1).map(function (color, idx) { if (idx === 3) { return parseInt(parseFloat(color) * 255, 10); } return parseInt(color, 10); }); } else if (colorPatterns.RGBA_PERCENT.test(str)) { vals = colorPatterns.RGBA_PERCENT.exec(str).slice(1).map(function (color, idx) { if (idx === 3) { return parseInt(parseFloat(color) * 255, 10); } return parseInt(parseFloat(color) / 100 * 255, 10); }); } else if (colorPatterns.HSL.test(str)) { vals = colorPatterns.HSL.exec(str).slice(1).map(function (color) { return parseInt(color, 10); }); } else if (colorPatterns.HSLA.test(str)) { vals = colorPatterns.HSLA.exec(str).slice(1).map(function (color) { return parseFloat(color, 10); }); } else { vals = [255]; } return p5.Color._getFormattedColor.apply(this, vals); } else if (numArgs === 1 && typeof arguments[0] === 'number') { if (mode === constants.RGB) { first = second = third = arguments[0]; } else if (mode === constants.HSB || mode === constants.HSL) { first = third = arguments[0]; second = 0; } alpha = typeof arguments[1] === 'number' ? arguments[1] : this._colorMaxes[mode][3]; } else if (numArgs === 2 && typeof arguments[0] === 'number' && typeof arguments[1] === 'number') { if (mode === constants.RGB) { first = second = third = arguments[0]; } else if (mode === constants.HSB || mode === constants.HSL) { first = third = arguments[0]; second = 0; } alpha = arguments[1]; } else { throw new Error(arguments + 'is not a valid color representation.'); } return [ first, second, third, alpha ]; }; return p5.Color; }({}, amdclean['core_core'], amdclean['color_color_utils'], amdclean['core_constants']); amdclean['core_p5Element'] = function (require, core_core) { var p5 = core_core; p5.Element = function (elt, pInst) { this.elt = elt; this._pInst = pInst; this._events = {}; this.width = this.elt.offsetWidth; this.height = this.elt.offsetHeight; }; p5.Element.prototype.parent = function (p) { if (typeof p === 'string') { p = document.getElementById(p); } else if (p instanceof p5.Element) { p = p.elt; } p.appendChild(this.elt); return this; }; p5.Element.prototype.id = function (id) { this.elt.id = id; return this; }; p5.Element.prototype.class = function (c) { this.elt.className += ' ' + c; return this; }; p5.Element.prototype.mousePressed = function (fxn) { attachListener('mousedown', fxn, this); attachListener('touchstart', fxn, this); return this; }; p5.Element.prototype.mouseWheel = function (fxn) { attachListener('mousewheel', fxn, this); return this; }; p5.Element.prototype.mouseReleased = function (fxn) { attachListener('mouseup', fxn, this); attachListener('touchend', fxn, this); return this; }; p5.Element.prototype.mouseClicked = function (fxn) { attachListener('click', fxn, this); return this; }; p5.Element.prototype.mouseMoved = function (fxn) { attachListener('mousemove', fxn, this); attachListener('touchmove', fxn, this); return this; }; p5.Element.prototype.mouseOver = function (fxn) { attachListener('mouseover', fxn, this); return this; }; p5.Element.prototype.mouseOut = function (fxn) { attachListener('mouseout', fxn, this); return this; }; p5.Element.prototype.touchStarted = function (fxn) { attachListener('touchstart', fxn, this); attachListener('mousedown', fxn, this); return this; }; p5.Element.prototype.touchMoved = function (fxn) { attachListener('touchmove', fxn, this); attachListener('mousemove', fxn, this); return this; }; p5.Element.prototype.touchEnded = function (fxn) { attachListener('touchend', fxn, this); attachListener('mouseup', fxn, this); return this; }; p5.Element.prototype.dragOver = function (fxn) { attachListener('dragover', fxn, this); return this; }; p5.Element.prototype.dragLeave = function (fxn) { attachListener('dragleave', fxn, this); return this; }; p5.Element.prototype.drop = function (callback, fxn) { function makeLoader(theFile) { var p5file = new p5.File(theFile); return function (e) { p5file.data = e.target.result; callback(p5file); }; } if (window.File && window.FileReader && window.FileList && window.Blob) { attachListener('dragover', function (evt) { evt.stopPropagation(); evt.preventDefault(); }, this); attachListener('dragleave', function (evt) { evt.stopPropagation(); evt.preventDefault(); }, this); if (arguments.length > 1) { attachListener('drop', fxn, this); } attachListener('drop', function (evt) { evt.stopPropagation(); evt.preventDefault(); var files = evt.dataTransfer.files; for (var i = 0; i < files.length; i++) { var f = files[i]; var reader = new FileReader(); reader.onload = makeLoader(f); if (f.type === 'text') { reader.readAsText(f); } else { reader.readAsDataURL(f); } } }, this); } else { console.log('The File APIs are not fully supported in this browser.'); } return this; }; function attachListener(ev, fxn, ctx) { var f = fxn.bind(ctx); ctx.elt.addEventListener(ev, f, false); ctx._events[ev] = f; } p5.Element.prototype._setProperty = function (prop, value) { this[prop] = value; }; return p5.Element; }({}, amdclean['core_core']); amdclean['typography_p5Font'] = function (require, core_core, core_constants) { 'use strict'; var p5 = core_core; var constants = core_constants; p5.Font = function (p) { this.parent = p; this.cache = {}; this.font = undefined; }; p5.Font.prototype._getGlyphs = function (str) { return this.font.stringToGlyphs(str); }; p5.Font.prototype._getPath = function (line, x, y, options) { var p = this.parent, ctx = p._graphics.drawingContext, pos = this._handleAlignment(p, ctx, line, x, y); return this.font.getPath(line, pos.x, pos.y, p._textSize, options); }; p5.Font.prototype._getPathData = function (line, x, y, options) { var decimals = 3; if (typeof line === 'string' && arguments.length > 2) { line = this._getPath(line, x, y, options); } else if (typeof x === 'object') { options = x; } if (options && typeof options.decimals === 'number') { decimals = options.decimals; } return line.toPathData(decimals); }; p5.Font.prototype._getSVG = function (line, x, y, options) { var decimals = 3; if (typeof line === 'string' && arguments.length > 2) { line = this._getPath(line, x, y, options); } else if (typeof x === 'object') { options = x; } if (options) { if (typeof options.decimals === 'number') { decimals = options.decimals; } if (typeof options.strokeWidth === 'number') { line.strokeWidth = options.strokeWidth; } if (typeof options.fill !== undefined) { line.fill = options.fill; } if (typeof options.stroke !== undefined) { line.stroke = options.stroke; } } return line.toSVG(decimals); }; p5.Font.prototype._renderPath = function (line, x, y, options) { var pdata, p = this.parent, pg = p._graphics, ctx = pg.drawingContext; if (typeof line === 'object' && line.commands) { pdata = line.commands; } else { pdata = this._getPath(line, x, y, p._textSize, options).commands; } ctx.beginPath(); for (var i = 0; i < pdata.length; i += 1) { var cmd = pdata[i]; if (cmd.type === 'M') { ctx.moveTo(cmd.x, cmd.y); } else if (cmd.type === 'L') { ctx.lineTo(cmd.x, cmd.y); } else if (cmd.type === 'C') { ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); } else if (cmd.type === 'Q') { ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y); } else if (cmd.type === 'Z') { ctx.closePath(); } } if (p._doStroke && p._strokeSet) { ctx.stroke(); } if (p._doFill) { ctx.fillStyle = p._fillSet ? ctx.fillStyle : constants._DEFAULT_TEXT_FILL; ctx.fill(); } return this; }; p5.Font.prototype._textWidth = function (str) { if (str === ' ') { return this.font.charToGlyph(' ').advanceWidth * this._scale(); } var bounds = this.textBounds(str); return bounds.w + bounds.advance; }; p5.Font.prototype._textAscent = function () { var bounds = this.textBounds('ABCjgq|'); return Math.abs(bounds.y); }; p5.Font.prototype._textDescent = function () { var bounds = this.textBounds('ABCjgq|'); return bounds.h - Math.abs(bounds.y); }; p5.Font.prototype._scale = function (fontSize) { return 1 / this.font.unitsPerEm * (fontSize || this.parent._textSize); }; p5.Font.prototype.textBounds = function (str, x, y, fontSize, options) { x = x !== undefined ? x : 0; y = y !== undefined ? y : 0; fontSize = fontSize || this.parent._textSize; var result = this.cache[cacheKey('textBounds', str, x, y, fontSize)]; if (!result) { if (str !== ' ') { var xCoords = [], yCoords = [], scale = this._scale(fontSize), minX, minY, maxX, maxY; this.font.forEachGlyph(str, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { if (glyph.name !== 'space') { gX = gX !== undefined ? gX : 0; gY = gY !== undefined ? gY : 0; var gm = glyph.getMetrics(); xCoords.push(gX + gm.xMin * scale); yCoords.push(gY + -gm.yMin * scale); xCoords.push(gX + gm.xMax * scale); yCoords.push(gY + -gm.yMax * scale); } }); minX = Math.min.apply(null, xCoords); minY = Math.min.apply(null, yCoords); maxX = Math.max.apply(null, xCoords); maxY = Math.max.apply(null, yCoords); result = { x: minX, y: minY, h: maxY - minY, w: maxX - minX, advance: minX - x }; } else { var tw = this._textWidth(str); result = { x: x, y: y, h: 0, w: tw, advance: 0 }; } this.cache[cacheKey('textBounds', str, x, y, fontSize)] = result; } return result; }; p5.Font.prototype._drawPoints = function (str, tx, ty, options) { var pdata, onCurvePts, offCurvePts, p = this.parent, scale = this._scale(); tx = tx !== undefined ? tx : 0; ty = ty !== undefined ? ty : 0; this.font.forEachGlyph(str, tx, ty, p._textSize, options, function (glyph, x, y, fontSize) { onCurvePts = []; offCurvePts = []; pdata = glyph.path.commands; for (var i = 0; i < pdata.length; i += 1) { var cmd = pdata[i]; if (cmd.x !== undefined) { onCurvePts.push({ x: cmd.x, y: -cmd.y }); } if (cmd.x1 !== undefined) { offCurvePts.push({ x: cmd.x1, y: -cmd.y1 }); } if (cmd.x2 !== undefined) { offCurvePts.push({ x: cmd.x2, y: -cmd.y2 }); } } p.noStroke(); p.fill(0, 0, 255); drawCircles(onCurvePts, x, y, scale); p.fill(255, 0, 0); drawCircles(offCurvePts, x, y, scale); }); function drawCircles(l, x, y, scale) { for (var j = 0; j < l.length; j++) { p.ellipse(x + l[j].x * scale, y + l[j].y * scale, 3, 3); } } }; p5.Font.prototype.list = function () { throw 'not yet implemented'; }; p5.Font.prototype._handleAlignment = function (p, ctx, line, x, y) { var textWidth = this._textWidth(line), textAscent = this._textAscent(), textDescent = this._textDescent(), textHeight = textAscent + textDescent; if (ctx.textAlign === constants.CENTER) { x -= textWidth / 2; } else if (ctx.textAlign === constants.RIGHT) { x -= textWidth; } if (ctx.textBaseline === constants.TOP) { y += textHeight; } else if (ctx.textBaseline === constants._CTX_MIDDLE) { y += textHeight / 2 - textDescent; } else if (ctx.textBaseline === constants.BOTTOM) { y -= textDescent; } return { x: x, y: y }; }; function cacheKey() { var args = Array.prototype.slice.call(arguments), i = args.length, hash = ''; while (i--) { hash += args[i] === Object(args[i]) ? JSON.stringify(args[i]) : args[i]; } return hash; } return p5.Font; }({}, amdclean['core_core'], amdclean['core_constants']); amdclean['core_p5Graphics'] = function (require, core_core, core_constants) { var p5 = core_core; var constants = core_constants; p5.Graphics = function (w, h, renderer, pInst) { var r = renderer || constants.P2D; var c = document.createElement('canvas'); var node = this._userNode || document.body; node.appendChild(c); p5.Element.call(this, c, pInst, false); this._styles = []; this.width = w; this.height = h; this.pixelDensity = pInst.pixelDensity; if (r === constants.WEBGL) { this._graphics = new p5.Renderer3D(c, this, false); } else { this._graphics = new p5.Renderer2D(c, this, false); } this._graphics.resize(w, h); this._graphics._applyDefaults(); pInst._elements.push(this); for (var p in p5.prototype) { if (!this[p]) { if (typeof p5.prototype[p] === 'function') { this[p] = p5.prototype[p].bind(this); } else { this[p] = p5.prototype[p]; } } } return this; }; p5.Graphics.prototype = Object.create(p5.Element.prototype); return p5.Graphics; }({}, amdclean['core_core'], amdclean['core_constants']); amdclean['core_canvas'] = function (require, core_constants) { var constants = core_constants; return { modeAdjust: function (a, b, c, d, mode) { if (mode === constants.CORNER) { return { x: a, y: b, w: c, h: d }; } else if (mode === constants.CORNERS) { return { x: a, y: b, w: c - a, h: d - b }; } else if (mode === constants.RADIUS) { return { x: a - c, y: b - d, w: 2 * c, h: 2 * d }; } else if (mode === constants.CENTER) { return { x: a - c * 0.5, y: b - d * 0.5, w: c, h: d }; } }, arcModeAdjust: function (a, b, c, d, mode) { if (mode === constants.CORNER) { return { x: a + c * 0.5, y: b + d * 0.5, w: c, h: d }; } else if (mode === constants.CORNERS) { return { x: a, y: b, w: c + a, h: d + b }; } else if (mode === constants.RADIUS) { return { x: a, y: b, w: 2 * c, h: 2 * d }; } else if (mode === constants.CENTER) { return { x: a, y: b, w: c, h: d }; } } }; }({}, amdclean['core_constants']); amdclean['image_filters'] = function (require) { 'use strict'; var Filters = {}; Filters._toPixels = function (canvas) { if (canvas instanceof ImageData) { return canvas.data; } else { return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data; } }; Filters._getARGB = function (data, i) { var offset = i * 4; return data[offset + 3] << 24 & 4278190080 | data[offset] << 16 & 16711680 | data[offset + 1] << 8 & 65280 | data[offset + 2] & 255; }; Filters._setPixels = function (pixels, data) { var offset = 0; for (var i = 0, al = pixels.length; i < al; i++) { offset = i * 4; pixels[offset + 0] = (data[i] & 16711680) >>> 16; pixels[offset + 1] = (data[i] & 65280) >>> 8; pixels[offset + 2] = data[i] & 255; pixels[offset + 3] = (data[i] & 4278190080) >>> 24; } }; Filters._toImageData = function (canvas) { if (canvas instanceof ImageData) { return canvas; } else { return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height); } }; Filters._createImageData = function (width, height) { Filters._tmpCanvas = document.createElement('canvas'); Filters._tmpCtx = Filters._tmpCanvas.getContext('2d'); return this._tmpCtx.createImageData(width, height); }; Filters.apply = function (canvas, func, filterParam) { var ctx = canvas.getContext('2d'); var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); var newImageData = func(imageData, filterParam); if (newImageData instanceof ImageData) { ctx.putImageData(newImageData, 0, 0, 0, 0, canvas.width, canvas.height); } else { ctx.putImageData(imageData, 0, 0, 0, 0, canvas.width, canvas.height); } }; Filters.threshold = function (canvas, level) { var pixels = Filters._toPixels(canvas); if (level === undefined) { level = 0.5; } var thresh = Math.floor(level * 255); for (var i = 0; i < pixels.length; i += 4) { var r = pixels[i]; var g = pixels[i + 1]; var b = pixels[i + 2]; var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b; var val; if (gray >= thresh) { val = 255; } else { val = 0; } pixels[i] = pixels[i + 1] = pixels[i + 2] = val; } }; Filters.gray = function (canvas) { var pixels = Filters._toPixels(canvas); for (var i = 0; i < pixels.length; i += 4) { var r = pixels[i]; var g = pixels[i + 1]; var b = pixels[i + 2]; var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b; pixels[i] = pixels[i + 1] = pixels[i + 2] = gray; } }; Filters.opaque = function (canvas) { var pixels = Filters._toPixels(canvas); for (var i = 0; i < pixels.length; i += 4) { pixels[i + 3] = 255; } return pixels; }; Filters.invert = function (canvas) { var pixels = Filters._toPixels(canvas); for (var i = 0; i < pixels.length; i += 4) { pixels[i] = 255 - pixels[i]; pixels[i + 1] = 255 - pixels[i + 1]; pixels[i + 2] = 255 - pixels[i + 2]; } }; Filters.posterize = function (canvas, level) { var pixels = Filters._toPixels(canvas); if (level < 2 || level > 255) { throw new Error('Level must be greater than 2 and less than 255 for posterize'); } var levels1 = level - 1; for (var i = 0; i < pixels.length; i += 4) { var rlevel = pixels[i]; var glevel = pixels[i + 1]; var blevel = pixels[i + 2]; pixels[i] = (rlevel * level >> 8) * 255 / levels1; pixels[i + 1] = (glevel * level >> 8) * 255 / levels1; pixels[i + 2] = (blevel * level >> 8) * 255 / levels1; } }; Filters.dilate = function (canvas) { var pixels = Filters._toPixels(canvas); var currIdx = 0; var maxIdx = pixels.length ? pixels.length / 4 : 0; var out = new Int32Array(maxIdx); var currRowIdx, maxRowIdx, colOrig, colOut, currLum; var idxRight, idxLeft, idxUp, idxDown, colRight, colLeft, colUp, colDown, lumRight, lumLeft, lumUp, lumDown; while (currIdx < maxIdx) { currRowIdx = currIdx; maxRowIdx = currIdx + canvas.width; while (currIdx < maxRowIdx) { colOrig = colOut = Filters._getARGB(pixels, currIdx); idxLeft = currIdx - 1; idxRight = currIdx + 1; idxUp = currIdx - canvas.width; idxDown = currIdx + canvas.width; if (idxLeft < currRowIdx) { idxLeft = currIdx; } if (idxRight >= maxRowIdx) { idxRight = currIdx; } if (idxUp < 0) { idxUp = 0; } if (idxDown >= maxIdx) { idxDown = currIdx; } colUp = Filters._getARGB(pixels, idxUp); colLeft = Filters._getARGB(pixels, idxLeft); colDown = Filters._getARGB(pixels, idxDown); colRight = Filters._getARGB(pixels, idxRight); currLum = 77 * (colOrig >> 16 & 255) + 151 * (colOrig >> 8 & 255) + 28 * (colOrig & 255); lumLeft = 77 * (colLeft >> 16 & 255) + 151 * (colLeft >> 8 & 255) + 28 * (colLeft & 255); lumRight = 77 * (colRight >> 16 & 255) + 151 * (colRight >> 8 & 255) + 28 * (colRight & 255); lumUp = 77 * (colUp >> 16 & 255) + 151 * (colUp >> 8 & 255) + 28 * (colUp & 255); lumDown = 77 * (colDown >> 16 & 255) + 151 * (colDown >> 8 & 255) + 28 * (colDown & 255); if (lumLeft > currLum) { colOut = colLeft; currLum = lumLeft; } if (lumRight > currLum) { colOut = colRight; currLum = lumRight; } if (lumUp > currLum) { colOut = colUp; currLum = lumUp; } if (lumDown > currLum) { colOut = colDown; currLum = lumDown; } out[currIdx++] = colOut; } } Filters._setPixels(pixels, out); }; Filters.erode = function (canvas) { var pixels = Filters._toPixels(canvas); var currIdx = 0; var maxIdx = pixels.length ? pixels.length / 4 : 0; var out = new Int32Array(maxIdx); var currRowIdx, maxRowIdx, colOrig, colOut, currLum; var idxRight, idxLeft, idxUp, idxDown, colRight, colLeft, colUp, colDown, lumRight, lumLeft, lumUp, lumDown; while (currIdx < maxIdx) { currRowIdx = currIdx; maxRowIdx = currIdx + canvas.width; while (currIdx < maxRowIdx) { colOrig = colOut = Filters._getARGB(pixels, currIdx); idxLeft = currIdx - 1; idxRight = currIdx + 1; idxUp = currIdx - canvas.width; idxDown = currIdx + canvas.width; if (idxLeft < currRowIdx) { idxLeft = currIdx; } if (idxRight >= maxRowIdx) { idxRight = currIdx; } if (idxUp < 0) { idxUp = 0; } if (idxDown >= maxIdx) { idxDown = currIdx; } colUp = Filters._getARGB(pixels, idxUp); colLeft = Filters._getARGB(pixels, idxLeft); colDown = Filters._getARGB(pixels, idxDown); colRight = Filters._getARGB(pixels, idxRight); currLum = 77 * (colOrig >> 16 & 255) + 151 * (colOrig >> 8 & 255) + 28 * (colOrig & 255); lumLeft = 77 * (colLeft >> 16 & 255) + 151 * (colLeft >> 8 & 255) + 28 * (colLeft & 255); lumRight = 77 * (colRight >> 16 & 255) + 151 * (colRight >> 8 & 255) + 28 * (colRight & 255); lumUp = 77 * (colUp >> 16 & 255) + 151 * (colUp >> 8 & 255) + 28 * (colUp & 255); lumDown = 77 * (colDown >> 16 & 255) + 151 * (colDown >> 8 & 255) + 28 * (colDown & 255); if (lumLeft < currLum) { colOut = colLeft; currLum = lumLeft; } if (lumRight < currLum) { colOut = colRight; currLum = lumRight; } if (lumUp < currLum) { colOut = colUp; currLum = lumUp; } if (lumDown < currLum) { colOut = colDown; currLum = lumDown; } out[currIdx++] = colOut; } } Filters._setPixels(pixels, out); }; var blurRadius; var blurKernelSize; var blurKernel; var blurMult; function buildBlurKernel(r) { var radius = r * 3.5 | 0; radius = radius < 1 ? 1 : radius < 248 ? radius : 248; if (blurRadius !== radius) { blurRadius = radius; blurKernelSize = 1 + blurRadius << 1; blurKernel = new Int32Array(blurKernelSize); blurMult = new Array(blurKernelSize); for (var l = 0; l < blurKernelSize; l++) { blurMult[l] = new Int32Array(256); } var bk, bki; var bm, bmi; for (var i = 1, radiusi = radius - 1; i < radius; i++) { blurKernel[radius + i] = blurKernel[radiusi] = bki = radiusi * radiusi; bm = blurMult[radius + i]; bmi = blurMult[radiusi--]; for (var j = 0; j < 256; j++) { bm[j] = bmi[j] = bki * j; } } bk = blurKernel[radius] = radius * radius; bm = blurMult[radius]; for (var k = 0; k < 256; k++) { bm[k] = bk * k; } } } function blurARGB(canvas, radius) { var pixels = Filters._toPixels(canvas); var width = canvas.width; var height = canvas.height; var numPackedPixels = width * height; var argb = new Int32Array(numPackedPixels); for (var j = 0; j < numPackedPixels; j++) { argb[j] = Filters._getARGB(pixels, j); } var sum, cr, cg, cb, ca; var read, ri, ym, ymi, bk0; var a2 = new Int32Array(numPackedPixels); var r2 = new Int32Array(numPackedPixels); var g2 = new Int32Array(numPackedPixels); var b2 = new Int32Array(numPackedPixels); var yi = 0; buildBlurKernel(radius); var x, y, i; var bm; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { cb = cg = cr = ca = sum = 0; read = x - blurRadius; if (read < 0) { bk0 = -read; read = 0; } else { if (read >= width) { break; } bk0 = 0; } for (i = bk0; i < blurKernelSize; i++) { if (read >= width) { break; } var c = argb[read + yi]; bm = blurMult[i]; ca += bm[(c & -16777216) >>> 24]; cr += bm[(c & 16711680) >> 16]; cg += bm[(c & 65280) >> 8]; cb += bm[c & 255]; sum += blurKernel[i]; read++; } ri = yi + x; a2[ri] = ca / sum; r2[ri] = cr / sum; g2[ri] = cg / sum; b2[ri] = cb / sum; } yi += width; } yi = 0; ym = -blurRadius; ymi = ym * width; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { cb = cg = cr = ca = sum = 0; if (ym < 0) { bk0 = ri = -ym; read = x; } else { if (ym >= height) { break; } bk0 = 0; ri = ym; read = x + ymi; } for (i = bk0; i < blurKernelSize; i++) { if (ri >= height) { break; } bm = blurMult[i]; ca += bm[a2[read]]; cr += bm[r2[read]]; cg += bm[g2[read]]; cb += bm[b2[read]]; sum += blurKernel[i]; ri++; read += width; } argb[x + yi] = ca / sum << 24 | cr / sum << 16 | cg / sum << 8 | cb / sum; } yi += width; ymi += width; ym++; } Filters._setPixels(pixels, argb); } Filters.blur = function (canvas, radius) { blurARGB(canvas, radius); }; return Filters; }({}); amdclean['core_p5Renderer'] = function (require, core_core) { var p5 = core_core; p5.Renderer = function (elt, pInst, isMainCanvas) { p5.Element.call(this, elt, pInst); this.canvas = elt; this._pInst = pInst; if (isMainCanvas) { this._isMainCanvas = true; this._pInst._setProperty('_curElement', this); this._pInst._setProperty('canvas', this.canvas); this._pInst._setProperty('width', this.width); this._pInst._setProperty('height', this.height); } else { this.canvas.style.display = 'none'; this._styles = []; } }; p5.Renderer.prototype = Object.create(p5.Element.prototype); p5.Renderer.prototype.resize = function (w, h) { this.width = w; this.height = h; this.elt.width = w * this._pInst.pixelDensity; this.elt.height = h * this._pInst.pixelDensity; this.elt.style.width = w + 'px'; this.elt.style.height = h + 'px'; if (this._isMainCanvas) { this._pInst._setProperty('width', this.width); this._pInst._setProperty('height', this.height); } }; return p5.Renderer; }({}, amdclean['core_core']); amdclean['core_p5Renderer2D'] = function (require, core_core, core_canvas, core_constants, image_filters, core_p5Renderer) { var p5 = core_core; var canvas = core_canvas; var constants = core_constants; var filters = image_filters; var styleEmpty = 'rgba(0,0,0,0)'; p5.Renderer2D = function (elt, pInst, isMainCanvas) { p5.Renderer.call(this, elt, pInst, isMainCanvas); this.drawingContext = this.canvas.getContext('2d'); this._pInst._setProperty('drawingContext', this.drawingContext); return this; }; p5.Renderer2D.prototype = Object.create(p5.Renderer.prototype); p5.Renderer2D.prototype._applyDefaults = function () { this.drawingContext.fillStyle = constants._DEFAULT_FILL; this.drawingContext.strokeStyle = constants._DEFAULT_STROKE; this.drawingContext.lineCap = constants.ROUND; this.drawingContext.font = 'normal 12px sans-serif'; }; p5.Renderer2D.prototype.resize = function (w, h) { p5.Renderer.prototype.resize.call(this, w, h); this.drawingContext.scale(this._pInst.pixelDensity, this._pInst.pixelDensity); }; p5.Renderer2D.prototype.background = function () { this.drawingContext.save(); this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); this.drawingContext.scale(this._pInst.pixelDensity, this._pInst.pixelDensity); if (arguments[0] instanceof p5.Image) { this._pInst.image(arguments[0], 0, 0, this.width, this.height); } else { var curFill = this.drawingContext.fillStyle; var color = this._pInst.color.apply(this._pInst, arguments); var newFill = color.toString(); this.drawingContext.fillStyle = newFill; this.drawingContext.fillRect(0, 0, this.width, this.height); this.drawingContext.fillStyle = curFill; } this.drawingContext.restore(); }; p5.Renderer2D.prototype.clear = function () { this.drawingContext.clearRect(0, 0, this.width, this.height); }; p5.Renderer2D.prototype.fill = function () { var ctx = this.drawingContext; var color = this._pInst.color.apply(this._pInst, arguments); ctx.fillStyle = color.toString(); }; p5.Renderer2D.prototype.stroke = function () { var ctx = this.drawingContext; var color = this._pInst.color.apply(this._pInst, arguments); ctx.strokeStyle = color.toString(); }; p5.Renderer2D.prototype.image = function (img, x, y, w, h) { var frame = img.canvas || img.elt; try { if (this._pInst._tint && img.canvas) { this.drawingContext.drawImage(this._getTintedImageCanvas(img), x, y, w, h); } else { this.drawingContext.drawImage(frame, x, y, w, h); } } catch (e) { if (e.name !== 'NS_ERROR_NOT_AVAILABLE') { throw e; } } }; p5.Renderer2D.prototype._getTintedImageCanvas = function (img) { if (!img.canvas) { return img; } var pixels = filters._toPixels(img.canvas); var tmpCanvas = document.createElement('canvas'); tmpCanvas.width = img.canvas.width; tmpCanvas.height = img.canvas.height; var tmpCtx = tmpCanvas.getContext('2d'); var id = tmpCtx.createImageData(img.canvas.width, img.canvas.height); var newPixels = id.data; for (var i = 0; i < pixels.length; i += 4) { var r = pixels[i]; var g = pixels[i + 1]; var b = pixels[i + 2]; var a = pixels[i + 3]; newPixels[i] = r * this._pInst._tint[0] / 255; newPixels[i + 1] = g * this._pInst._tint[1] / 255; newPixels[i + 2] = b * this._pInst._tint[2] / 255; newPixels[i + 3] = a * this._pInst._tint[3] / 255; } tmpCtx.putImageData(id, 0, 0); return tmpCanvas; }; p5.Renderer2D.prototype.blendMode = function (mode) { this.drawingContext.globalCompositeOperation = mode; }; p5.Renderer2D.prototype.blend = function () { var currBlend = this.drawingContext.globalCompositeOperation; var blendMode = arguments[arguments.length - 1]; var copyArgs = Array.prototype.slice.call(arguments, 0, arguments.length - 1); this.drawingContext.globalCompositeOperation = blendMode; this._pInst.copy.apply(this._pInst, copyArgs); this.drawingContext.globalCompositeOperation = currBlend; }; p5.Renderer2D.prototype.copy = function () { var srcImage, sx, sy, sw, sh, dx, dy, dw, dh; if (arguments.length === 9) { srcImage = arguments[0]; sx = arguments[1]; sy = arguments[2]; sw = arguments[3]; sh = arguments[4]; dx = arguments[5]; dy = arguments[6]; dw = arguments[7]; dh = arguments[8]; } else if (arguments.length === 8) { srcImage = this._pInst; sx = arguments[0]; sy = arguments[1]; sw = arguments[2]; sh = arguments[3]; dx = arguments[4]; dy = arguments[5]; dw = arguments[6]; dh = arguments[7]; } else { throw new Error('Signature not supported'); } p5.Renderer2D._copyHelper(srcImage, sx, sy, sw, sh, dx, dy, dw, dh); }; p5.Renderer2D._copyHelper = function (srcImage, sx, sy, sw, sh, dx, dy, dw, dh) { var s = srcImage.canvas.width / srcImage.width; this.drawingContext.drawImage(srcImage.canvas, s * sx, s * sy, s * sw, s * sh, dx, dy, dw, dh); }; p5.Renderer2D.prototype.get = function (x, y, w, h) { if (x === undefined && y === undefined && w === undefined && h === undefined) { x = 0; y = 0; w = this.width; h = this.height; } else if (w === undefined && h === undefined) { w = 1; h = 1; } if (x > this.width || y > this.height || x < 0 || y < 0) { return [ 0, 0, 0, 255 ]; } var pd = this.pixelDensity || this._pInst.pixelDensity; if (w === 1 && h === 1) { var imageData = this.drawingContext.getImageData(x * pd, y * pd, w, h); var data = imageData.data; var pixels = []; for (var i = 0; i < data.length; i += 4) { pixels.push(data[i], data[i + 1], data[i + 2], data[i + 3]); } return pixels; } else { var sx = x * pd; var sy = y * pd; var dw = Math.min(w, this.width); var dh = Math.min(h, this.height); var sw = dw * pd; var sh = dh * pd; var region = new p5.Image(dw, dh); region.canvas.getContext('2d').drawImage(this.canvas, sx, sy, sw, sh, 0, 0, dw, dh); return region; } }; p5.Renderer2D.prototype.loadPixels = function () { var pd = this.pixelDensity || this._pInst.pixelDensity; var w = this.width * pd; var h = this.height * pd; var imageData = this.drawingContext.getImageData(0, 0, w, h); if (this._pInst) { this._pInst._setProperty('imageData', imageData); this._pInst._setProperty('pixels', imageData.data); } else { this._setProperty('imageData', imageData); this._setProperty('pixels', imageData.data); } }; p5.Renderer2D.prototype.set = function (x, y, imgOrCol) { if (imgOrCol instanceof p5.Image) { this.drawingContext.save(); this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); this.drawingContext.scale(this._pInst.pixelDensity, this._pInst.pixelDensity); this.drawingContext.drawImage(imgOrCol.canvas, x, y); this.loadPixels.call(this._pInst); this.drawingContext.restore(); } else { var ctx = this._pInst || this; var r = 0, g = 0, b = 0, a = 0; var idx = 4 * (y * ctx.pixelDensity * (this.width * ctx.pixelDensity) + x * ctx.pixelDensity); if (!ctx.imageData) { ctx.loadPixels.call(ctx); } if (typeof imgOrCol === 'number') { if (idx < ctx.pixels.length) { r = imgOrCol; g = imgOrCol; b = imgOrCol; a = 255; } } else if (imgOrCol instanceof Array) { if (imgOrCol.length < 4) { throw new Error('pixel array must be of the form [R, G, B, A]'); } if (idx < ctx.pixels.length) { r = imgOrCol[0]; g = imgOrCol[1]; b = imgOrCol[2]; a = imgOrCol[3]; } } else if (imgOrCol instanceof p5.Color) { if (idx < ctx.pixels.length) { r = imgOrCol.rgba[0]; g = imgOrCol.rgba[1]; b = imgOrCol.rgba[2]; a = imgOrCol.rgba[3]; } } for (var i = 0; i < ctx.pixelDensity; i++) { for (var j = 0; j < ctx.pixelDensity; j++) { idx = 4 * ((y * ctx.pixelDensity + j) * this.width * ctx.pixelDensity + (x * ctx.pixelDensity + i)); ctx.pixels[idx] = r; ctx.pixels[idx + 1] = g; ctx.pixels[idx + 2] = b; ctx.pixels[idx + 3] = a; } } } }; p5.Renderer2D.prototype.updatePixels = function (x, y, w, h) { var pd = this.pixelDensity || this._pInst.pixelDensity; if (x === undefined && y === undefined && w === undefined && h === undefined) { x = 0; y = 0; w = this.width; h = this.height; } w *= pd; h *= pd; if (this._pInst) { this.drawingContext.putImageData(this._pInst.imageData, x, y, 0, 0, w, h); } else { this.drawingContext.putImageData(this.imageData, x, y, 0, 0, w, h); } }; p5.Renderer2D.prototype.arc = function (x, y, w, h, start, stop, mode, curves) { if (!this._pInst._doStroke && !this._pInst._doFill) { return; } var ctx = this.drawingContext; var vals = canvas.arcModeAdjust(x, y, w, h, this._pInst._ellipseMode); var rx = vals.w / 2; var ry = vals.h / 2; ctx.beginPath(); curves.forEach(function (curve, index) { if (index === 0) { ctx.moveTo(vals.x + curve.x1 * rx, vals.y + curve.y1 * ry); } ctx.bezierCurveTo(vals.x + curve.x2 * rx, vals.y + curve.y2 * ry, vals.x + curve.x3 * rx, vals.y + curve.y3 * ry, vals.x + curve.x4 * rx, vals.y + curve.y4 * ry); }); if (this._pInst._doFill) { if (mode === constants.PIE || mode == null) { ctx.lineTo(vals.x, vals.y); } ctx.closePath(); ctx.fill(); if (this._pInst._doStroke) { if (mode === constants.CHORD || mode === constants.PIE) { ctx.stroke(); return this; } } } if (this._pInst._doStroke) { if (mode === constants.OPEN || mode == null) { ctx.beginPath(); curves.forEach(function (curve, index) { if (index === 0) { ctx.moveTo(vals.x + curve.x1 * rx, vals.y + curve.y1 * ry); } ctx.bezierCurveTo(vals.x + curve.x2 * rx, vals.y + curve.y2 * ry, vals.x + curve.x3 * rx, vals.y + curve.y3 * ry, vals.x + curve.x4 * rx, vals.y + curve.y4 * ry); }); ctx.stroke(); } } return this; }; p5.Renderer2D.prototype.ellipse = function (x, y, w, h) { var ctx = this.drawingContext; var doFill = this._pInst._doFill, doStroke = this._pInst._doStroke; if (doFill && !doStroke) { if (ctx.fillStyle === styleEmpty) { return this; } } else if (!doFill && doStroke) { if (ctx.strokeStyle === styleEmpty) { return this; } } var vals = canvas.modeAdjust(x, y, w, h, this._pInst._ellipseMode); var kappa = 0.5522848, ox = vals.w / 2 * kappa, oy = vals.h / 2 * kappa, xe = vals.x + vals.w, ye = vals.y + vals.h, xm = vals.x + vals.w / 2, ym = vals.y + vals.h / 2; ctx.beginPath(); ctx.moveTo(vals.x, ym); ctx.bezierCurveTo(vals.x, ym - oy, xm - ox, vals.y, xm, vals.y); ctx.bezierCurveTo(xm + ox, vals.y, xe, ym - oy, xe, ym); ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); ctx.bezierCurveTo(xm - ox, ye, vals.x, ym + oy, vals.x, ym); ctx.closePath(); if (doFill) { ctx.fill(); } if (doStroke) { ctx.stroke(); } }; p5.Renderer2D.prototype.line = function (x1, y1, x2, y2) { var ctx = this.drawingContext; if (!this._pInst._doStroke) { return this; } else if (ctx.strokeStyle === styleEmpty) { return this; } if (ctx.lineWidth % 2 === 1) { ctx.translate(0.5, 0.5); } ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); if (ctx.lineWidth % 2 === 1) { ctx.translate(-0.5, -0.5); } return this; }; p5.Renderer2D.prototype.point = function (x, y) { var ctx = this.drawingContext; var s = ctx.strokeStyle; var f = ctx.fillStyle; if (!this._pInst._doStroke) { return this; } else if (ctx.strokeStyle === styleEmpty) { return this; } x = Math.round(x); y = Math.round(y); ctx.fillStyle = s; if (ctx.lineWidth > 1) { ctx.beginPath(); ctx.arc(x, y, ctx.lineWidth / 2, 0, constants.TWO_PI, false); ctx.fill(); } else { ctx.fillRect(x, y, 1, 1); } ctx.fillStyle = f; }; p5.Renderer2D.prototype.quad = function (x1, y1, x2, y2, x3, y3, x4, y4) { var ctx = this.drawingContext; var doFill = this._pInst._doFill, doStroke = this._pInst._doStroke; if (doFill && !doStroke) { if (ctx.fillStyle === styleEmpty) { return this; } } else if (!doFill && doStroke) { if (ctx.strokeStyle === styleEmpty) { return this; } } ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.lineTo(x3, y3); ctx.lineTo(x4, y4); ctx.closePath(); if (doFill) { ctx.fill(); } if (doStroke) { ctx.stroke(); } return this; }; p5.Renderer2D.prototype.rect = function (x, y, w, h, tl, tr, br, bl) { var ctx = this.drawingContext; var doFill = this._pInst._doFill, doStroke = this._pInst._doStroke; if (doFill && !doStroke) { if (ctx.fillStyle === styleEmpty) { return this; } } else if (!doFill && doStroke) { if (ctx.strokeStyle === styleEmpty) { return this; } } var vals = canvas.modeAdjust(x, y, w, h, this._pInst._rectMode); if (this._pInst._doStroke && ctx.lineWidth % 2 === 1) { ctx.translate(0.5, 0.5); } ctx.beginPath(); if (typeof tl === 'undefined') { ctx.rect(vals.x, vals.y, vals.w, vals.h); } else { if (typeof tr === 'undefined') { tr = tl; } if (typeof br === 'undefined') { br = tr; } if (typeof bl === 'undefined') { bl = br; } var _x = vals.x; var _y = vals.y; var _w = vals.w; var _h = vals.h; var hw = _w / 2; var hh = _h / 2; if (_w < 2 * tl) { tl = hw; } if (_h < 2 * tl) { tl = hh; } if (_w < 2 * tr) { tr = hw; } if (_h < 2 * tr) { tr = hh; } if (_w < 2 * br) { br = hw; } if (_h < 2 * br) { br = hh; } if (_w < 2 * bl) { bl = hw; } if (_h < 2 * bl) { bl = hh; } ctx.beginPath(); ctx.moveTo(_x + tl, _y); ctx.arcTo(_x + _w, _y, _x + _w, _y + _h, tr); ctx.arcTo(_x + _w, _y + _h, _x, _y + _h, br); ctx.arcTo(_x, _y + _h, _x, _y, bl); ctx.arcTo(_x, _y, _x + _w, _y, tl); ctx.closePath(); } if (this._pInst._doFill) { ctx.fill(); } if (this._pInst._doStroke) { ctx.stroke(); } if (this._pInst._doStroke && ctx.lineWidth % 2 === 1) { ctx.translate(-0.5, -0.5); } return this; }; p5.Renderer2D.prototype.triangle = function (x1, y1, x2, y2, x3, y3) { var ctx = this.drawingContext; var doFill = this._pInst._doFill, doStroke = this._pInst._doStroke; if (doFill && !doStroke) { if (ctx.fillStyle === styleEmpty) { return this; } } else if (!doFill && doStroke) { if (ctx.strokeStyle === styleEmpty) { return this; } } ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.lineTo(x3, y3); ctx.closePath(); if (doFill) { ctx.fill(); } if (doStroke) { ctx.stroke(); } }; p5.Renderer2D.prototype.endShape = function (mode, vertices, isCurve, isBezier, isQuadratic, isContour, shapeKind) { if (vertices.length === 0) { return this; } if (!this._pInst._doStroke && !this._pInst._doFill) { return this; } var closeShape = mode === constants.CLOSE; var v; if (closeShape && !isContour) { vertices.push(vertices[0]); } var i, j; var numVerts = vertices.length; if (isCurve && (shapeKind === constants.POLYGON || shapeKind === null)) { if (numVerts > 3) { var b = [], s = 1 - this._pInst._curveTightness; this.drawingContext.beginPath(); this.drawingContext.moveTo(vertices[1][0], vertices[1][1]); for (i = 1; i + 2 < numVerts; i++) { v = vertices[i]; b[0] = [ v[0], v[1] ]; b[1] = [ v[0] + (s * vertices[i + 1][0] - s * vertices[i - 1][0]) / 6, v[1] + (s * vertices[i + 1][1] - s * vertices[i - 1][1]) / 6 ]; b[2] = [ vertices[i + 1][0] + (s * vertices[i][0] - s * vertices[i + 2][0]) / 6, vertices[i + 1][1] + (s * vertices[i][1] - s * vertices[i + 2][1]) / 6 ]; b[3] = [ vertices[i + 1][0], vertices[i + 1][1] ]; this.drawingContext.bezierCurveTo(b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1]); } if (closeShape) { this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); } this._doFillStrokeClose(); } } else if (isBezier && (shapeKind === constants.POLYGON || shapeKind === null)) { this.drawingContext.beginPath(); for (i = 0; i < numVerts; i++) { if (vertices[i].isVert) { if (vertices[i].moveTo) { this.drawingContext.moveTo(vertices[i][0], vertices[i][1]); } else { this.drawingContext.lineTo(vertices[i][0], vertices[i][1]); } } else { this.drawingContext.bezierCurveTo(vertices[i][0], vertices[i][1], vertices[i][2], vertices[i][3], vertices[i][4], vertices[i][5]); } } this._doFillStrokeClose(); } else if (isQuadratic && (shapeKind === constants.POLYGON || shapeKind === null)) { this.drawingContext.beginPath(); for (i = 0; i < numVerts; i++) { if (vertices[i].isVert) { if (vertices[i].moveTo) { this.drawingContext.moveTo([0], vertices[i][1]); } else { this.drawingContext.lineTo(vertices[i][0], vertices[i][1]); } } else { this.drawingContext.quadraticCurveTo(vertices[i][0], vertices[i][1], vertices[i][2], vertices[i][3]); } } this._doFillStrokeClose(); } else { if (shapeKind === constants.POINTS) { for (i = 0; i < numVerts; i++) { v = vertices[i]; if (this._pInst._doStroke) { this._pInst.stroke(v[6]); } this._pInst.point(v[0], v[1]); } } else if (shapeKind === constants.LINES) { for (i = 0; i + 1 < numVerts; i += 2) { v = vertices[i]; if (this._pInst._doStroke) { this._pInst.stroke(vertices[i + 1][6]); } this._pInst.line(v[0], v[1], vertices[i + 1][0], vertices[i + 1][1]); } } else if (shapeKind === constants.TRIANGLES) { for (i = 0; i + 2 < numVerts; i += 3) { v = vertices[i]; this.drawingContext.beginPath(); this.drawingContext.moveTo(v[0], v[1]); this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]); this.drawingContext.lineTo(v[0], v[1]); if (this._pInst._doFill) { this._pInst.fill(vertices[i + 2][5]); this.drawingContext.fill(); } if (this._pInst._doStroke) { this._pInst.stroke(vertices[i + 2][6]); this.drawingContext.stroke(); } this.drawingContext.closePath(); } } else if (shapeKind === constants.TRIANGLE_STRIP) { for (i = 0; i + 1 < numVerts; i++) { v = vertices[i]; this.drawingContext.beginPath(); this.drawingContext.moveTo(vertices[i + 1][0], vertices[i + 1][1]); this.drawingContext.lineTo(v[0], v[1]); if (this._pInst._doStroke) { this._pInst.stroke(vertices[i + 1][6]); } if (this._pInst._doFill) { this._pInst.fill(vertices[i + 1][5]); } if (i + 2 < numVerts) { this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]); if (this._pInst._doStroke) { this._pInst.stroke(vertices[i + 2][6]); } if (this._pInst._doFill) { this._pInst.fill(vertices[i + 2][5]); } } this._doFillStrokeClose(); } } else if (shapeKind === constants.TRIANGLE_FAN) { if (numVerts > 2) { this.drawingContext.beginPath(); this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); this.drawingContext.lineTo(vertices[1][0], vertices[1][1]); this.drawingContext.lineTo(vertices[2][0], vertices[2][1]); if (this._pInst._doFill) { this._pInst.fill(vertices[2][5]); } if (this._pInst._doStroke) { this._pInst.stroke(vertices[2][6]); } this._doFillStrokeClose(); for (i = 3; i < numVerts; i++) { v = vertices[i]; this.drawingContext.beginPath(); this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); this.drawingContext.lineTo(vertices[i - 1][0], vertices[i - 1][1]); this.drawingContext.lineTo(v[0], v[1]); if (this._pInst._doFill) { this._pInst.fill(v[5]); } if (this._pInst._doStroke) { this._pInst.stroke(v[6]); } this._doFillStrokeClose(); } } } else if (shapeKind === constants.QUADS) { for (i = 0; i + 3 < numVerts; i += 4) { v = vertices[i]; this.drawingContext.beginPath(); this.drawingContext.moveTo(v[0], v[1]); for (j = 1; j < 4; j++) { this.drawingContext.lineTo(vertices[i + j][0], vertices[i + j][1]); } this.drawingContext.lineTo(v[0], v[1]); if (this._pInst._doFill) { this._pInst.fill(vertices[i + 3][5]); } if (this._pInst._doStroke) { this._pInst.stroke(vertices[i + 3][6]); } this._doFillStrokeClose(); } } else if (shapeKind === constants.QUAD_STRIP) { if (numVerts > 3) { for (i = 0; i + 1 < numVerts; i += 2) { v = vertices[i]; this.drawingContext.beginPath(); if (i + 3 < numVerts) { this.drawingContext.moveTo(vertices[i + 2][0], vertices[i + 2][1]); this.drawingContext.lineTo(v[0], v[1]); this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); this.drawingContext.lineTo(vertices[i + 3][0], vertices[i + 3][1]); if (this._pInst._doFill) { this._pInst.fill(vertices[i + 3][5]); } if (this._pInst._doStroke) { this._pInst.stroke(vertices[i + 3][6]); } } else { this.drawingContext.moveTo(v[0], v[1]); this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); } this._doFillStrokeClose(); } } } else { this.drawingContext.beginPath(); this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); for (i = 1; i < numVerts; i++) { v = vertices[i]; if (v.isVert) { if (v.moveTo) { this.drawingContext.moveTo(v[0], v[1]); } else { this.drawingContext.lineTo(v[0], v[1]); } } } this._doFillStrokeClose(); } } isCurve = false; isBezier = false; isQuadratic = false; isContour = false; if (closeShape) { vertices.pop(); } return this; }; p5.Renderer2D.prototype.noSmooth = function () { if ('imageSmoothingEnabled' in this.drawingContext) { this.drawingContext.imageSmoothingEnabled = false; } else if ('mozImageSmoothingEnabled' in this.drawingContext) { this.drawingContext.mozImageSmoothingEnabled = false; } else if ('webkitImageSmoothingEnabled' in this.drawingContext) { this.drawingContext.webkitImageSmoothingEnabled = false; } else if ('msImageSmoothingEnabled' in this.drawingContext) { this.drawingContext.msImageSmoothingEnabled = false; } return this; }; p5.Renderer2D.prototype.smooth = function () { if ('imageSmoothingEnabled' in this.drawingContext) { this.drawingContext.imageSmoothingEnabled = true; } else if ('mozImageSmoothingEnabled' in this.drawingContext) { this.drawingContext.mozImageSmoothingEnabled = true; } else if ('webkitImageSmoothingEnabled' in this.drawingContext) { this.drawingContext.webkitImageSmoothingEnabled = true; } else if ('msImageSmoothingEnabled' in this.drawingContext) { this.drawingContext.msImageSmoothingEnabled = true; } return this; }; p5.Renderer2D.prototype.strokeCap = function (cap) { if (cap === constants.ROUND || cap === constants.SQUARE || cap === constants.PROJECT) { this.drawingContext.lineCap = cap; } return this; }; p5.Renderer2D.prototype.strokeJoin = function (join) { if (join === constants.ROUND || join === constants.BEVEL || join === constants.MITER) { this.drawingContext.lineJoin = join; } return this; }; p5.Renderer2D.prototype.strokeWeight = function (w) { if (typeof w === 'undefined' || w === 0) { this.drawingContext.lineWidth = 0.0001; } else { this.drawingContext.lineWidth = w; } return this; }; p5.Renderer2D.prototype._getFill = function () { return this.drawingContext.fillStyle; }; p5.Renderer2D.prototype._getStroke = function () { return this.drawingContext.strokeStyle; }; p5.Renderer2D.prototype.bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) { this._pInst.beginShape(); this._pInst.vertex(x1, y1); this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4); this._pInst.endShape(); return this; }; p5.Renderer2D.prototype.curve = function (x1, y1, x2, y2, x3, y3, x4, y4) { this._pInst.beginShape(); this._pInst.curveVertex(x1, y1); this._pInst.curveVertex(x2, y2); this._pInst.curveVertex(x3, y3); this._pInst.curveVertex(x4, y4); this._pInst.endShape(); return this; }; p5.Renderer2D.prototype._doFillStrokeClose = function () { if (this._pInst._doFill) { this.drawingContext.fill(); } if (this._pInst._doStroke) { this.drawingContext.stroke(); } this.drawingContext.closePath(); }; p5.Renderer2D.prototype.applyMatrix = function (n00, n01, n02, n10, n11, n12) { this.drawingContext.transform(n00, n01, n02, n10, n11, n12); }; p5.Renderer2D.prototype.resetMatrix = function () { this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); return this; }; p5.Renderer2D.prototype.rotate = function (r) { this.drawingContext.rotate(r); }; p5.Renderer2D.prototype.scale = function () { var x = 1, y = 1; if (arguments.length === 1) { x = y = arguments[0]; } else { x = arguments[0]; y = arguments[1]; } this.drawingContext.scale(x, y); return this; }; p5.Renderer2D.prototype.shearX = function (angle) { if (this._pInst._angleMode === constants.DEGREES) { angle = this._pInst.radians(angle); } this.drawingContext.transform(1, 0, this._pInst.tan(angle), 1, 0, 0); return this; }; p5.Renderer2D.prototype.shearY = function (angle) { if (this._pInst._angleMode === constants.DEGREES) { angle = this._pInst.radians(angle); } this.drawingContext.transform(1, this._pInst.tan(angle), 0, 1, 0, 0); return this; }; p5.Renderer2D.prototype.translate = function (x, y) { this.drawingContext.translate(x, y); return this; }; p5.Renderer2D.prototype.text = function (str, x, y, maxWidth, maxHeight) { var p = this._pInst, cars, n, ii, jj, line, testLine, testWidth, words, totalHeight, baselineHacked; if (!(p._doFill || p._doStroke)) { return; } if (typeof str !== 'string') { str = str.toString(); } str = str.replace(/(\t)/g, ' '); cars = str.split('\n'); if (typeof maxWidth !== 'undefined') { totalHeight = 0; for (ii = 0; ii < cars.length; ii++) { line = ''; words = cars[ii].split(' '); for (n = 0; n < words.length; n++) { testLine = line + words[n] + ' '; testWidth = this.textWidth(testLine); if (testWidth > maxWidth) { line = words[n] + ' '; totalHeight += p.textLeading(); } else { line = testLine; } } } switch (this.drawingContext.textAlign) { case constants.CENTER: x += maxWidth / 2; break; case constants.RIGHT: x += maxWidth; break; } if (typeof maxHeight !== 'undefined') { switch (this.drawingContext.textBaseline) { case constants.BOTTOM: y += maxHeight - totalHeight; break; case constants._CTX_MIDDLE: y += (maxHeight - totalHeight) / 2; break; case constants.BASELINE: baselineHacked = true; this.drawingContext.textBaseline = constants.TOP; break; } } for (ii = 0; ii < cars.length; ii++) { line = ''; words = cars[ii].split(' '); for (n = 0; n < words.length; n++) { testLine = line + words[n] + ' '; testWidth = this.textWidth(testLine); if (testWidth > maxWidth) { this._renderText(p, line, x, y); line = words[n] + ' '; y += p.textLeading(); } else { line = testLine; } } this._renderText(p, line, x, y); y += p.textLeading(); } } else { for (jj = 0; jj < cars.length; jj++) { this._renderText(p, cars[jj], x, y); y += p.textLeading(); } } if (baselineHacked) { this.drawingContext.textBaseline = constants.BASELINE; } return p; }; p5.Renderer2D.prototype._renderText = function (p, line, x, y) { if (p._isOpenType()) { return p._textFont._renderPath(line, x, y); } if (p._doStroke && p._strokeSet) { this.drawingContext.strokeText(line, x, y); } if (p._doFill) { this.drawingContext.fillStyle = p._fillSet ? this.drawingContext.fillStyle : constants._DEFAULT_TEXT_FILL; this.drawingContext.fillText(line, x, y); } return p; }; p5.Renderer2D.prototype.textWidth = function (s) { if (this._pInst._isOpenType()) { return this._pInst._textFont._textWidth(s); } return this.drawingContext.measureText(s).width; }; p5.Renderer2D.prototype.textAlign = function (h, v) { if (arguments.length) { if (h === constants.LEFT || h === constants.RIGHT || h === constants.CENTER) { this.drawingContext.textAlign = h; } if (v === constants.TOP || v === constants.BOTTOM || v === constants.CENTER || v === constants.BASELINE) { if (v === constants.CENTER) { this.drawingContext.textBaseline = constants._CTX_MIDDLE; } else { this.drawingContext.textBaseline = v; } } return this._pInst; } else { var valign = this.drawingContext.textBaseline; if (valign === constants._CTX_MIDDLE) { valign = constants.CENTER; } return { horizontal: this.drawingContext.textAlign, vertical: valign }; } }; p5.Renderer2D.prototype._applyTextProperties = function () { var font, p = this._pInst; p._setProperty('_textAscent', null); p._setProperty('_textDescent', null); font = p._textFont; if (p._isOpenType()) { font = p._textFont.font.familyName; p._setProperty('_textStyle', p._textFont.font.styleName); } this.drawingContext.font = p._textStyle + ' ' + p._textSize + 'px ' + font; return p; }; p5.Renderer2D.prototype.push = function () { this.drawingContext.save(); }; p5.Renderer2D.prototype.pop = function () { this.drawingContext.restore(); }; return p5.Renderer2D; }({}, amdclean['core_core'], amdclean['core_canvas'], amdclean['core_constants'], amdclean['image_filters'], amdclean['core_p5Renderer']); amdclean['image_p5Image'] = function (require, core_core, image_filters) { 'use strict'; var p5 = core_core; var Filters = image_filters; p5.Image = function (width, height) { this.width = width; this.height = height; this.canvas = document.createElement('canvas'); this.canvas.width = this.width; this.canvas.height = this.height; this.drawingContext = this.canvas.getContext('2d'); this.pixelDensity = 1; this.pixels = []; }; p5.Image.prototype._setProperty = function (prop, value) { this[prop] = value; }; p5.Image.prototype.loadPixels = function () { p5.Renderer2D.prototype.loadPixels.call(this); }; p5.Image.prototype.updatePixels = function (x, y, w, h) { p5.Renderer2D.prototype.updatePixels.call(this, x, y, w, h); }; p5.Image.prototype.get = function (x, y, w, h) { return p5.Renderer2D.prototype.get.call(this, x, y, w, h); }; p5.Image.prototype.set = function (x, y, imgOrCol) { p5.Renderer2D.prototype.set.call(this, x, y, imgOrCol); }; p5.Image.prototype.resize = function (width, height) { width = width || this.canvas.width; height = height || this.canvas.height; var tempCanvas = document.createElement('canvas'); tempCanvas.width = width; tempCanvas.height = height; tempCanvas.getContext('2d').drawImage(this.canvas, 0, 0, this.canvas.width, this.canvas.height, 0, 0, tempCanvas.width, tempCanvas.height); this.canvas.width = this.width = width; this.canvas.height = this.height = height; this.drawingContext.drawImage(tempCanvas, 0, 0, width, height, 0, 0, width, height); if (this.pixels.length > 0) { this.loadPixels(); } }; p5.Image.prototype.copy = function () { p5.prototype.copy.apply(this, arguments); }; p5.Image.prototype.mask = function (p5Image) { if (p5Image === undefined) { p5Image = this; } var currBlend = this.drawingContext.globalCompositeOperation; var scaleFactor = 1; if (p5Image instanceof p5.Renderer) { scaleFactor = p5Image._pInst.pixelDensity; } var copyArgs = [ p5Image, 0, 0, scaleFactor * p5Image.width, scaleFactor * p5Image.height, 0, 0, this.width, this.height ]; this.drawingContext.globalCompositeOperation = 'destination-in'; this.copy.apply(this, copyArgs); this.drawingContext.globalCompositeOperation = currBlend; }; p5.Image.prototype.filter = function (operation, value) { Filters.apply(this.canvas, Filters[operation.toLowerCase()], value); }; p5.Image.prototype.blend = function () { p5.prototype.blend.apply(this, arguments); }; p5.Image.prototype.save = function (filename, extension) { 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 = this.canvas.toDataURL(mimeType); imageData = imageData.replace(mimeType, downloadMime); p5.prototype.downloadFile(imageData, filename, extension); }; return p5.Image; }({}, amdclean['core_core'], amdclean['image_filters']); amdclean['math_polargeometry'] = function (require) { return { degreesToRadians: function (x) { return 2 * Math.PI * x / 360; }, radiansToDegrees: function (x) { return 360 * x / (2 * Math.PI); } }; }({}); amdclean['math_p5Vector'] = function (require, core_core, math_polargeometry, core_constants) { 'use strict'; var p5 = core_core; var polarGeometry = math_polargeometry; var constants = core_constants; p5.Vector = function () { var x, y, z; if (arguments[0] instanceof p5) { this.p5 = arguments[0]; x = arguments[1][0] || 0; y = arguments[1][1] || 0; z = arguments[1][2] || 0; } else { x = arguments[0] || 0; y = arguments[1] || 0; z = arguments[2] || 0; } this.x = x; this.y = y; this.z = z; }; p5.Vector.prototype.toString = function p5VectorToString() { return 'p5.Vector Object : [' + this.x + ', ' + this.y + ', ' + this.z + ']'; }; p5.Vector.prototype.set = function (x, y, z) { if (x instanceof p5.Vector) { this.x = x.x || 0; this.y = x.y || 0; this.z = x.z || 0; return this; } if (x instanceof Array) { this.x = x[0] || 0; this.y = x[1] || 0; this.z = x[2] || 0; return this; } this.x = x || 0; this.y = y || 0; this.z = z || 0; return this; }; p5.Vector.prototype.copy = function () { if (this.p5) { return new p5.Vector(this.p5, [ this.x, this.y, this.z ]); } else { return new p5.Vector(this.x, this.y, this.z); } }; p5.Vector.prototype.add = function (x, y, z) { if (x instanceof p5.Vector) { this.x += x.x || 0; this.y += x.y || 0; this.z += x.z || 0; return this; } if (x instanceof Array) { this.x += x[0] || 0; this.y += x[1] || 0; this.z += x[2] || 0; return this; } this.x += x || 0; this.y += y || 0; this.z += z || 0; return this; }; p5.Vector.prototype.sub = function (x, y, z) { if (x instanceof p5.Vector) { this.x -= x.x || 0; this.y -= x.y || 0; this.z -= x.z || 0; return this; } if (x instanceof Array) { this.x -= x[0] || 0; this.y -= x[1] || 0; this.z -= x[2] || 0; return this; } this.x -= x || 0; this.y -= y || 0; this.z -= z || 0; return this; }; p5.Vector.prototype.mult = function (n) { this.x *= n || 0; this.y *= n || 0; this.z *= n || 0; return this; }; p5.Vector.prototype.div = function (n) { this.x /= n; this.y /= n; this.z /= n; return this; }; p5.Vector.prototype.mag = function () { return Math.sqrt(this.magSq()); }; p5.Vector.prototype.magSq = function () { var x = this.x, y = this.y, z = this.z; return x * x + y * y + z * z; }; p5.Vector.prototype.dot = function (x, y, z) { if (x instanceof p5.Vector) { return this.dot(x.x, x.y, x.z); } return this.x * (x || 0) + this.y * (y || 0) + this.z * (z || 0); }; p5.Vector.prototype.cross = function (v) { var x = this.y * v.z - this.z * v.y; var y = this.z * v.x - this.x * v.z; var z = this.x * v.y - this.y * v.x; if (this.p5) { return new p5.Vector(this.p5, [ x, y, z ]); } else { return new p5.Vector(x, y, z); } }; p5.Vector.prototype.dist = function (v) { var d = v.copy().sub(this); return d.mag(); }; p5.Vector.prototype.normalize = function () { return this.div(this.mag()); }; p5.Vector.prototype.limit = function (l) { var mSq = this.magSq(); if (mSq > l * l) { this.div(Math.sqrt(mSq)); this.mult(l); } return this; }; p5.Vector.prototype.setMag = function (n) { return this.normalize().mult(n); }; p5.Vector.prototype.heading = function () { var h = Math.atan2(this.y, this.x); if (this.p5) { if (this.p5._angleMode === constants.RADIANS) { return h; } else { return polarGeometry.radiansToDegrees(h); } } else { return h; } }; p5.Vector.prototype.rotate = function (a) { if (this.p5) { if (this.p5._angleMode === constants.DEGREES) { a = polarGeometry.degreesToRadians(a); } } var newHeading = this.heading() + a; var mag = this.mag(); this.x = Math.cos(newHeading) * mag; this.y = Math.sin(newHeading) * mag; return this; }; p5.Vector.prototype.lerp = function (x, y, z, amt) { if (x instanceof p5.Vector) { return this.lerp(x.x, x.y, x.z, y); } this.x += (x - this.x) * amt || 0; this.y += (y - this.y) * amt || 0; this.z += (z - this.z) * amt || 0; return this; }; p5.Vector.prototype.array = function () { return [ this.x || 0, this.y || 0, this.z || 0 ]; }; p5.Vector.prototype.equals = function (x, y, z) { var a, b, c; if (x instanceof p5.Vector) { a = x.x || 0; b = x.y || 0; c = x.z || 0; } else if (x instanceof Array) { a = x[0] || 0; b = x[1] || 0; c = x[2] || 0; } else { a = x || 0; b = y || 0; c = z || 0; } return this.x === a && this.y === b && this.z === c; }; p5.Vector.fromAngle = function (angle) { if (this.p5) { if (this.p5._angleMode === constants.DEGREES) { angle = polarGeometry.degreesToRadians(angle); } } if (this.p5) { return new p5.Vector(this.p5, [ Math.cos(angle), Math.sin(angle), 0 ]); } else { return new p5.Vector(Math.cos(angle), Math.sin(angle), 0); } }; p5.Vector.random2D = function () { var angle; if (this.p5) { if (this.p5._angleMode === constants.DEGREES) { angle = this.p5.random(360); } else { angle = this.p5.random(constants.TWO_PI); } } else { angle = Math.random() * Math.PI * 2; } return this.fromAngle(angle); }; p5.Vector.random3D = function () { var angle, vz; if (this.p5) { angle = this.p5.random(0, constants.TWO_PI); vz = this.p5.random(-1, 1); } else { angle = Math.random() * Math.PI * 2; vz = Math.random() * 2 - 1; } var vx = Math.sqrt(1 - vz * vz) * Math.cos(angle); var vy = Math.sqrt(1 - vz * vz) * Math.sin(angle); if (this.p5) { return new p5.Vector(this.p5, [ vx, vy, vz ]); } else { return new p5.Vector(vx, vy, vz); } }; p5.Vector.add = function (v1, v2, target) { if (!target) { target = v1.copy(); } else { target.set(v1); } target.add(v2); return target; }; p5.Vector.sub = function (v1, v2, target) { if (!target) { target = v1.copy(); } else { target.set(v1); } target.sub(v2); return target; }; p5.Vector.mult = function (v, n, target) { if (!target) { target = v.copy(); } else { target.set(v); } target.mult(n); return target; }; p5.Vector.div = function (v, n, target) { if (!target) { target = v.copy(); } else { target.set(v); } target.div(n); return target; }; p5.Vector.dot = function (v1, v2) { return v1.dot(v2); }; p5.Vector.cross = function (v1, v2) { return v1.cross(v2); }; p5.Vector.dist = function (v1, v2) { return v1.dist(v2); }; p5.Vector.lerp = function (v1, v2, amt, target) { if (!target) { target = v1.copy(); } else { target.set(v1); } target.lerp(v2, amt); return target; }; p5.Vector.angleBetween = function (v1, v2) { var angle = Math.acos(v1.dot(v2) / (v1.mag() * v2.mag())); if (this.p5) { if (this.p5._angleMode === constants.DEGREES) { angle = polarGeometry.radiansToDegrees(angle); } } return angle; }; return p5.Vector; }({}, amdclean['core_core'], amdclean['math_polargeometry'], amdclean['core_constants']); amdclean['io_p5TableRow'] = function (require, core_core) { 'use strict'; var p5 = core_core; p5.TableRow = function (str, separator) { var arr = []; var obj = {}; if (str) { separator = separator || ','; arr = str.split(separator); } for (var i = 0; i < arr.length; i++) { var key = i; var val = arr[i]; obj[key] = val; } this.arr = arr; this.obj = obj; this.table = null; }; p5.TableRow.prototype.set = function (column, value) { if (typeof column === 'string') { var cPos = this.table.columns.indexOf(column); if (cPos >= 0) { this.obj[column] = value; this.arr[cPos] = value; } else { throw 'This table has no column named "' + column + '"'; } } else { if (column < this.table.columns.length) { this.arr[column] = value; var cTitle = this.table.columns[column]; this.obj[cTitle] = value; } else { throw 'Column #' + column + ' is out of the range of this table'; } } }; p5.TableRow.prototype.setNum = function (column, value) { var floatVal = parseFloat(value, 10); this.set(column, floatVal); }; p5.TableRow.prototype.setString = function (column, value) { var stringVal = value.toString(); this.set(column, stringVal); }; p5.TableRow.prototype.get = function (column) { if (typeof column === 'string') { return this.obj[column]; } else { return this.arr[column]; } }; p5.TableRow.prototype.getNum = function (column) { var ret; if (typeof column === 'string') { ret = parseFloat(this.obj[column], 10); } else { ret = parseFloat(this.arr[column], 10); } if (ret.toString() === 'NaN') { throw 'Error: ' + this.obj[column] + ' is NaN (Not a Number)'; } return ret; }; p5.TableRow.prototype.getString = function (column) { if (typeof column === 'string') { return this.obj[column].toString(); } else { return this.arr[column].toString(); } }; return p5.TableRow; }({}, amdclean['core_core']); amdclean['io_p5Table'] = function (require, core_core) { 'use strict'; var p5 = core_core; p5.Table = function (rows) { this.columns = []; this.rows = []; }; p5.Table.prototype.addRow = function (row) { var r = row || new p5.TableRow(); if (typeof r.arr === 'undefined' || typeof r.obj === 'undefined') { throw 'invalid TableRow: ' + r; } r.table = this; this.rows.push(r); return r; }; p5.Table.prototype.removeRow = function (id) { this.rows[id].table = null; var chunk = this.rows.splice(id + 1, this.rows.length); this.rows.pop(); this.rows = this.rows.concat(chunk); }; p5.Table.prototype.getRow = function (r) { return this.rows[r]; }; p5.Table.prototype.getRows = function () { return this.rows; }; p5.Table.prototype.findRow = function (value, column) { if (typeof column === 'string') { for (var i = 0; i < this.rows.length; i++) { if (this.rows[i].obj[column] === value) { return this.rows[i]; } } } else { for (var j = 0; j < this.rows.length; j++) { if (this.rows[j].arr[column] === value) { return this.rows[j]; } } } return null; }; p5.Table.prototype.findRows = function (value, column) { var ret = []; if (typeof column === 'string') { for (var i = 0; i < this.rows.length; i++) { if (this.rows[i].obj[column] === value) { ret.push(this.rows[i]); } } } else { for (var j = 0; j < this.rows.length; j++) { if (this.rows[j].arr[column] === value) { ret.push(this.rows[j]); } } } return ret; }; p5.Table.prototype.matchRow = function (regexp, column) { if (typeof column === 'number') { for (var j = 0; j < this.rows.length; j++) { if (this.rows[j].arr[column].match(regexp)) { return this.rows[j]; } } } else { for (var i = 0; i < this.rows.length; i++) { if (this.rows[i].obj[column].match(regexp)) { return this.rows[i]; } } } return null; }; p5.Table.prototype.matchRows = function (regexp, column) { var ret = []; if (typeof column === 'number') { for (var j = 0; j < this.rows.length; j++) { if (this.rows[j].arr[column].match(regexp)) { ret.push(this.rows[j]); } } } else { for (var i = 0; i < this.rows.length; i++) { if (this.rows[i].obj[column].match(regexp)) { ret.push(this.rows[i]); } } } return ret; }; p5.Table.prototype.getColumn = function (value) { var ret = []; if (typeof value === 'string') { for (var i = 0; i < this.rows.length; i++) { ret.push(this.rows[i].obj[value]); } } else { for (var j = 0; j < this.rows.length; j++) { ret.push(this.rows[j].arr[value]); } } return ret; }; p5.Table.prototype.clearRows = function () { delete this.rows; this.rows = []; }; p5.Table.prototype.addColumn = function (title) { var t = title || null; this.columns.push(t); }; p5.Table.prototype.getColumnCount = function () { return this.columns.length; }; p5.Table.prototype.getRowCount = function () { return this.rows.length; }; p5.Table.prototype.removeTokens = function (chars, column) { var escape = function (s) { return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); }; var charArray = []; for (var i = 0; i < chars.length; i++) { charArray.push(escape(chars.charAt(i))); } var regex = new RegExp(charArray.join('|'), 'g'); if (typeof column === 'undefined') { for (var c = 0; c < this.columns.length; c++) { for (var d = 0; d < this.rows.length; d++) { var s = this.rows[d].arr[c]; s = s.replace(regex, ''); this.rows[d].arr[c] = s; this.rows[d].obj[this.columns[c]] = s; } } } else if (typeof column === 'string') { for (var j = 0; j < this.rows.length; j++) { var val = this.rows[j].obj[column]; val = val.replace(regex, ''); this.rows[j].obj[column] = val; var pos = this.columns.indexOf(column); this.rows[j].arr[pos] = val; } } else { for (var k = 0; k < this.rows.length; k++) { var str = this.rows[k].arr[column]; str = str.replace(regex, ''); this.rows[k].arr[column] = str; this.rows[k].obj[this.columns[column]] = str; } } }; p5.Table.prototype.trim = function (column) { var regex = new RegExp(' ', 'g'); if (typeof column === 'undefined') { for (var c = 0; c < this.columns.length; c++) { for (var d = 0; d < this.rows.length; d++) { var s = this.rows[d].arr[c]; s = s.replace(regex, ''); this.rows[d].arr[c] = s; this.rows[d].obj[this.columns[c]] = s; } } } else if (typeof column === 'string') { for (var j = 0; j < this.rows.length; j++) { var val = this.rows[j].obj[column]; val = val.replace(regex, ''); this.rows[j].obj[column] = val; var pos = this.columns.indexOf(column); this.rows[j].arr[pos] = val; } } else { for (var k = 0; k < this.rows.length; k++) { var str = this.rows[k].arr[column]; str = str.replace(regex, ''); this.rows[k].arr[column] = str; this.rows[k].obj[this.columns[column]] = str; } } }; p5.Table.prototype.removeColumn = function (c) { var cString; var cNumber; if (typeof c === 'string') { cString = c; cNumber = this.columns.indexOf(c); console.log('string'); } else { cNumber = c; cString = this.columns[c]; } var chunk = this.columns.splice(cNumber + 1, this.columns.length); this.columns.pop(); this.columns = this.columns.concat(chunk); for (var i = 0; i < this.rows.length; i++) { var tempR = this.rows[i].arr; var chip = tempR.splice(cNumber + 1, tempR.length); tempR.pop(); this.rows[i].arr = tempR.concat(chip); delete this.rows[i].obj[cString]; } }; p5.Table.prototype.set = function (row, column, value) { this.rows[row].set(column, value); }; p5.Table.prototype.setNum = function (row, column, value) { this.rows[row].set(column, value); }; p5.Table.prototype.setString = function (row, column, value) { this.rows[row].set(column, value); }; p5.Table.prototype.get = function (row, column) { return this.rows[row].get(column); }; p5.Table.prototype.getNum = function (row, column) { return this.rows[row].getNum(column); }; p5.Table.prototype.getString = function (row, column) { return this.rows[row].getString(column); }; p5.Table.prototype.getObject = function (headerColumn) { var tableObject = {}; var obj, cPos, index; for (var i = 0; i < this.rows.length; i++) { obj = this.rows[i].obj; if (typeof headerColumn === 'string') { cPos = this.columns.indexOf(headerColumn); if (cPos >= 0) { index = obj[headerColumn]; tableObject[index] = obj; } else { throw 'This table has no column named "' + headerColumn + '"'; } } else { tableObject[i] = this.rows[i].obj; } } return tableObject; }; p5.Table.prototype.getArray = function () { var tableArray = []; for (var i = 0; i < this.rows.length; i++) { tableArray.push(this.rows[i].arr); } return tableArray; }; return p5.Table; }({}, amdclean['core_core']); amdclean['color_creating_reading'] = function (require, core_core, color_p5Color) { 'use strict'; var p5 = core_core; p5.prototype.alpha = function (c) { if (c instanceof p5.Color || c instanceof Array) { return this.color(c).getAlpha(); } else { throw new Error('Needs p5.Color or pixel array as argument.'); } }; p5.prototype.blue = function (c) { if (c instanceof p5.Color || c instanceof Array) { return this.color(c).getBlue(); } else { throw new Error('Needs p5.Color or pixel array as argument.'); } }; p5.prototype.brightness = function (c) { if (c instanceof p5.Color || c instanceof Array) { return this.color(c).getBrightness(); } else { throw new Error('Needs p5.Color or pixel array as argument.'); } }; p5.prototype.color = function () { if (arguments[0] instanceof p5.Color) { return arguments[0]; } else if (arguments[0] instanceof Array) { return new p5.Color(this, arguments[0]); } else { var args = Array.prototype.slice.call(arguments); return new p5.Color(this, args); } }; p5.prototype.green = function (c) { if (c instanceof p5.Color || c instanceof Array) { return this.color(c).getGreen(); } else { throw new Error('Needs p5.Color or pixel array as argument.'); } }; p5.prototype.hue = function (c) { if (!c instanceof p5.Color) { throw new Error('Needs p5.Color as argument.'); } return c.getHue(); }; p5.prototype.lerpColor = function (c1, c2, amt) { amt = Math.max(Math.min(amt, 1), 0); if (c1 instanceof Array) { var c = []; for (var i = 0; i < c1.length; i++) { c.push(Math.sqrt(p5.prototype.lerp(c1[i] * c1[i], c2[i] * c2[i], amt))); } return c; } else if (c1 instanceof p5.Color) { var pc = []; for (var j = 0; j < 4; j++) { pc.push(Math.sqrt(p5.prototype.lerp(c1.rgba[j] * c1.rgba[j], c2.rgba[j] * c2.rgba[j], amt))); } return new p5.Color(this, pc); } else { return Math.sqrt(p5.prototype.lerp(c1 * c1, c2 * c2, amt)); } }; p5.prototype.lightness = function (c) { if (c instanceof p5.Color || c instanceof Array) { return this.color(c).getLightness(); } else { throw new Error('Needs p5.Color or pixel array as argument.'); } }; p5.prototype.red = function (c) { if (c instanceof p5.Color || c instanceof Array) { return this.color(c).getRed(); } else { throw new Error('Needs p5.Color or pixel array as argument.'); } }; p5.prototype.saturation = function (c) { if (!c instanceof p5.Color) { throw new Error('Needs p5.Color as argument.'); } return c.getSaturation(); }; return p5; }({}, amdclean['core_core'], amdclean['color_p5Color']); amdclean['color_setting'] = function (require, core_core, core_constants, color_p5Color) { 'use strict'; var p5 = core_core; var constants = core_constants; p5.prototype._doStroke = true; p5.prototype._doFill = true; p5.prototype._strokeSet = false; p5.prototype._fillSet = false; p5.prototype._colorMode = constants.RGB; p5.prototype._colorMaxes = { rgb: [ 255, 255, 255, 255 ], hsb: [ 360, 100, 100, 1 ], hsl: [ 360, 100, 100, 1 ] }; p5.prototype.background = function () { if (arguments[0] instanceof p5.Image) { this.image(arguments[0], 0, 0, this.width, this.height); } else { this._graphics.background.apply(this._graphics, arguments); } return this; }; p5.prototype.clear = function () { this._graphics.clear(); return this; }; p5.prototype.colorMode = function () { if (arguments[0] === constants.RGB || arguments[0] === constants.HSB || arguments[0] === constants.HSL) { this._colorMode = arguments[0]; var maxArr = this._colorMaxes[this._colorMode]; if (arguments.length === 2) { maxArr[0] = arguments[1]; maxArr[1] = arguments[1]; maxArr[2] = arguments[1]; maxArr[3] = arguments[1]; } else if (arguments.length > 2) { maxArr[0] = arguments[1]; maxArr[1] = arguments[2]; maxArr[2] = arguments[3]; } if (arguments.length === 5) { maxArr[3] = arguments[4]; } } return this; }; p5.prototype.fill = function () { this._setProperty('_fillSet', true); this._setProperty('_doFill', true); this._graphics.fill.apply(this._graphics, arguments); return this; }; p5.prototype.noFill = function () { this._setProperty('_doFill', false); return this; }; p5.prototype.noStroke = function () { this._setProperty('_doStroke', false); return this; }; p5.prototype.stroke = function () { this._setProperty('_strokeSet', true); this._setProperty('_doStroke', true); this._graphics.stroke.apply(this._graphics, arguments); return this; }; return p5; }({}, amdclean['core_core'], amdclean['core_constants'], amdclean['color_p5Color']); amdclean['utilities_conversion'] = function (require, core_core) { 'use strict'; var p5 = core_core; p5.prototype.float = function (str) { return parseFloat(str); }; p5.prototype.int = function (n, radix) { if (typeof n === 'string') { radix = radix || 10; return parseInt(n, radix); } else if (typeof n === 'number') { return n | 0; } else if (typeof n === 'boolean') { return n ? 1 : 0; } else if (n instanceof Array) { return n.map(function (n) { return p5.prototype.int(n, radix); }); } }; p5.prototype.str = function (n) { if (n instanceof Array) { return n.map(p5.prototype.str); } else { return String(n); } }; p5.prototype.boolean = function (n) { if (typeof n === 'number') { return n !== 0; } else if (typeof n === 'string') { return n.toLowerCase() === 'true'; } else if (typeof n === 'boolean') { return n; } else if (n instanceof Array) { return n.map(p5.prototype.boolean); } }; p5.prototype.byte = function (n) { var nn = p5.prototype.int(n, 10); if (typeof nn === 'number') { return (nn + 128) % 256 - 128; } else if (nn instanceof Array) { return nn.map(p5.prototype.byte); } }; p5.prototype.char = function (n) { if (typeof n === 'number' && !isNaN(n)) { return String.fromCharCode(n); } else if (n instanceof Array) { return n.map(p5.prototype.char); } else if (typeof n === 'string') { return p5.prototype.char(parseInt(n, 10)); } }; p5.prototype.unchar = function (n) { if (typeof n === 'string' && n.length === 1) { return n.charCodeAt(0); } else if (n instanceof Array) { return n.map(p5.prototype.unchar); } }; p5.prototype.hex = function (n, digits) { digits = digits === undefined || digits === null ? digits = 8 : digits; if (n instanceof Array) { return n.map(function (n) { return p5.prototype.hex(n, digits); }); } else if (typeof n === 'number') { if (n < 0) { n = 4294967295 + n + 1; } var hex = Number(n).toString(16).toUpperCase(); while (hex.length < digits) { hex = '0' + hex; } if (hex.length >= digits) { hex = hex.substring(hex.length - digits, hex.length); } return hex; } }; p5.prototype.unhex = function (n) { if (n instanceof Array) { return n.map(p5.prototype.unhex); } else { return parseInt('0x' + n, 16); } }; return p5; }({}, amdclean['core_core']); amdclean['utilities_array_functions'] = function (require, core_core) { 'use strict'; var p5 = core_core; p5.prototype.append = function (array, value) { array.push(value); return array; }; p5.prototype.arrayCopy = function (src, srcPosition, dst, dstPosition, length) { var start, end; if (typeof length !== 'undefined') { end = Math.min(length, src.length); start = dstPosition; src = src.slice(srcPosition, end + srcPosition); } else { if (typeof dst !== 'undefined') { end = dst; end = Math.min(end, src.length); } else { end = src.length; } start = 0; dst = srcPosition; src = src.slice(0, end); } Array.prototype.splice.apply(dst, [ start, end ].concat(src)); }; p5.prototype.concat = function (list0, list1) { return list0.concat(list1); }; p5.prototype.reverse = function (list) { return list.reverse(); }; p5.prototype.shorten = function (list) { list.pop(); return list; }; p5.prototype.shuffle = function (arr, bool) { arr = bool || ArrayBuffer.isView(arr) ? arr : arr.slice(); var rnd, tmp, idx = arr.length; while (idx > 1) { rnd = Math.random() * idx | 0; tmp = arr[--idx]; arr[idx] = arr[rnd]; arr[rnd] = tmp; } return arr; }; p5.prototype.sort = function (list, count) { var arr = count ? list.slice(0, Math.min(count, list.length)) : list; var rest = count ? list.slice(Math.min(count, list.length)) : []; if (typeof arr[0] === 'string') { arr = arr.sort(); } else { arr = arr.sort(function (a, b) { return a - b; }); } return arr.concat(rest); }; p5.prototype.splice = function (list, value, index) { Array.prototype.splice.apply(list, [ index, 0 ].concat(value)); return list; }; p5.prototype.subset = function (list, start, count) { if (typeof count !== 'undefined') { return list.slice(start, start + count); } else { return list.slice(start, list.length); } }; return p5; }({}, amdclean['core_core']); amdclean['utilities_string_functions'] = function (require, core_core) { 'use strict'; var p5 = core_core; p5.prototype.join = function (list, separator) { return list.join(separator); }; p5.prototype.match = function (str, reg) { return str.match(reg); }; p5.prototype.matchAll = function (str, reg) { var re = new RegExp(reg, 'g'); var match = re.exec(str); var matches = []; while (match !== null) { matches.push(match); match = re.exec(str); } return matches; }; p5.prototype.nf = function () { if (arguments[0] instanceof Array) { var a = arguments[1]; var b = arguments[2]; return arguments[0].map(function (x) { return doNf(x, a, b); }); } else { var typeOfFirst = Object.prototype.toString.call(arguments[0]); if (typeOfFirst === '[object Arguments]') { if (arguments[0].length === 3) { return this.nf(arguments[0][0], arguments[0][1], arguments[0][2]); } else if (arguments[0].length === 2) { return this.nf(arguments[0][0], arguments[0][1]); } else { return this.nf(arguments[0][0]); } } else { return doNf.apply(this, arguments); } } }; function doNf() { var num = arguments[0]; var neg = num < 0; var n = neg ? num.toString().substring(1) : num.toString(); var decimalInd = n.indexOf('.'); var intPart = decimalInd !== -1 ? n.substring(0, decimalInd) : n; var decPart = decimalInd !== -1 ? n.substring(decimalInd + 1) : ''; var str = neg ? '-' : ''; if (arguments.length === 3) { var decimal = ''; if (decimalInd !== -1 || arguments[2] - decPart.length > 0) { decimal = '.'; } if (decPart.length > arguments[2]) { decPart = decPart.substring(0, arguments[2]); } for (var i = 0; i < arguments[1] - intPart.length; i++) { str += '0'; } str += intPart; str += decimal; str += decPart; for (var j = 0; j < arguments[2] - decPart.length; j++) { str += '0'; } return str; } else { for (var k = 0; k < Math.max(arguments[1] - intPart.length, 0); k++) { str += '0'; } str += n; return str; } } p5.prototype.nfc = function () { if (arguments[0] instanceof Array) { var a = arguments[1]; return arguments[0].map(function (x) { return doNfc(x, a); }); } else { return doNfc.apply(this, arguments); } }; function doNfc() { var num = arguments[0].toString(); var dec = num.indexOf('.'); var rem = dec !== -1 ? num.substring(dec) : ''; var n = dec !== -1 ? num.substring(0, dec) : num; n = n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); if (arguments[1] === 0) { rem = ''; } else if (arguments[1] !== undefined) { if (arguments[1] > rem.length) { rem += dec === -1 ? '.' : ''; var len = arguments[1] - rem.length + 1; for (var i = 0; i < len; i++) { rem += '0'; } } else { rem = rem.substring(0, arguments[1] + 1); } } return n + rem; } p5.prototype.nfp = function () { var nfRes = this.nf.apply(this, arguments); if (nfRes instanceof Array) { return nfRes.map(addNfp); } else { return addNfp(nfRes); } }; function addNfp() { return parseFloat(arguments[0]) > 0 ? '+' + arguments[0].toString() : arguments[0].toString(); } p5.prototype.nfs = function () { var nfRes = this.nf.apply(this, arguments); if (nfRes instanceof Array) { return nfRes.map(addNfs); } else { return addNfs(nfRes); } }; function addNfs() { return parseFloat(arguments[0]) > 0 ? ' ' + arguments[0].toString() : arguments[0].toString(); } p5.prototype.split = function (str, delim) { return str.split(delim); }; p5.prototype.splitTokens = function () { var d = arguments.length > 0 ? arguments[1] : /\s/g; return arguments[0].split(d).filter(function (n) { return n; }); }; p5.prototype.trim = function (str) { if (str instanceof Array) { return str.map(this.trim); } else { return str.trim(); } }; return p5; }({}, amdclean['core_core']); amdclean['core_environment'] = function (require, core_core, core_constants) { 'use strict'; var p5 = core_core; var C = core_constants; var standardCursors = [ C.ARROW, C.CROSS, C.HAND, C.MOVE, C.TEXT, C.WAIT ]; p5.prototype._frameRate = 0; p5.prototype._lastFrameTime = window.performance.now(); p5.prototype._targetFrameRate = 60; if (window.console && console.log) { p5.prototype.print = function (args) { try { var newArgs = JSON.parse(JSON.stringify(args)); console.log(newArgs); } catch (err) { console.log(args); } }; } else { p5.prototype.print = function () { }; } p5.prototype.println = p5.prototype.print; p5.prototype.frameCount = 0; p5.prototype.focused = document.hasFocus(); p5.prototype.cursor = function (type, x, y) { var cursor = 'auto'; var canvas = this._curElement.elt; if (standardCursors.indexOf(type) > -1) { cursor = type; } else if (typeof type === 'string') { var coords = ''; if (x && y && (typeof x === 'number' && typeof y === 'number')) { coords = x + ' ' + y; } if (type.substring(0, 6) !== 'http://') { cursor = 'url(' + type + ') ' + coords + ', auto'; } else if (/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(type)) { cursor = 'url(' + type + ') ' + coords + ', auto'; } else { cursor = type; } } canvas.style.cursor = cursor; }; p5.prototype.frameRate = function (fps) { if (typeof fps === 'undefined') { return this._frameRate; } else { this._setProperty('_targetFrameRate', fps); this._runFrames(); return this; } }; p5.prototype.getFrameRate = function () { return this.frameRate(); }; p5.prototype.setFrameRate = function (fps) { return this.frameRate(fps); }; p5.prototype.noCursor = function () { this._curElement.elt.style.cursor = 'none'; }; p5.prototype.displayWidth = screen.width; p5.prototype.displayHeight = screen.height; p5.prototype.windowWidth = window.innerWidth; p5.prototype.windowHeight = window.innerHeight; p5.prototype._onresize = function (e) { this._setProperty('windowWidth', window.innerWidth); this._setProperty('windowHeight', window.innerHeight); var context = this._isGlobal ? window : this; var executeDefault; if (typeof context.windowResized === 'function') { executeDefault = context.windowResized(e); if (executeDefault !== undefined && !executeDefault) { e.preventDefault(); } } }; p5.prototype.width = 0; p5.prototype.height = 0; p5.prototype.fullscreen = function (val) { if (typeof val === 'undefined') { return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement; } else { if (val) { launchFullscreen(document.documentElement); } else { exitFullscreen(); } } }; p5.prototype.devicePixelScaling = function (val) { if (val) { if (typeof val === 'number') { this.pixelDensity = val; } else { this.pixelDensity = window.devicePixelRatio || 1; } } else { this.pixelDensity = 1; } this.resizeCanvas(this.width, this.height, true); }; function launchFullscreen(element) { var enabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled; if (!enabled) { throw new Error('Fullscreen not enabled in this browser.'); } if (element.requestFullscreen) { element.requestFullscreen(); } else if (element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if (element.webkitRequestFullscreen) { element.webkitRequestFullscreen(); } else if (element.msRequestFullscreen) { element.msRequestFullscreen(); } } function exitFullscreen() { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } p5.prototype.getURL = function () { return location.href; }; p5.prototype.getURLPath = function () { return location.pathname.split('/').filter(function (v) { return v !== ''; }); }; p5.prototype.getURLParams = function () { var re = /[?&]([^&=]+)(?:[&=])([^&=]+)/gim; var m; var v = {}; while ((m = re.exec(location.search)) != null) { if (m.index === re.lastIndex) { re.lastIndex++; } v[m[1]] = m[2]; } return v; }; return p5; }({}, amdclean['core_core'], amdclean['core_constants']); amdclean['image_image'] = function (require, core_core, core_constants) { 'use strict'; var p5 = core_core; var constants = core_constants; p5.prototype._imageMode = constants.CORNER; p5.prototype._tint = null; p5.prototype.createImage = function (width, height) { return new p5.Image(width, height); }; var frames = []; p5.prototype.saveCanvas = function (filename, extension, selectedCanvas) { if (!extension) { extension = p5.prototype._checkFileExtension(filename, extension)[1]; if (extension === '') { extension = 'png'; } } var cnv; if (selectedCanvas) { cnv = selectedCanvas; } 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 (typeof extension === 'undefined') { extension = 'png'; mimeType = 'image/png'; } else { switch (extension) { 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; }({}, amdclean['core_core'], amdclean['core_constants']); amdclean['core_error_helpers'] = function (require, core_core) { 'use strict'; var p5 = core_core; var doFriendlyWelcome = true; var class2type = {}; var toString = class2type.toString; var names = [ 'Boolean', 'Number', 'String', 'Function', 'Array', 'Date', 'RegExp', 'Object', 'Error' ]; for (var n = 0; n < names.length; n++) { class2type['[object ' + names[n] + ']'] = names[n].toLowerCase(); } var getType = function (obj) { if (obj == null) { return obj + ''; } return typeof obj === 'object' || typeof obj === 'function' ? class2type[toString.call(obj)] || 'object' : typeof obj; }; var isArray = Array.isArray || function (obj) { return getType(obj) === 'array'; }; var isNumeric = function (obj) { return !isArray(obj) && obj - parseFloat(obj) + 1 >= 0; }; var numberTypes = [ 'Number', 'Integer', 'Number/Constant' ]; function typeMatches(defType, argType, arg) { if (defType.match(/^p5\./)) { var parts = defType.split('.'); return arg instanceof p5[parts[1]]; } return defType === 'Boolean' || defType.toLowerCase() === argType || numberTypes.indexOf(defType) > -1 && isNumeric(arg); } var PARAM_COUNT = 0; var EMPTY_VAR = 1; var WRONG_TYPE = 2; var FILE_LOAD = 3; var typeColors = [ '#2D7BB6', '#EE9900', '#4DB200', '#C83C00' ]; function report(message, func, color) { if (doFriendlyWelcome) { friendlyWelcome(); doFriendlyWelcome = false; } if ('undefined' === getType(color)) { color = '#B40033'; } else if (getType(color) === 'number') { color = typeColors[color]; } if (func.substring(0, 4) === 'load') { console.log('%c> p5.js says: ' + message + '%c' + '[https://github.com/processing/p5.js/wiki/Local-server]', 'background-color:' + color + ';color:#FFF;', 'background-color:transparent;color:' + color + ';', 'background-color:' + color + ';color:#FFF;', 'background-color:transparent;color:' + color + ';'); } else { console.log('%c> p5.js says: ' + message + '%c [http://p5js.org/reference/#p5/' + func + ']', 'background-color:' + color + ';color:#FFF;', 'background-color:transparent;color:' + color + ';'); } } p5.prototype._validateParameters = function (func, args, types) { if (!isArray(types[0])) { types = [types]; } var diff = Math.abs(args.length - types[0].length); var message, tindex = 0; for (var i = 1, len = types.length; i < len; i++) { var d = Math.abs(args.length - types[i].length); if (d <= diff) { tindex = i; diff = d; } } var symbol = 'X'; if (diff > 0) { message = 'You wrote ' + func + '('; if (args.length > 0) { message += symbol + (',' + symbol).repeat(args.length - 1); } message += '). ' + func + ' was expecting ' + types[tindex].length + ' parameters. Try ' + func + '('; if (types[tindex].length > 0) { message += symbol + (',' + symbol).repeat(types[tindex].length - 1); } message += ').'; if (types.length > 1) { message += ' ' + func + ' takes different numbers of parameters ' + 'depending on what you want to do. Click this link to learn more: '; } report(message, func, PARAM_COUNT); } for (var format = 0; format < types.length; format++) { for (var p = 0; p < types[format].length && p < args.length; p++) { var defType = types[format][p]; var argType = getType(args[p]); if ('undefined' === argType || null === argType) { report('It looks like ' + func + ' received an empty variable in spot #' + (p + 1) + '. If not intentional, this is often a problem with scope: ' + '[link to scope].', func, EMPTY_VAR); } else if (defType !== '*' && !typeMatches(defType, argType, args[p])) { message = func + ' was expecting a ' + defType.toLowerCase() + ' for parameter #' + (p + 1) + ', received '; message += 'string' === argType ? '"' + args[p] + '"' : args[p]; message += ' instead.'; if (types.length > 1) { message += ' ' + func + ' takes different numbers of parameters ' + 'depending on what you want to do. ' + 'Click this link to learn more:'; } report(message, func, WRONG_TYPE); } } } }; var errorCases = { '0': { fileType: 'image', method: 'loadImage', message: ' hosting the image online,' }, '1': { fileType: 'XML file', method: 'loadXML' }, '2': { fileType: 'table file', method: 'loadTable' }, '3': { fileType: 'text file', method: 'loadStrings' } }; p5._friendlyFileLoadError = function (errorType, filePath) { var errorInfo = errorCases[errorType]; var message = 'It looks like there was a problem' + ' loading your ' + errorInfo.fileType + '.' + ' Try checking if the file path%c [' + filePath + '] %cis correct,' + (errorInfo.message || '') + ' or running a local server.'; report(message, errorInfo.method, FILE_LOAD); }; function friendlyWelcome() { var astrixBgColor = 'transparent'; var astrixTxtColor = '#ED225D'; var welcomeBgColor = '#ED225D'; var welcomeTextColor = 'white'; console.log('%c _ \n' + ' /\\| |/\\ \n' + ' \\ ` \' / \n' + ' / , . \\ \n' + ' \\/|_|\\/ ' + '\n\n%c> p5.js says: Welcome! ' + 'This is your friendly debugger. ' + 'To turn me off switch to using \u201cp5.min.js\u201d.', 'background-color:' + astrixBgColor + ';color:' + astrixTxtColor + ';', 'background-color:' + welcomeBgColor + ';color:' + welcomeTextColor + ';'); } return p5; }({}, amdclean['core_core']); amdclean['image_loading_displaying'] = function (require, core_core, image_filters, core_canvas, core_constants, core_error_helpers) { 'use strict'; var p5 = core_core; var Filters = image_filters; var canvas = core_canvas; var constants = core_constants; p5.prototype.loadImage = function (path, successCallback, failureCallback) { var img = new Image(); var pImg = new p5.Image(1, 1, this); img.onload = function () { pImg.width = pImg.canvas.width = img.width; pImg.height = pImg.canvas.height = img.height; pImg.canvas.getContext('2d').drawImage(img, 0, 0); if (typeof successCallback === 'function') { successCallback(pImg); } }; img.onerror = function (e) { p5._friendlyFileLoadError(0, img.src); if (typeof failureCallback === 'function') { failureCallback(e); } }; if (path.indexOf('data:image/') !== 0) { img.crossOrigin = 'Anonymous'; } img.src = path; return pImg; }; p5.prototype.image = function (img, x, y, width, height) { x = x || 0; y = y || 0; width = width || img.width; height = height || img.height; var vals = canvas.modeAdjust(x, y, width, height, this._imageMode); this._graphics.image(img, vals.x, vals.y, vals.w, vals.h); }; p5.prototype.tint = function () { var c = this.color.apply(this, arguments); this._tint = c.rgba; }; p5.prototype.noTint = function () { this._tint = null; }; p5.prototype._getTintedImageCanvas = function (img) { if (!img.canvas) { return img; } var pixels = Filters._toPixels(img.canvas); var tmpCanvas = document.createElement('canvas'); tmpCanvas.width = img.canvas.width; tmpCanvas.height = img.canvas.height; var tmpCtx = tmpCanvas.getContext('2d'); var id = tmpCtx.createImageData(img.canvas.width, img.canvas.height); var newPixels = id.data; for (var i = 0; i < pixels.length; i += 4) { var r = pixels[i]; var g = pixels[i + 1]; var b = pixels[i + 2]; var a = pixels[i + 3]; newPixels[i] = r * this._tint[0] / 255; newPixels[i + 1] = g * this._tint[1] / 255; newPixels[i + 2] = b * this._tint[2] / 255; newPixels[i + 3] = a * this._tint[3] / 255; } tmpCtx.putImageData(id, 0, 0); return tmpCanvas; }; p5.prototype.imageMode = function (m) { if (m === constants.CORNER || m === constants.CORNERS || m === constants.CENTER) { this._imageMode = m; } }; return p5; }({}, amdclean['core_core'], amdclean['image_filters'], amdclean['core_canvas'], amdclean['core_constants'], amdclean['core_error_helpers']); amdclean['image_pixels'] = function (require, core_core, image_filters, color_p5Color) { 'use strict'; var p5 = core_core; var Filters = image_filters; p5.prototype.pixels = []; p5.prototype.blend = function () { this._graphics.blend.apply(this._graphics, arguments); }; p5.prototype.copy = function () { p5.Renderer2D._copyHelper.apply(this, arguments); }; p5.prototype.filter = function (operation, value) { Filters.apply(this.canvas, Filters[operation.toLowerCase()], value); }; p5.prototype.get = function (x, y, w, h) { return this._graphics.get(x, y, w, h); }; p5.prototype.loadPixels = function () { this._graphics.loadPixels(); }; p5.prototype.set = function (x, y, imgOrCol) { this._graphics.set(x, y, imgOrCol); }; p5.prototype.updatePixels = function (x, y, w, h) { this._graphics.updatePixels(x, y, w, h); }; return p5; }({}, amdclean['core_core'], amdclean['image_filters'], amdclean['color_p5Color']); !function (name, context, definition) { if (typeof module != 'undefined' && module.exports) module.exports = definition(); else if (typeof define == 'function' && define.amd) define('reqwest', definition); else context[name] = definition(); }('reqwest', amdclean, function () { var win = window, doc = document, httpsRe = /^http/, protocolRe = /(^\w+):\/\//, twoHundo = /^(20\d|1223)$/, byTag = 'getElementsByTagName', readyState = 'readyState', contentType = 'Content-Type', requestedWith = 'X-Requested-With', head = doc[byTag]('head')[0], uniqid = 0, callbackPrefix = 'reqwest_' + +new Date(), lastValue, xmlHttpRequest = 'XMLHttpRequest', xDomainRequest = 'XDomainRequest', noop = function () { }, isArray = typeof Array.isArray == 'function' ? Array.isArray : function (a) { return a instanceof Array; }, defaultHeaders = { 'contentType': 'application/x-www-form-urlencoded', 'requestedWith': xmlHttpRequest, 'accept': { '*': 'text/javascript, text/html, application/xml, text/xml, */*', 'xml': 'application/xml, text/xml', 'html': 'text/html', 'text': 'text/plain', 'json': 'application/json, text/javascript', 'js': 'application/javascript, text/javascript' } }, xhr = function (o) { if (o['crossOrigin'] === true) { var xhr = win[xmlHttpRequest] ? new XMLHttpRequest() : null; if (xhr && 'withCredentials' in xhr) { return xhr; } else if (win[xDomainRequest]) { return new XDomainRequest(); } else { throw new Error('Browser does not support cross-origin requests'); } } else if (win[xmlHttpRequest]) { return new XMLHttpRequest(); } else { return new ActiveXObject('Microsoft.XMLHTTP'); } }, globalSetupOptions = { dataFilter: function (data) { return data; } }; function succeed(r) { var protocol = protocolRe.exec(r.url); protocol = protocol && protocol[1] || window.location.protocol; return httpsRe.test(protocol) ? twoHundo.test(r.request.status) : !!r.request.response; } function handleReadyState(r, success, error) { return function () { if (r._aborted) return error(r.request); if (r._timedOut) return error(r.request, 'Request is aborted: timeout'); if (r.request && r.request[readyState] == 4) { r.request.onreadystatechange = noop; if (succeed(r)) success(r.request); else error(r.request); } }; } function setHeaders(http, o) { var headers = o['headers'] || {}, h; headers['Accept'] = headers['Accept'] || defaultHeaders['accept'][o['type']] || defaultHeaders['accept']['*']; var isAFormData = typeof FormData === 'function' && o['data'] instanceof FormData; if (!o['crossOrigin'] && !headers[requestedWith]) headers[requestedWith] = defaultHeaders['requestedWith']; if (!headers[contentType] && !isAFormData) headers[contentType] = o['contentType'] || defaultHeaders['contentType']; for (h in headers) headers.hasOwnProperty(h) && 'setRequestHeader' in http && http.setRequestHeader(h, headers[h]); } function setCredentials(http, o) { if (typeof o['withCredentials'] !== 'undefined' && typeof http.withCredentials !== 'undefined') { http.withCredentials = !!o['withCredentials']; } } function generalCallback(data) { lastValue = data; } function urlappend(url, s) { return url + (/\?/.test(url) ? '&' : '?') + s; } function handleJsonp(o, fn, err, url) { var reqId = uniqid++, cbkey = o['jsonpCallback'] || 'callback', cbval = o['jsonpCallbackName'] || reqwest.getcallbackPrefix(reqId), cbreg = new RegExp('((^|\\?|&)' + cbkey + ')=([^&]+)'), match = url.match(cbreg), script = doc.createElement('script'), loaded = 0, isIE10 = navigator.userAgent.indexOf('MSIE 10.0') !== -1; if (match) { if (match[3] === '?') { url = url.replace(cbreg, '$1=' + cbval); } else { cbval = match[3]; } } else { url = urlappend(url, cbkey + '=' + cbval); } win[cbval] = generalCallback; script.type = 'text/javascript'; script.src = url; script.async = true; if (typeof script.onreadystatechange !== 'undefined' && !isIE10) { script.htmlFor = script.id = '_reqwest_' + reqId; } script.onload = script.onreadystatechange = function () { if (script[readyState] && script[readyState] !== 'complete' && script[readyState] !== 'loaded' || loaded) { return false; } script.onload = script.onreadystatechange = null; script.onclick && script.onclick(); fn(lastValue); lastValue = undefined; head.removeChild(script); loaded = 1; }; head.appendChild(script); return { abort: function () { script.onload = script.onreadystatechange = null; err({}, 'Request is aborted: timeout', {}); lastValue = undefined; head.removeChild(script); loaded = 1; } }; } function getRequest(fn, err) { var o = this.o, method = (o['method'] || 'GET').toUpperCase(), url = typeof o === 'string' ? o : o['url'], data = o['processData'] !== false && o['data'] && typeof o['data'] !== 'string' ? reqwest.toQueryString(o['data']) : o['data'] || null, http, sendWait = false; if ((o['type'] == 'jsonp' || method == 'GET') && data) { url = urlappend(url, data); data = null; } if (o['type'] == 'jsonp') return handleJsonp(o, fn, err, url); http = o.xhr && o.xhr(o) || xhr(o); http.open(method, url, o['async'] === false ? false : true); setHeaders(http, o); setCredentials(http, o); if (win[xDomainRequest] && http instanceof win[xDomainRequest]) { http.onload = fn; http.onerror = err; http.onprogress = function () { }; sendWait = true; } else { http.onreadystatechange = handleReadyState(this, fn, err); } o['before'] && o['before'](http); if (sendWait) { setTimeout(function () { http.send(data); }, 200); } else { http.send(data); } return http; } function Reqwest(o, fn) { this.o = o; this.fn = fn; init.apply(this, arguments); } function setType(header) { if (header.match('json')) return 'json'; if (header.match('javascript')) return 'js'; if (header.match('text')) return 'html'; if (header.match('xml')) return 'xml'; } function init(o, fn) { this.url = typeof o == 'string' ? o : o['url']; this.timeout = null; this._fulfilled = false; this._successHandler = function () { }; this._fulfillmentHandlers = []; this._errorHandlers = []; this._completeHandlers = []; this._erred = false; this._responseArgs = {}; var self = this; fn = fn || function () { }; if (o['timeout']) { this.timeout = setTimeout(function () { timedOut(); }, o['timeout']); } if (o['success']) { this._successHandler = function () { o['success'].apply(o, arguments); }; } if (o['error']) { this._errorHandlers.push(function () { o['error'].apply(o, arguments); }); } if (o['complete']) { this._completeHandlers.push(function () { o['complete'].apply(o, arguments); }); } function complete(resp) { o['timeout'] && clearTimeout(self.timeout); self.timeout = null; while (self._completeHandlers.length > 0) { self._completeHandlers.shift()(resp); } } function success(resp) { var type = o['type'] || resp && setType(resp.getResponseHeader('Content-Type')); resp = type !== 'jsonp' ? 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; break; } } self._responseArgs.resp = resp; self._fulfilled = true; fn(resp); self._successHandler(resp); while (self._fulfillmentHandlers.length > 0) { resp = self._fulfillmentHandlers.shift()(resp); } complete(resp); } function timedOut() { self._timedOut = true; self.request.abort(); } function error(resp, msg, t) { resp = self.request; self._responseArgs.resp = resp; self._responseArgs.msg = msg; self._responseArgs.t = t; self._erred = true; while (self._errorHandlers.length > 0) { self._errorHandlers.shift()(resp, msg, t); } complete(resp); } this.request = getRequest.call(this, success, error); } Reqwest.prototype = { abort: function () { this._aborted = true; this.request.abort(); }, retry: function () { init.call(this, this.o, this.fn); }, then: function (success, fail) { success = success || function () { }; fail = fail || function () { }; if (this._fulfilled) { this._responseArgs.resp = success(this._responseArgs.resp); } else if (this._erred) { fail(this._responseArgs.resp, this._responseArgs.msg, this._responseArgs.t); } else { this._fulfillmentHandlers.push(success); this._errorHandlers.push(fail); } return this; }, always: function (fn) { if (this._fulfilled || this._erred) { fn(this._responseArgs.resp); } else { this._completeHandlers.push(fn); } return this; }, fail: function (fn) { if (this._erred) { fn(this._responseArgs.resp, this._responseArgs.msg, this._responseArgs.t); } else { this._errorHandlers.push(fn); } return this; }, 'catch': function (fn) { return this.fail(fn); } }; function reqwest(o, fn) { return new Reqwest(o, fn); } function normalize(s) { return s ? s.replace(/\r?\n/g, '\r\n') : ''; } function serial(el, cb) { var n = el.name, t = el.tagName.toLowerCase(), optCb = function (o) { if (o && !o['disabled']) cb(n, normalize(o['attributes']['value'] && o['attributes']['value']['specified'] ? o['value'] : o['text'])); }, ch, ra, val, i; if (el.disabled || !n) return; switch (t) { case 'input': if (!/reset|button|image|file/i.test(el.type)) { ch = /checkbox/i.test(el.type); ra = /radio/i.test(el.type); val = el.value; (!(ch || ra) || el.checked) && cb(n, normalize(ch && val === '' ? 'on' : val)); } break; case 'textarea': cb(n, normalize(el.value)); break; case 'select': if (el.type.toLowerCase() === 'select-one') { optCb(el.selectedIndex >= 0 ? el.options[el.selectedIndex] : null); } else { for (i = 0; el.length && i < el.length; i++) { el.options[i].selected && optCb(el.options[i]); } } break; } } function eachFormElement() { var cb = this, e, i, serializeSubtags = function (e, tags) { var i, j, fa; for (i = 0; i < tags.length; i++) { fa = e[byTag](tags[i]); for (j = 0; j < fa.length; j++) serial(fa[j], cb); } }; for (i = 0; i < arguments.length; i++) { e = arguments[i]; if (/input|select|textarea/i.test(e.tagName)) serial(e, cb); serializeSubtags(e, [ 'input', 'select', 'textarea' ]); } } function serializeQueryString() { return reqwest.toQueryString(reqwest.serializeArray.apply(null, arguments)); } function serializeHash() { var hash = {}; eachFormElement.apply(function (name, value) { if (name in hash) { hash[name] && !isArray(hash[name]) && (hash[name] = [hash[name]]); hash[name].push(value); } else hash[name] = value; }, arguments); return hash; } reqwest.serializeArray = function () { var arr = []; eachFormElement.apply(function (name, value) { arr.push({ name: name, value: value }); }, arguments); return arr; }; reqwest.serialize = function () { if (arguments.length === 0) return ''; var opt, fn, args = Array.prototype.slice.call(arguments, 0); opt = args.pop(); opt && opt.nodeType && args.push(opt) && (opt = null); opt && (opt = opt.type); if (opt == 'map') fn = serializeHash; else if (opt == 'array') fn = reqwest.serializeArray; else fn = serializeQueryString; return fn.apply(null, args); }; reqwest.toQueryString = function (o, trad) { var prefix, i, traditional = trad || false, s = [], enc = encodeURIComponent, add = function (key, value) { value = 'function' === typeof value ? value() : value == null ? '' : value; s[s.length] = enc(key) + '=' + enc(value); }; if (isArray(o)) { for (i = 0; o && i < o.length; i++) add(o[i]['name'], o[i]['value']); } else { for (prefix in o) { if (o.hasOwnProperty(prefix)) buildParams(prefix, o[prefix], traditional, add); } } return s.join('&').replace(/%20/g, '+'); }; function buildParams(prefix, obj, traditional, add) { var name, i, v, rbracket = /\[\]$/; if (isArray(obj)) { for (i = 0; obj && i < obj.length; i++) { v = obj[i]; if (traditional || rbracket.test(prefix)) { add(prefix, v); } else { buildParams(prefix + '[' + (typeof v === 'object' ? i : '') + ']', v, traditional, add); } } } else if (obj && obj.toString() === '[object Object]') { for (name in obj) { buildParams(prefix + '[' + name + ']', obj[name], traditional, add); } } else { add(prefix, obj); } } reqwest.getcallbackPrefix = function () { return callbackPrefix; }; reqwest.compat = function (o, fn) { if (o) { o['type'] && (o['method'] = o['type']) && delete o['type']; o['dataType'] && (o['type'] = o['dataType']); o['jsonpCallback'] && (o['jsonpCallbackName'] = o['jsonpCallback']) && delete o['jsonpCallback']; o['jsonp'] && (o['jsonpCallback'] = o['jsonp']); } return new Reqwest(o, fn); }; reqwest.ajaxSetup = function (options) { options = options || {}; for (var k in options) { globalSetupOptions[k] = options[k]; } }; return reqwest; }); amdclean['io_files'] = function (require, core_core, reqwest, core_error_helpers) { 'use strict'; var p5 = core_core; var reqwest = reqwest; p5.prototype.loadFont = function (path, callback) { var p5Font = new p5.Font(this); opentype.load(path, function (err, font) { if (err) { throw Error(err); } p5Font.font = font; if (typeof callback !== 'undefined') { callback(p5Font); } }); return p5Font; }; p5.prototype.createInput = function () { throw 'not yet implemented'; }; p5.prototype.createReader = function () { throw 'not yet implemented'; }; p5.prototype.loadBytes = function () { throw 'not yet implemented'; }; p5.prototype.loadJSON = function () { var path = arguments[0]; var callback = arguments[1]; var ret = []; var t = 'json'; if (typeof arguments[2] === 'string') { if (arguments[2] === 'jsonp' || arguments[2] === 'json') { t = arguments[2]; } } reqwest({ url: path, type: t, crossOrigin: true }).then(function (resp) { for (var k in resp) { ret[k] = resp[k]; } if (typeof callback !== 'undefined') { callback(resp); } }); return ret; }; p5.prototype.loadStrings = function (path, callback) { var ret = []; var req = new XMLHttpRequest(); req.open('GET', path, true); req.onreadystatechange = function () { if (req.readyState === 4 && req.status === 200) { var arr = req.responseText.match(/[^\r\n]+/g); for (var k in arr) { ret[k] = arr[k]; } if (typeof callback !== 'undefined') { callback(ret); } } else { p5._friendlyFileLoadError(3, path); } }; req.send(null); return ret; }; p5.prototype.loadTable = function (path) { var callback = null; var options = []; var header = false; var sep = ','; var separatorSet = false; for (var i = 1; i < arguments.length; i++) { if (typeof arguments[i] === 'function') { callback = arguments[i]; } else if (typeof arguments[i] === 'string') { options.push(arguments[i]); if (arguments[i] === 'header') { header = true; } if (arguments[i] === 'csv') { if (separatorSet) { throw new Error('Cannot set multiple separator types.'); } else { sep = ','; separatorSet = true; } } else if (arguments[i] === 'tsv') { if (separatorSet) { throw new Error('Cannot set multiple separator types.'); } else { sep = '\t'; separatorSet = true; } } } } var t = new p5.Table(); reqwest({ url: path, crossOrigin: true, type: 'csv' }).then(function (resp) { resp = resp.responseText; var state = {}; var PRE_TOKEN = 0, MID_TOKEN = 1, POST_TOKEN = 2, POST_RECORD = 4; var QUOTE = '"', CR = '\r', LF = '\n'; var records = []; var offset = 0; var currentRecord = null; var currentChar; var recordBegin = function () { state.escaped = false; currentRecord = []; tokenBegin(); }; var recordEnd = function () { state.currentState = POST_RECORD; records.push(currentRecord); currentRecord = null; }; var tokenBegin = function () { state.currentState = PRE_TOKEN; state.token = ''; }; var tokenEnd = function () { currentRecord.push(state.token); tokenBegin(); }; while (true) { currentChar = resp[offset++]; if (currentChar == null) { if (state.escaped) { throw new Error('Unclosed quote in file.'); } if (currentRecord) { tokenEnd(); recordEnd(); break; } } if (currentRecord === null) { recordBegin(); } if (state.currentState === PRE_TOKEN) { if (currentChar === QUOTE) { state.escaped = true; state.currentState = MID_TOKEN; continue; } state.currentState = MID_TOKEN; } if (state.currentState === MID_TOKEN && state.escaped) { if (currentChar === QUOTE) { if (resp[offset] === QUOTE) { state.token += QUOTE; offset++; } else { state.escaped = false; state.currentState = POST_TOKEN; } } else { state.token += currentChar; } continue; } if (currentChar === CR) { if (resp[offset] === LF) { offset++; } tokenEnd(); recordEnd(); } else if (currentChar === LF) { tokenEnd(); recordEnd(); } else if (currentChar === sep) { tokenEnd(); } else if (state.currentState === MID_TOKEN) { state.token += currentChar; } } if (header) { t.columns = records.shift(); } else { for (i = 0; i < records.length; i++) { t.columns[i] = i.toString(); } } var row; for (i = 0; i < records.length; i++) { if (i === records.length - 1 && records[i].length === 1) { if (records[i][0] === 'undefined') { break; } } row = new p5.TableRow(); row.arr = records[i]; row.obj = makeObject(records[i], t.columns); t.addRow(row); } if (callback !== null) { callback(t); } }).fail(function (err, msg) { p5._friendlyFileLoadError(2, path); if (typeof callback !== 'undefined') { callback(false); } }); return t; }; function makeObject(row, headers) { var ret = {}; headers = headers || []; if (typeof headers === 'undefined') { for (var j = 0; j < row.length; j++) { headers[j.toString()] = j; } } for (var i = 0; i < headers.length; i++) { var key = headers[i]; var val = row[i]; ret[key] = val; } return ret; } p5.prototype.loadXML = function (path, callback) { var ret = document.implementation.createDocument(null, null); reqwest({ url: path, type: 'xml', crossOrigin: true, error: function (err) { p5._friendlyFileLoadError(1, path); } }).then(function (resp) { var x = resp.documentElement; ret.appendChild(x); if (typeof callback !== 'undefined') { callback(resp); } }); return ret; }; p5.prototype.parseXML = function () { throw 'not yet implemented'; }; p5.prototype.selectFolder = function () { throw 'not yet implemented'; }; p5.prototype.selectInput = function () { throw 'not yet implemented'; }; p5.prototype.httpGet = function () { var args = Array.prototype.slice.call(arguments); args.push('GET'); p5.prototype.httpDo.apply(this, args); }; p5.prototype.httpPost = function () { var args = Array.prototype.slice.call(arguments); args.push('POST'); p5.prototype.httpDo.apply(this, args); }; p5.prototype.httpDo = function () { var method = 'GET'; var path = arguments[0]; var data = {}; var type = ''; var callback; for (var i = 1; i < arguments.length; i++) { var a = arguments[i]; if (typeof a === 'string') { if (a === 'GET' || a === 'POST' || a === 'PUT') { method = a; } else { type = a; } } else if (typeof a === 'object') { data = a; } else if (typeof a === 'function') { callback = a; } } if (type === '') { if (path.indexOf('json') !== -1) { type = 'json'; } else if (path.indexOf('xml') !== -1) { type = 'xml'; } else { type = 'text'; } } reqwest({ url: path, method: method, data: data, type: type, crossOrigin: true, success: function (resp) { if (typeof callback !== 'undefined') { if (type === 'text') { callback(resp.response); } else { callback(resp); } } } }); }; window.URL = window.URL || window.webkitURL; p5.prototype._pWriters = []; p5.prototype.beginRaw = function () { throw 'not yet implemented'; }; p5.prototype.beginRecord = function () { throw 'not yet implemented'; }; p5.prototype.createOutput = function () { throw 'not yet implemented'; }; p5.prototype.createWriter = function (name, extension) { var newPW; for (var i in p5.prototype._pWriters) { if (p5.prototype._pWriters[i].name === name) { newPW = new p5.PrintWriter(name + window.millis(), extension); p5.prototype._pWriters.push(newPW); return newPW; } } newPW = new p5.PrintWriter(name, extension); p5.prototype._pWriters.push(newPW); return newPW; }; p5.prototype.endRaw = function () { throw 'not yet implemented'; }; p5.prototype.endRecord = function () { throw 'not yet implemented'; }; p5.PrintWriter = function (filename, extension) { var self = this; this.name = filename; this.content = ''; this.print = function (data) { this.content += data; }; this.println = function (data) { this.content += data + '\n'; }; this.flush = function () { this.content = ''; }; this.close = function () { var arr = []; arr.push(this.content); p5.prototype.writeFile(arr, filename, extension); for (var i in p5.prototype._pWriters) { if (p5.prototype._pWriters[i].name === this.name) { p5.prototype._pWriters.splice(i, 1); } } self.flush(); self = {}; }; }; 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(cnv); return; } else if (args[0] instanceof p5.Renderer) { p5.prototype.saveCanvas(args[0].elt, args[1], args[2]); return; } else if (args.length === 1 && typeof args[0] === 'string') { p5.prototype.saveCanvas(cnv, args[0]); } else { var extension = _checkFileExtension(args[1], args[2])[1]; switch (extension) { case 'json': p5.prototype.saveJSON(args[0], args[1], args[2]); return; case 'txt': p5.prototype.saveStrings(args[0], args[1], args[2]); return; 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[0].canvas, args[1]); } else if (args[0] instanceof p5.SoundFile) { p5.prototype.saveSound(args[0], args[1], args[2], args[3]); } } } }; p5.prototype.saveJSON = function (json, filename, opt) { var stringify; if (opt) { stringify = JSON.stringify(json); } else { stringify = JSON.stringify(json, undefined, 2); } console.log(stringify); this.saveStrings(stringify.split('\n'), filename, 'json'); }; p5.prototype.saveJSONObject = p5.prototype.saveJSON; p5.prototype.saveJSONArray = p5.prototype.saveJSON; p5.prototype.saveStream = function () { throw 'not yet implemented'; }; p5.prototype.saveStrings = function (list, filename, extension) { var ext = extension || 'txt'; var pWriter = this.createWriter(filename, ext); for (var i in list) { if (i < list.length - 1) { pWriter.println(list[i]); } else { pWriter.print(list[i]); } } pWriter.close(); pWriter.flush(); }; p5.prototype.saveXML = function () { throw 'not yet implemented'; }; p5.prototype.selectOutput = function () { throw 'not yet implemented'; }; p5.prototype.saveTable = function (table, filename, options) { var pWriter = this.createWriter(filename, options); var header = table.columns; var sep = ','; if (options === 'tsv') { sep = '\t'; } if (options !== 'html') { if (header[0] !== '0') { for (var h = 0; h < header.length; h++) { if (h < header.length - 1) { pWriter.print(header[h] + sep); } else { pWriter.println(header[h]); } } } for (var i = 0; i < table.rows.length; i++) { var j; for (j = 0; j < table.rows[i].arr.length; j++) { if (j < table.rows[i].arr.length - 1) { pWriter.print(table.rows[i].arr[j] + sep); } else if (i < table.rows.length - 1) { pWriter.println(table.rows[i].arr[j]); } else { pWriter.print(table.rows[i].arr[j]); } } } } else { pWriter.println(''); pWriter.println('
'); var str = ' '; pWriter.println(str); pWriter.println(''); pWriter.println(''); pWriter.println('' + e); pWriter.println(' | '); } pWriter.println('
' + htmlEntry); pWriter.println(' | '); } pWriter.println('