made with requirebin
Created
August 8, 2014 18:14
-
-
Save davidguttman/f042def21b552c1a9b8d to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/davidguttman/loading-wave | |
var Wave = require('loading-wave') | |
var wave = Wave({ | |
width: 100, | |
height: 100, | |
n: 10 | |
}) | |
document.body.appendChild(wave.el) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}if(canPost){var queue=[];window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.once=noop;process.off=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],zwrJnk:[function(require,module,exports){var Bar,TWOPI,Wave,raf;raf=require("raf");TWOPI=Math.PI*2;module.exports=function(){return function(func,args,ctor){ctor.prototype=func.prototype;var child=new ctor,result=func.apply(child,args);return Object(result)===result?result:child}(Wave,arguments,function(){})};Wave=function(opts){var bar,k,v,_i,_j,_len,_ref,_ref1,_ref2,_ref3,_results;this.opts=opts!=null?opts:{};this.el=document.createElement("div");_ref=this.opts,this.height=_ref.height,this.width=_ref.width,this.color=_ref.color,this.n=_ref.n;if(this.height==null){this.height=100}if(this.width==null){this.width=100}if(this.n==null){this.n=10}if(this.color==null){this.color="steelblue"}_ref1={position:"relative",width:this.width+"px",height:this.height+"px"};for(k in _ref1){v=_ref1[k];this.el.style[k]=v}this.bars=function(){_results=[];for(var _i=1,_ref2=this.n;1<=_ref2?_i<=_ref2:_i>=_ref2;1<=_ref2?_i++:_i--){_results.push(_i)}return _results}.apply(this).map(function(_this){return function(n){var bar,period;period=750/(n+10/2);return bar=new Bar({x:n*_this.width/_this.n,y:_this.height/2,w:_this.width/_this.n-2,boxHeight:_this.height,color:_this.color,period:period})}}(this));_ref3=this.bars;for(_j=0,_len=_ref3.length;_j<_len;_j++){bar=_ref3[_j];this.el.appendChild(bar.el)}this.timeStart=Date.now();this.loop();return this};Wave.prototype.loop=function(){var bar,elapsed,_i,_len,_ref;if(this.stopped){return}elapsed=Date.now()-this.timeStart;_ref=this.bars;for(_i=0,_len=_ref.length;_i<_len;_i++){bar=_ref[_i];bar.update(elapsed)}return raf(function(_this){return function(){return _this.loop()}}(this))};Wave.prototype.start=function(){if(this.stopped){this.stopped=false;return this.loop()}};Wave.prototype.stop=function(){return this.stopped=true};Bar=function(opts){var k,v,_ref,_ref1;this.opts=opts!=null?opts:{};this.el=document.createElement("div");_ref=this.opts,this.period=_ref.period,this.x=_ref.x,this.y=_ref.y,this.w=_ref.w,this.h=_ref.h,this.color=_ref.color,this.boxHeight=_ref.boxHeight;if(this.period==null){this.period=1}if(this.x==null){this.x=0}if(this.y==null){this.y=0}if(this.w==null){this.w=10}if(this.h==null){this.h=10}if(this.boxHeight==null){this.boxHeight=100}if(this.color==null){this.color="black"}_ref1={position:"absolute",width:this.w+"px",left:this.x-this.w+"px",top:this.boxHeight/2+"px",height:this.y-this.boxHeight+"px",background:this.color};for(k in _ref1){v=_ref1[k];this.el.style[k]=v}this.setPos(this.x,this.y);return this};Bar.prototype.update=function(time){var t;t=time/this.period/TWOPI;this.y=Math.sin(-t)/2*this.boxHeight;return this.setPos()};Bar.prototype.setPos=function(){var k,v,_ref,_ref1,_results,_results1;if(this.y>0){_ref={top:this.boxHeight/2+"px",height:this.y+"px"};_results=[];for(k in _ref){v=_ref[k];_results.push(this.el.style[k]=v)}return _results}else{_ref1={top:this.boxHeight/2+this.y+"px",height:-this.y+"px"};_results1=[];for(k in _ref1){v=_ref1[k];_results1.push(this.el.style[k]=v)}return _results1}}},{raf:4}],"loading-wave":[function(require,module,exports){module.exports=require("zwrJnk")},{}],4:[function(require,module,exports){var now=require("performance-now"),global=typeof window==="undefined"?{}:window,vendors=["moz","webkit"],suffix="AnimationFrame",raf=global["request"+suffix],caf=global["cancel"+suffix]||global["cancelRequest"+suffix],native=true;for(var i=0;i<vendors.length&&!raf;i++){raf=global[vendors[i]+"Request"+suffix];caf=global[vendors[i]+"Cancel"+suffix]||global[vendors[i]+"CancelRequest"+suffix]}if(!raf||!caf){native=false;var last=0,id=0,queue=[],frameDuration=1e3/60;raf=function(callback){if(queue.length===0){var _now=now(),next=Math.max(0,frameDuration-(_now-last));last=next+_now;setTimeout(function(){var cp=queue.slice(0);queue.length=0;for(var i=0;i<cp.length;i++){if(!cp[i].cancelled){try{cp[i].callback(last)}catch(e){setTimeout(function(){throw e},0)}}}},next)}queue.push({handle:++id,callback:callback,cancelled:false});return id};caf=function(handle){for(var i=0;i<queue.length;i++){if(queue[i].handle===handle){queue[i].cancelled=true}}}}module.exports=function(fn){if(!native){return raf.call(global,fn)}return raf.call(global,function(){try{fn.apply(this,arguments)}catch(e){setTimeout(function(){throw e},0)}})};module.exports.cancel=function(){caf.apply(global,arguments)}},{"performance-now":5}],5:[function(require,module,exports){(function(process){(function(){var getNanoSeconds,hrtime,loadTime;if(typeof performance!=="undefined"&&performance!==null&&performance.now){module.exports=function(){return performance.now()}}else if(typeof process!=="undefined"&&process!==null&&process.hrtime){module.exports=function(){return(getNanoSeconds()-loadTime)/1e6};hrtime=process.hrtime;getNanoSeconds=function(){var hr;hr=hrtime();return hr[0]*1e9+hr[1]};loadTime=getNanoSeconds()}else if(Date.now){module.exports=function(){return Date.now()-loadTime};loadTime=Date.now()}else{module.exports=function(){return(new Date).getTime()-loadTime};loadTime=(new Date).getTime()}}).call(this)}).call(this,require("/home/admin/browserify-cdn/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))},{"/home/admin/browserify-cdn/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":1}]},{},[]);var Wave=require("loading-wave");var wave=Wave({width:100,height:100,n:10});document.body.appendChild(wave.el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"loading-wave": "0.0.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment