Browse files

Added sketch.js 1.0.0 (bis)

  • Loading branch information...
1 parent 434c2d7 commit 69f7dc8959582291f2dbc7cec9ad2dd75dea930c @nitriques nitriques committed Apr 29, 2013
Showing with 749 additions and 0 deletions.
  1. +723 −0 ajax/libs/sketch.js/1.0.0/sketch.js
  2. +1 −0 ajax/libs/sketch.js/1.0.0/sketch.min.js
  3. +25 −0 ajax/libs/sketch.js/package.json
View
723 ajax/libs/sketch.js/1.0.0/sketch.js
@@ -0,0 +1,723 @@
+
+/**
+ * Copyright (C) 2012 by Justin Windle
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+var Sketch = (function() {
+
+ // ----------------------------------------
+ // CONSTANTS
+ // ----------------------------------------
+
+ var GUID = 0;
+ var CANVAS = 'canvas';
+ var WEB_GL = 'web-gl';
+ var DOM = 'dom';
+
+ // ----------------------------------------
+ // Members
+ // ----------------------------------------
+
+ var ctx;
+ var counter = 0;
+ var timeout = -1;
+ var bindings = {};
+ var instances = [];
+
+ // Default options
+ var defaults = {
+
+ fullscreen : true,
+ autostart : true,
+ autoclear : true,
+ autopause : true,
+ autoresize : true,
+ container : document.body,
+ interval : 1,
+ type : CANVAS
+
+ };
+
+ // Mixed into the window object
+ var globals = {
+
+ PI : Math.PI,
+ TWO_PI : Math.PI * 2,
+ HALF_PI : Math.PI / 2,
+ QUARTER_PI : Math.PI / 4,
+
+ abs : Math.abs,
+ acos : Math.acos,
+ asin : Math.asin,
+ atan2 : Math.atan2,
+ atan : Math.atan,
+ ceil : Math.ceil,
+ cos : Math.cos,
+ exp : Math.exp,
+ floor : Math.floor,
+ log : Math.log,
+ max : Math.max,
+ min : Math.min,
+ pow : Math.pow,
+ round : Math.round,
+ sin : Math.sin,
+ sqrt : Math.sqrt,
+ tan : Math.tan,
+
+ // TODO: map, lerp (etc)
+
+ random : function( min, max ) {
+
+ if ( min && typeof min.length === 'number' && !!min.length )
+ return min[ Math.floor( Math.random() * min.length ) ];
+
+ if ( typeof max !== 'number' )
+ max = min || 1, min = 0;
+
+ return min + Math.random() * (max - min);
+ }
+ };
+
+ // Properties & methods mixed into ctx
+ var api = {
+
+ millis : 0, // Total running milliseconds
+ now : NaN, // Current time in milliseconds
+ dt : NaN, // Delta time between frames (milliseconds)
+
+ keys : {}, // Hash of currently pressed keys
+
+ mouse : { x:0, y:0, ox:0, oy:0, dx:0, dy:0 },
+ touches : [],
+ initialized : false,
+ dragging : false,
+ running : false,
+
+ // Starts the update / rendering process
+ start: function() {
+
+ if ( ctx.running ) return;
+
+ if ( ctx.setup && !ctx.initialized ) {
+
+ if ( ctx.autopause ) {
+
+ bind( window, 'focus', ctx.start );
+ bind( window, 'blur', ctx.stop );
+ }
+
+ ctx.setup();
+ }
+
+ ctx.initialized = true;
+ ctx.running = true;
+ ctx.now = Date.now();
+ update();
+ },
+
+ // Stops the update / rendering process
+ stop: function() {
+
+ cancelAnimationFrame( timeout );
+ ctx.running = false;
+ },
+
+ // Toggles the update / rendering process
+ toggle: function() {
+ (ctx.running ? ctx.stop : ctx.start)();
+ },
+
+ // Clears the current drawing context
+ // TODO: Empty children here for non-canvas sketches?
+ clear: function() {
+
+ if ( ctx.canvas )
+ ctx.canvas.width = ctx.canvas.width;
+ },
+
+ destroy: function() {
+
+ // Variable cache
+ var binding, type, list, prop, i, n;
+
+ // Remove from the global index
+ instances.splice( instances.indexOf( ctx ), 1 );
+
+ // Stop update loop
+ ctx.stop();
+
+ // Remove event handlers
+ for ( type in bindings ) {
+
+ list = bindings[ type ];
+
+ for ( i = 0, n = list.length; i < n; i++ ) {
+
+ binding = list[ i ];
+ unbind( binding.el, type, binding.fn );
+ }
+
+ delete bindings[ type ];
+ }
+
+ // Empty display list
+ ctx.container.removeChild( ctx.canvas );
+
+ // Delete all properties
+ for ( prop in ctx ) {
+ if ( ctx.hasOwnProperty( prop ) ) {
+ delete ctx[ prop ];
+ }
+ }
+ }
+ };
+
+ // ----------------------------------------
+ // Helpers
+ // ----------------------------------------
+
+ // Returns the browser specific even binding method
+ var bind = (function() {
+
+ function remember( el, ev, fn ) {
+
+ if ( !bindings[ ev ] ) bindings[ ev ] = [];
+ bindings[ ev ].push({ el: el, fn: fn });
+ }
+
+ if ( window.addEventListener ) {
+
+ return function( el, ev, fn ) {
+
+ el.addEventListener( ev, fn, false );
+ remember( el, ev, fn );
+ };
+
+ } else if ( window.attachEvent ) {
+
+ return function( el, ev, fn ) {
+
+ el.attachEvent( 'on' + ev, fn );
+ remember( el, ev, fn );
+ };
+
+ } else {
+
+ return function( el, ev, fn ) {
+
+ el[ 'on' + ev ] = fn;
+ remember( el, ev, fn );
+ };
+ }
+
+ })();
+
+ // Returns the browser specific even unbinding method
+ var unbind = (function() {
+
+ function forget( el, ev, fn ) {
+
+ if ( bindings[ ev ] ) {
+
+ var binding;
+
+ for ( var i = bindings[ ev ].length - 1; i >= 0; i-- ) {
+
+ binding = bindings[ ev ][ i ];
+
+ if ( binding.el === el && binding.fn === fn ) {
+ bindings[ ev ].splice( i, 1 );
+ }
+ }
+ }
+ }
+
+ if ( window.removeEventListener ) {
+
+ return function( el, ev, fn ) {
+
+ el.removeEventListener( ev, fn, false );
+ forget( el, ev, fn );
+ };
+
+ } else if ( window.detachEvent ) {
+
+ return function( el, ev, fn ) {
+
+ el.detachEvent( 'on' + ev, fn );
+ forget( el, ev, fn );
+ };
+
+ } else {
+
+ el[ 'on' + ev ] = null;
+ forget( el, ev, fn );
+ }
+
+ })();
+
+ // ----------------------------------------
+ // Methods
+ // ----------------------------------------
+
+ // Sets up & returns a new sketch
+ function create( options ) {
+
+ options = extend( options || {}, defaults );
+
+ var id = 'sketch-' + GUID++,
+ hasCustomCanvas = options.hasOwnProperty('canvas'),
+ canvas = hasCustomCanvas ? options['canvas'] : document.createElement( 'canvas' );
+
+ switch ( options.type ) {
+
+ case WEB_GL:
+
+ try { ctx = canvas.getContext( 'webgl', options ); } catch (e) {}
+ try { ctx = ctx || canvas.getContext( 'experimental-webgl', options ); } catch (e) {}
+ if ( !ctx ) throw 'WebGL not supported';
+
+ break;
+
+ case CANVAS:
+
+ try { ctx = canvas.getContext( '2d', options ); } catch (e) {}
+ if ( !ctx ) throw 'Canvas not supported';
+
+ break;
+
+ default:
+
+ canvas = ctx = document.createElement( 'div' );
+
+ }
+
+ // DOM type consistency
+ ctx.canvas = canvas;
+
+ // ID & class can be useful
+ canvas.className = 'sketch';
+
+ if(!hasCustomCanvas) {
+
+ options.container.appendChild( canvas );
+ if(!options.hasOwnProperty('autoresize')) options.autoresize = defaults.autoresize;
+ canvas.id = id;
+
+ } else {
+ options.autoresize = false;
+ }
+
+ // Mix globals into the window object
+ extend( self, globals );
+
+ // Mix options into ctx
+ extend( ctx, options );
+
+ // Add public properties
+ extend( ctx, api );
+
+ // Bind event handlers
+ bindEvents();
+
+ // Set initial dimension (only if `autoresize` is `true`)
+ if(options.autoresize) resize();
+
+ // Add to global index
+ instances.push( ctx );
+
+ // Optionally trigger start after stack execution
+ if ( ctx.autostart ) setTimeout( ctx.start, 0 );
+
+ return ctx;
+ }
+
+ // Soft object merge
+ function extend( target, source ) {
+
+ for ( var prop in source ) {
+
+ if ( !target.hasOwnProperty( prop ) ) {
+ target[ prop ] = source[ prop ];
+ }
+ }
+
+ return target;
+ }
+
+ // Shallow clones a given object
+ function clone( obj ) {
+
+ var copy = {};
+
+ function getCallback( method, context ) {
+
+ return function() {
+ method.call( context, arguments );
+ };
+ }
+
+ for ( var prop in obj ) {
+
+ if ( typeof obj[ prop ] === 'function' )
+
+ copy[ prop ] = getCallback( obj[ prop ], obj );
+
+ else
+
+ copy[ prop ] = obj[ prop ];
+ }
+
+ return copy;
+ }
+
+ // Replaces array contents, maintaining the original object
+ function displace( array, contents ) {
+
+ // we could use `a.splice.apply( a, [ 0, a.length ].concat( b ) )`
+ // but contents could be a `touchlist` and we need to flatten it
+
+ array.length = 0;
+
+ for ( var i = 0, n = contents.length; i < n; i++ ) {
+ array[i] = contents[i];
+ }
+
+ return array;
+ }
+
+ // Sets up sketch mouse & keyboard events
+ function bindEvents() {
+
+ var keynames = {
+ 8: 'BACKSPACE',
+ 9: 'TAB',
+ 13: 'ENTER',
+ 16: 'SHIFT',
+ 27: 'ESCAPE',
+ 32: 'SPACE',
+ 37: 'LEFT',
+ 38: 'UP',
+ 39: 'RIGHT',
+ 40: 'DOWN'
+ };
+
+ // Explicitly set all keys to false initially
+ for ( var name in keynames ) {
+ api.keys[ keynames[ name ] ] = false;
+ }
+
+ // maps a key code to a key name
+ function map( code ) {
+ return keynames[ code ] || String.fromCharCode( code );
+ }
+
+ // Update mouse position
+ function updateMouse( coord ) {
+
+ ctx.mouse.ox = ctx.mouse.x;
+ ctx.mouse.oy = ctx.mouse.y;
+
+ ctx.mouse.x = coord.x;
+ ctx.mouse.y = coord.y;
+
+ ctx.mouse.dx = ctx.mouse.x - ctx.mouse.ox;
+ ctx.mouse.dy = ctx.mouse.y - ctx.mouse.oy;
+ }
+
+ var old = {};
+
+ // Augments the native mouse event
+ function augment( event ) {
+
+ var o, e = clone( event );
+ e.original = event;
+
+ // Compute container offset
+ for ( var el = ctx.canvas, ox = 0, oy = 0; el; el = el.offsetParent ) {
+
+ ox += el.offsetLeft;
+ oy += el.offsetTop;
+ }
+
+ // Normalise touches / mouse
+ if ( e.touches && !!e.touches.length ) {
+
+ for ( var i = e.touches.length - 1, touch; i >= 0; i-- ) {
+
+ touch = e.touches[i];
+ touch.x = touch.pageX - ox;
+ touch.y = touch.pageY - oy;
+
+ o = old[i] || touch;
+
+ touch.dx = touch.x - o.x;
+ touch.dy = touch.y - o.x;
+
+ touch.ox = o.x;
+ touch.oy = o.y;
+
+ old[i] = clone( touch );
+ }
+
+ } else {
+
+ e.x = e.pageX - ox;
+ e.y = e.pageY - oy;
+
+ o = old[ 'mouse' ] || e;
+
+ e.dx = e.x - o.x;
+ e.dy = e.y - o.y;
+
+ e.ox = o.x;
+ e.oy = o.y;
+
+ old[ 'mouse' ] = e;
+ }
+
+ return e;
+ }
+
+ // Touch events
+
+ function touchstart( event ) {
+
+ // Prevent scrolling (should this be optional?)
+ event.preventDefault();
+
+ event = augment( event );
+ displace( ctx.touches, event.touches );
+ updateMouse( ctx.touches[0] );
+
+ if ( ctx.touchstart ) ctx.touchstart( event );
+ if ( ctx.mousedown ) ctx.mousedown( event );
+ }
+
+ function touchmove( event ) {
+
+ event = augment( event );
+ displace( ctx.touches, event.touches );
+ updateMouse( ctx.touches[0] );
+
+ if ( ctx.touchmove ) ctx.touchmove( event );
+ if ( ctx.mousemove ) ctx.mousemove( event );
+ }
+
+ function touchend( event ) {
+
+ event = augment( event );
+
+ // Cleanup ended touches
+ if ( !event.touches.length ) old = {};
+ else for ( var id in old ) if ( !event.touches[ id ] ) delete old[ id ];
+
+ if ( ctx.touchend ) ctx.touchend( event );
+ if ( ctx.mouseup ) ctx.mouseup( event );
+ }
+
+ // Mouse events
+
+ function mouseover( event ) {
+
+ event = augment( event );
+ if ( ctx.mouseover ) ctx.mouseover( event );
+ }
+
+ function mousedown( event ) {
+
+ event = augment( event );
+
+ if ( !ctx.dragging ) {
+
+ unbind( ctx.canvas, 'mousemove', mousemove );
+ unbind( ctx.canvas, 'mouseup', mouseup );
+
+ bind( document, 'mousemove', mousemove );
+ bind( document, 'mouseup', mouseup );
+
+ ctx.dragging = true;
+ }
+
+ displace( ctx.touches, [ event ] );
+
+ if ( ctx.touchstart ) ctx.touchstart( event );
+ if ( ctx.mousedown ) ctx.mousedown( event );
+ }
+
+ function mousemove( event ) {
+
+ event = augment( event );
+ updateMouse( event );
+
+ displace( ctx.touches, [ event ] );
+
+ if ( ctx.touchmove ) ctx.touchmove( event );
+ if ( ctx.mousemove ) ctx.mousemove( event );
+ }
+
+ function mouseout( event ) {
+
+ event = augment( event );
+ if ( ctx.mouseout ) ctx.mouseout( event );
+ }
+
+ function mouseup( event ) {
+
+ event = augment( event );
+
+ if ( ctx.dragging ) {
+
+ unbind( document, 'mousemove', mousemove );
+ unbind( document, 'mouseup', mouseup );
+
+ bind( ctx.canvas, 'mousemove', mousemove );
+ bind( ctx.canvas, 'mouseup', mouseup );
+
+ ctx.dragging = false;
+ }
+
+ delete old[ 'mouse' ];
+
+ if ( ctx.touchend ) ctx.touchend( event );
+ if ( ctx.mouseup ) ctx.mouseup( event );
+ }
+
+ function click( event ) {
+
+ event = augment( event );
+ if ( ctx.click ) ctx.click( event );
+ }
+
+ // Keyboard events
+
+ function keydown( event ) {
+
+ ctx.keys[ map( event.keyCode ) ] = true;
+ ctx.keys[ event.keyCode ] = true;
+
+ if ( ctx.keydown ) ctx.keydown( event );
+ }
+
+ function keyup( event ) {
+
+ ctx.keys[ map( event.keyCode ) ] = false;
+ ctx.keys[ event.keyCode ] = false;
+
+ if ( ctx.keyup ) ctx.keyup( event );
+ }
+
+ // Bind to context
+
+ bind( ctx.canvas, 'touchstart', touchstart );
+ bind( ctx.canvas, 'touchmove', touchmove );
+ bind( ctx.canvas, 'touchend', touchend );
+
+ bind( ctx.canvas, 'mouseover', mouseover );
+ bind( ctx.canvas, 'mousedown', mousedown );
+ bind( ctx.canvas, 'mousemove', mousemove );
+ bind( ctx.canvas, 'mouseout', mouseout );
+ bind( ctx.canvas, 'mouseup', mouseup );
+ bind( ctx.canvas, 'click', click );
+
+ bind( document, 'keydown', keydown );
+ bind( document, 'keyup', keyup );
+ bind( window, 'resize', resize );
+ }
+
+ // ----------------------------------------
+ // Event handlers
+ // ----------------------------------------
+
+ function update() {
+
+ if ( !counter ) {
+
+ var now = Date.now();
+
+ ctx.dt = now - ctx.now;
+ ctx.millis += ctx.dt;
+ ctx.now = now;
+
+ if ( ctx.update ) ctx.update( ctx.dt );
+ if ( ctx.autoclear ) ctx.clear();
+ if ( ctx.draw ) ctx.draw( ctx );
+ }
+
+ counter = ++counter % ctx.interval;
+ timeout = requestAnimationFrame( update );
+ }
+
+ function resize( event ) {
+
+ if ( !ctx.autoresize ) return;
+
+ var target = ctx.type === DOM ? ctx.style : ctx.canvas;
+
+ if ( ctx.fullscreen ) {
+
+ ctx.height = target.height = window.innerHeight;
+ ctx.width = target.width = window.innerWidth;
+
+ } else {
+
+ target.height = ctx.height;
+ target.width = ctx.width;
+ }
+
+ if ( ctx.resize ) ctx.resize();
+ }
+
+ // ----------------------------------------
+ // Public API
+ // ----------------------------------------
+
+ return {
+
+ CANVAS: CANVAS,
+ WEB_GL: WEB_GL,
+ DOM: DOM,
+
+ instances: instances,
+ create: create
+ };
+
+})();
+
+// ----------------------------------------
+// Useful polyfills
+// ----------------------------------------
+
+if ( !Date.now ) {
+ Date.now = function now() {
+ return +( new Date() );
+ };
+}
+
+/**
+ * requestAnimationFrame polyfill by Erik Möller
+ * Fixes from Paul Irish and Tino Zijdel
+ *
+ * @see http://goo.gl/ZC1Lm
+ * @see http://goo.gl/X0h6k
+ */
+
+(function(){for(var d=0,a=["ms","moz","webkit","o"],b=0;b<a.length&&!window.requestAnimationFrame;++b)window.requestAnimationFrame=window[a[b]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[a[b]+"CancelAnimationFrame"]||window[a[b]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(b){var a=Date.now(),c=Math.max(0,16-(a-d)),e=window.setTimeout(function(){b(a+c)},c);d=a+c;return e});window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){clearTimeout(a)})})();
View
1 ajax/libs/sketch.js/1.0.0/sketch.min.js
@@ -0,0 +1 @@
+var Sketch=function(){function e(e){e=n(e||{},l);var t="sketch-"+r++,o=e.hasOwnProperty("canvas"),u=o?e.canvas:document.createElement("canvas");switch(e.type){case m:try{s=u.getContext("webgl",e)}catch(d){}try{s=s||u.getContext("experimental-webgl",e)}catch(d){}if(!s)throw"WebGL not supported";break;case c:try{s=u.getContext("2d",e)}catch(d){}if(!s)throw"Canvas not supported";break;default:u=s=document.createElement("div")}return s.canvas=u,u.className="sketch",o?e.autoresize=!1:(e.container.appendChild(u),e.hasOwnProperty("autoresize")||(e.autoresize=l.autoresize),u.id=t),n(self,g),n(s,e),n(s,p),a(),e.autoresize&&i(),w.push(s),s.autostart&&setTimeout(s.start,0),s}function n(e,n){for(var t in n)e.hasOwnProperty(t)||(e[t]=n[t]);return e}function t(e){function n(e,n){return function(){e.call(n,arguments)}}var t={};for(var o in e)t[o]="function"==typeof e[o]?n(e[o],e):e[o];return t}function o(e,n){e.length=0;for(var t=0,o=n.length;o>t;t++)e[t]=n[t];return e}function a(){function e(e){return M[e]||String.fromCharCode(e)}function n(e){s.mouse.ox=s.mouse.x,s.mouse.oy=s.mouse.y,s.mouse.x=e.x,s.mouse.y=e.y,s.mouse.dx=s.mouse.x-s.mouse.ox,s.mouse.dy=s.mouse.y-s.mouse.oy}function a(e){var n,o=t(e);o.original=e;for(var a=s.canvas,u=0,i=0;a;a=a.offsetParent)u+=a.offsetLeft,i+=a.offsetTop;if(o.touches&&o.touches.length)for(var r,c=o.touches.length-1;c>=0;c--)r=o.touches[c],r.x=r.pageX-u,r.y=r.pageY-i,n=A[c]||r,r.dx=r.x-n.x,r.dy=r.y-n.x,r.ox=n.x,r.oy=n.y,A[c]=t(r);else o.x=o.pageX-u,o.y=o.pageY-i,n=A.mouse||o,o.dx=o.x-n.x,o.dy=o.y-n.y,o.ox=n.x,o.oy=n.y,A.mouse=o;return o}function u(e){e.preventDefault(),e=a(e),o(s.touches,e.touches),n(s.touches[0]),s.touchstart&&s.touchstart(e),s.mousedown&&s.mousedown(e)}function r(e){e=a(e),o(s.touches,e.touches),n(s.touches[0]),s.touchmove&&s.touchmove(e),s.mousemove&&s.mousemove(e)}function c(e){if(e=a(e),e.touches.length)for(var n in A)e.touches[n]||delete A[n];else A={};s.touchend&&s.touchend(e),s.mouseup&&s.mouseup(e)}function m(e){e=a(e),s.mouseover&&s.mouseover(e)}function d(e){e=a(e),s.dragging||(x(s.canvas,"mousemove",h),x(s.canvas,"mouseup",v),y(document,"mousemove",h),y(document,"mouseup",v),s.dragging=!0),o(s.touches,[e]),s.touchstart&&s.touchstart(e),s.mousedown&&s.mousedown(e)}function h(e){e=a(e),n(e),o(s.touches,[e]),s.touchmove&&s.touchmove(e),s.mousemove&&s.mousemove(e)}function f(e){e=a(e),s.mouseout&&s.mouseout(e)}function v(e){e=a(e),s.dragging&&(x(document,"mousemove",h),x(document,"mouseup",v),y(s.canvas,"mousemove",h),y(s.canvas,"mouseup",v),s.dragging=!1),delete A.mouse,s.touchend&&s.touchend(e),s.mouseup&&s.mouseup(e)}function w(e){e=a(e),s.click&&s.click(e)}function l(n){s.keys[e(n.keyCode)]=!0,s.keys[n.keyCode]=!0,s.keydown&&s.keydown(n)}function g(n){s.keys[e(n.keyCode)]=!1,s.keys[n.keyCode]=!1,s.keyup&&s.keyup(n)}var M={8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",27:"ESCAPE",32:"SPACE",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN"};for(var k in M)p.keys[M[k]]=!1;var A={};y(s.canvas,"touchstart",u),y(s.canvas,"touchmove",r),y(s.canvas,"touchend",c),y(s.canvas,"mouseover",m),y(s.canvas,"mousedown",d),y(s.canvas,"mousemove",h),y(s.canvas,"mouseout",f),y(s.canvas,"mouseup",v),y(s.canvas,"click",w),y(document,"keydown",l),y(document,"keyup",g),y(window,"resize",i)}function u(){if(!h){var e=Date.now();s.dt=e-s.now,s.millis+=s.dt,s.now=e,s.update&&s.update(s.dt),s.autoclear&&s.clear(),s.draw&&s.draw(s)}h=++h%s.interval,f=requestAnimationFrame(u)}function i(){if(s.autoresize){var e=s.type===d?s.style:s.canvas;s.fullscreen?(s.height=e.height=window.innerHeight,s.width=e.width=window.innerWidth):(e.height=s.height,e.width=s.width),s.resize&&s.resize()}}var s,r=0,c="canvas",m="web-gl",d="dom",h=0,f=-1,v={},w=[],l={fullscreen:!0,autostart:!0,autoclear:!0,autopause:!0,autoresize:!0,container:document.body,interval:1,type:c},g={PI:Math.PI,TWO_PI:2*Math.PI,HALF_PI:Math.PI/2,QUARTER_PI:Math.PI/4,abs:Math.abs,acos:Math.acos,asin:Math.asin,atan2:Math.atan2,atan:Math.atan,ceil:Math.ceil,cos:Math.cos,exp:Math.exp,floor:Math.floor,log:Math.log,max:Math.max,min:Math.min,pow:Math.pow,round:Math.round,sin:Math.sin,sqrt:Math.sqrt,tan:Math.tan,random:function(e,n){return e&&"number"==typeof e.length&&e.length?e[Math.floor(Math.random()*e.length)]:("number"!=typeof n&&(n=e||1,e=0),e+Math.random()*(n-e))}},p={millis:0,now:0/0,dt:0/0,keys:{},mouse:{x:0,y:0,ox:0,oy:0,dx:0,dy:0},touches:[],initialized:!1,dragging:!1,running:!1,start:function(){s.running||(s.setup&&!s.initialized&&(s.autopause&&(y(window,"focus",s.start),y(window,"blur",s.stop)),s.setup()),s.initialized=!0,s.running=!0,s.now=Date.now(),u())},stop:function(){cancelAnimationFrame(f),s.running=!1},toggle:function(){(s.running?s.stop:s.start)()},clear:function(){s.canvas&&(s.canvas.width=s.canvas.width)},destroy:function(){var e,n,t,o,a,u;w.splice(w.indexOf(s),1),s.stop();for(n in v){for(t=v[n],a=0,u=t.length;u>a;a++)e=t[a],x(e.el,n,e.fn);delete v[n]}s.container.removeChild(s.canvas);for(o in s)s.hasOwnProperty(o)&&delete s[o]}},y=function(){function e(e,n,t){v[n]||(v[n]=[]),v[n].push({el:e,fn:t})}return window.addEventListener?function(n,t,o){n.addEventListener(t,o,!1),e(n,t,o)}:window.attachEvent?function(n,t,o){n.attachEvent("on"+t,o),e(n,t,o)}:function(n,t,o){n["on"+t]=o,e(n,t,o)}}(),x=function(){function e(e,n,t){if(v[n])for(var o,a=v[n].length-1;a>=0;a--)o=v[n][a],o.el===e&&o.fn===t&&v[n].splice(a,1)}return window.removeEventListener?function(n,t,o){n.removeEventListener(t,o,!1),e(n,t,o)}:window.detachEvent?function(n,t,o){n.detachEvent("on"+t,o),e(n,t,o)}:(el["on"+ev]=null,e(el,ev,fn),void 0)}();return{CANVAS:c,WEB_GL:m,DOM:d,instances:w,create:e}}();Date.now||(Date.now=function(){return+new Date}),function(){for(var e=0,n=["ms","moz","webkit","o"],t=0;n.length>t&&!window.requestAnimationFrame;++t)window.requestAnimationFrame=window[n[t]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[n[t]+"CancelAnimationFrame"]||window[n[t]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(n){var t=Date.now(),o=Math.max(0,16-(t-e)),a=window.setTimeout(function(){n(t+o)},o);return e=t+o,a}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){clearTimeout(e)})}();
View
25 ajax/libs/sketch.js/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "sketch.js",
+ "filename": "sketch.min.js",
+ "version": "1.0.0",
+ "description": "sketch.js is a tiny (~5k) boilerplate for creating JavaScript based creative coding experiments.",
+ "homepage": "https://github.com/soulwire/sketch.js/",
+ "keywords": [
+ "framework",
+ "audio",
+ "video",
+ "html5"
+ ],
+ "maintainers": [
+ {
+ "name": "soulwire",
+ "web": "https://github.com/soulwire/"
+ }
+ ],
+ "repositories": [
+ {
+ "type": "git",
+ "url": "https://github.com/soulwire/sketch.js.git"
+ }
+ ]
+}

0 comments on commit 69f7dc8

Please sign in to comment.