You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6 lines
85 KiB
JavaScript

/*! p5.min.js v0.3.15 December 23, 2014 */
var shim=function(){window.requestDraw=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}()}({}),constants=function(){var t=Math.PI;return{ARROW:"default",CROSS:"crosshair",HAND:"pointer",MOVE:"move",TEXT:"text",WAIT:"wait",HALF_PI:t/2,PI:t,QUARTER_PI:t/4,TAU:2*t,TWO_PI:2*t,DEGREES:"degrees",RADIANS:"radians",CORNER:"corner",CORNERS:"corners",RADIUS:"radius",RIGHT:"right",LEFT:"left",CENTER:"center",POINTS:"points",LINES:"lines",TRIANGLES:"triangles",TRIANGLE_FAN:"triangles_fan",TRIANGLE_STRIP:"triangles_strip",QUADS:"quads",QUAD_STRIP:"quad_strip",CLOSE:"close",OPEN:"open",CHORD:"chord",PIE:"pie",PROJECT:"square",SQUARE:"butt",ROUND:"round",BEVEL:"bevel",MITER:"miter",RGB:"rgb",HSB:"hsb",AUTO:"auto",ALT:18,BACKSPACE:8,CONTROL:17,DELETE:46,DOWN_ARROW:40,ENTER:13,ESCAPE:27,LEFT_ARROW:37,OPTION:18,RETURN:13,RIGHT_ARROW:39,SHIFT:16,TAB:9,UP_ARROW:38,BLEND:"normal",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",NORMAL:"normal",ITALIC:"italic",BOLD:"bold",LINEAR:"linear",QUADRATIC:"quadratic",BEZIER:"bezier",CURVE:"curve"}}({}),core=function(t,e,r){"use strict";var r=r,o=function(t,e){this._setupDone=!1,this._pixelDensity=window.devicePixelRatio||1,this._startTime=(new Date).getTime(),this._userNode=e,this._curElement=null,this._elements=[],this._preloadCount=0,this._updateInterval=0,this._isGlobal=!1,this._loop=!0,this._styles=[],this._defaultCanvasSize={width:100,height:100},this._events={mousemove:null,mousedown:null,mouseup:null,click:null,mousewheel:null,mouseover:null,mouseout:null,keydown:null,keyup:null,keypress:null,touchstart:null,touchmove:null,touchend:null,resize:null,blur:null},this._loadingScreenId="p5_loading",this._start=function(){if(this._userNode&&"string"==typeof this._userNode&&(this._userNode=document.getElementById(this._userNode)),this._loadingScreen=document.getElementById(this._loadingScreenId),!this._loadingScreen){this._loadingScreen=document.createElement("loadingDiv"),this._loadingScreen.innerHTML="loading...",this._loadingScreen.style.position="absolute";var t=this._userNode||document.body;t.appendChild(this._loadingScreen)}this.createCanvas(this._defaultCanvasSize.width,this._defaultCanvasSize.height,!0);var e=this.preload||window.preload,r=this._isGlobal?window:this;e?(this._preloadMethods.forEach(function(t){r[t]=function(e){return r._preload(t,e)}}),e(),0===this._preloadCount&&(this._setup(),this._runFrames(),this._draw())):(this._setup(),this._runFrames(),this._draw())}.bind(this),this._preload=function(t,e){var r=this._isGlobal?window:this;return r._setProperty("_preloadCount",r._preloadCount+1),o.prototype[t].call(r,e,function(){r._setProperty("_preloadCount",r._preloadCount-1),0===r._preloadCount&&(r._setup(),r._runFrames(),r._draw())})}.bind(this),this._setup=function(){var t=this._isGlobal?window:this;"function"==typeof t.preload&&this._preloadMethods.forEach(function(e){t[e]=o.prototype[e]}),"function"==typeof t.setup&&t.setup(),this.canvas.style.visibility="",this.canvas.className=this.canvas.className.replace("p5_hidden",""),this._setupDone=!0,this._loadingScreen.parentNode.removeChild(this._loadingScreen)}.bind(this),this._draw=function(){var t=this.setup||window.setup,e=(new Date).getTime();this._frameRate=1e3/(e-this._lastFrameTime),this._lastFrameTime=e;var r=this.draw||window.draw;this._loop&&(this._drawInterval&&clearInterval(this._drawInterval),this._drawInterval=setTimeout(function(){window.requestDraw(this._draw.bind(this))}.bind(this),1e3/this._targetFrameRate)),"function"==typeof r&&(this.push(),"undefined"==typeof t&&this.scale(this._pixelDensity,this._pixelDensity),this._registeredMethods.pre.forEach(function(t){t.call(this)}),r(),this._registeredMethods.post.forEach(function(t){t.call(this)})
}var s=e;return s.prototype.join=function(t,e){return t.join(e)},s.prototype.match=function(t,e){return t.match(e)},s.prototype.matchAll=function(t,e){for(var r=new RegExp(e,"g"),o=r.exec(t),n=[];null!==o;)n.push(o),o=r.exec(t);return n},s.prototype.nf=function(){if(arguments[0]instanceof Array){var t=arguments[1],e=arguments[2];return arguments[0].map(function(o){return r(o,t,e)})}return r.apply(this,arguments)},s.prototype.nfc=function(){if(arguments[0]instanceof Array){var t=arguments[1];return arguments[0].map(function(e){return o(e,t)})}return o.apply(this,arguments)},s.prototype.nfp=function(){var t=this.nf(arguments);return t instanceof Array?t.map(n):n(t)},s.prototype.nfs=function(){var t=this.nf(arguments);return t instanceof Array?t.map(i):i(t)},s.prototype.split=function(t,e){return t.split(e)},s.prototype.splitTokens=function(){var t=arguments.length>0?arguments[1]:/\s/g;return arguments[0].split(t).filter(function(t){return t})},s.prototype.trim=function(t){return t instanceof Array?t.map(this.trim):t.trim()},s}({},core),environment=function(t,e,r){"use strict";function o(t){var e=document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled;if(!e)throw new Error("Fullscreen not enabled in this browser.");t.requestFullscreen?t.requestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen?t.webkitRequestFullscreen():t.msRequestFullscreen&&t.msRequestFullscreen()}function n(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}var i=e,s=r,a=[s.ARROW,s.CROSS,s.HAND,s.MOVE,s.TEXT,s.WAIT];return i.prototype._frameRate=0,i.prototype._lastFrameTime=(new Date).getTime(),i.prototype._targetFrameRate=60,i.prototype.frameCount=0,i.prototype.focused=!0,i.prototype.cursor=function(t,e,r){var o="auto",n=this._curElement.elt;if(a.indexOf(t)>-1)o=t;else if("string"==typeof t){var i="";e&&r&&"number"==typeof e&&"number"==typeof r&&(i=e+" "+r),o="http://"!==t.substring(0,6)?"url("+t+") "+i+", auto":/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(t)?"url("+t+") "+i+", auto":t}n.style.cursor=o},i.prototype.frameRate=function(t){return"undefined"==typeof t?this._frameRate:(this._setProperty("_targetFrameRate",t),this._runFrames(),this)},i.prototype.getFrameRate=function(){return this.frameRate()},i.prototype.setFrameRate=function(t){return this.frameRate(t)},i.prototype.noCursor=function(){this._curElement.elt.style.cursor="none"},i.prototype.displayWidth=screen.width,i.prototype.displayHeight=screen.height,i.prototype.windowWidth=window.innerWidth,i.prototype.windowHeight=window.innerHeight,i.prototype.onresize=function(t){this._setProperty("windowWidth",window.innerWidth),this._setProperty("windowHeight",window.innerHeight);var e,r=this._isGlobal?window:this;"function"==typeof r.windowResized&&(e=r.windowResized(t),void 0===e||e||t.preventDefault())},i.prototype.width=0,i.prototype.height=0,i.prototype.fullscreen=function(t){return"undefined"==typeof t?document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement:void(t?o(document.documentElement):n())},i.prototype.devicePixelScaling=function(t){this._pixelDensity=t?window.devicePixelRatio||1:1,this.resizeCanvas(this.width,this.height)},i.prototype.getURL=function(){return location.href},i.prototype.getURLPath=function(){return location.pathname.split("/").filter(function(t){return""!==t})},i.prototype.getURLParams=function(){for(var t,e=/[?&]([^&=]+)(?:[&=])([^&=]+)/gim,r={};null!=(t=e.exec(location.search));)t.index===e.lastIndex&&e.lastIndex++,r[t[1]]=t[2];return r},i}({},core,constants),imageimage=function(t,e,r){"use strict";var o=e,r=r;return o.prototype._imageMode=r.CORNER,o.prototype._tint=null,o.prototype.createImage=function(t,e){return new o.Image(t,e)},o}({},core,constants),canvas=function(t,e){var e=e;return{modeAdjust:function(t,r,o,n,i){return i===e.CORNER?{x:t,y:r,w:o,h:n}:i===e.CORNERS
else{var o=r(t[1],t[2])[1];switch(o){case"json":n.prototype.saveJSON(t[0],t[1],t[2]);break;case"txt":n.prototype.saveStrings(t[0],t[1],t[2]);break;default:t[0]instanceof Array?n.prototype.saveStrings(t[0],t[1],t[2]):t[0]instanceof n.Table?n.prototype.saveTable(t[0],t[1],t[2],t[3]):t[0]instanceof n.Image?n.prototype.saveCanvas(t[0].canvas,t[1]):t[0]instanceof n.SoundFile?n.prototype.saveSound(t[0],t[1],t[2],t[3]):t[0]instanceof Object&&n.prototype.saveJSON(t[0],t[1],t[2])}}},n.prototype.saveJSON=function(t,e,r){var o;o=r?JSON.stringify(t):JSON.stringify(t,void 0,2),this.saveStrings(o.split("\n"),e,"json")},n.prototype.saveJSONObject=n.prototype.saveJSON,n.prototype.saveJSONArray=n.prototype.saveJSON,n.prototype.saveStream=function(){throw"not yet implemented"},n.prototype.saveStrings=function(t,e,r){var o=r||"txt",n=this.createWriter(e,o);for(var i in t)i<t.length-1?n.println(t[i]):n.print(t[i]);n.close(),n.flush()},n.prototype.saveXML=function(){throw"not yet implemented"},n.prototype.selectOutput=function(){throw"not yet implemented"},n.prototype.saveTable=function(t,e,r){var o=this.createWriter(e,r),n=t.columns,s=",";if("tsv"===r&&(s=" "),"html"!==r){if("0"!==n[0])for(var a=0;a<n.length;a++)a<n.length-1?o.print(n[a]+s):o.println(n[a]);for(var h=0;h<t.rows.length;h++){var p;for(p=0;p<t.rows[h].arr.length;p++)p<t.rows[h].arr.length-1?o.print(t.rows[h].arr[p]+s):h<t.rows.length-1?o.println(t.rows[h].arr[p]):o.print(t.rows[h].arr[p])}}else{o.println("<html>"),o.println("<head>");var u=' <meta http-equiv="content-type" content';if(u+='="text/html;charset=utf-8" />',o.println(u),o.println("</head>"),o.println("<body>"),o.println(" <table>"),"0"!==n[0]){o.println(" <tr>");for(var l=0;l<n.length;l++){var c=i(n[l]);o.println(" <td>"+c),o.println(" </td>")}o.println(" </tr>")}for(var d=0;d<t.rows.length;d++){o.println(" <tr>");for(var f=0;f<t.columns.length;f++){var g=t.rows[d].getString(f),y=i(g);o.println(" <td>"+y),o.println(" </td>")}o.println(" </tr>")}o.println(" </table>"),o.println("</body>"),o.print("</html>")}o.close(),o.flush()};var i=function(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")};return n.prototype.writeFile=function(t,e,r){var o="application/octet-stream";n.prototype._isSafari()&&(o="text/plain");var i=new Blob(t,{type:o}),s=window.URL.createObjectURL(i);n.prototype.downloadFile(s,e,r)},n.prototype.downloadFile=function(t,e,i){var s=r(e,i),a=s[0],h=s[1],p=document.createElement("a");if(p.href=t,p.download=a,p.onclick=o,p.style.display="none",document.body.appendChild(p),n.prototype._isSafari()){var u="Hello, Safari user! To download this file...\n";u+="1. Go to File --> Save As.\n",u+='2. Choose "Page Source" as the Format.\n',u+='3. Name it with this extension: ."'+h+'"',alert(u)}p.click(),t=null},n.prototype._checkFileExtension=r,n.prototype._isSafari=function(){var t=Object.prototype.toString.call(window.HTMLElement);return t.indexOf("Constructor")>0},n}({},core),outputimage=function(t,e){"use strict";var r=e,o=[];return r.prototype.saveCanvas=function(t,e,o){o||(o=r.prototype._checkFileExtension(e,o)[1],""===o&&(o="png"));var n;if(t?n=t:this._curElement&&this._curElement.elt&&(n=this._curElement.elt),r.prototype._isSafari()){var i="Hello, Safari user!\n";i+="Now capturing a screenshot...\n",i+="To save this image,\n",i+="go to File --> Save As.\n",alert(i),window.location.href=n.toDataURL()}else{var s;if("undefined"==typeof o)o="png",s="image/png";else switch(o){case"png":s="image/png";break;case"jpeg":s="image/jpeg";break;case"jpg":s="image/jpeg";break;default:s="image/png"}var a="image/octet-stream",h=n.toDataURL(s);h=h.replace(s,a),r.prototype.downloadFile(h,e,o)}},r.prototype.saveFrames=function(t,e,n,i,s){var a=n||3;a=r.prototype.constrain(a,0,15),a=1e3*a;var h=i||15;h=r.prototype.constrain(h,0,22);var p=0,u=r.prototype._makeFrame,l=this._curElement.elt,c=setInterval(function(){u(t+p,e,l),p++},1e3/h);setTimeout(function(){if(clearInterval(c),s)s(o);else for(var t=0;t<o.length;t++){var e=o