Skip to content

Instantly share code, notes, and snippets.

@mikolalysenko
Created August 6, 2013 02:41
Show Gist options
  • Save mikolalysenko/6161578 to your computer and use it in GitHub Desktop.
Save mikolalysenko/6161578 to your computer and use it in GitHub Desktop.
requirebin sketch
var raf = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
var zoom = 10
raf(canvas).on("data", function(dt) {
zoom += dt * 0.1
context.clearRect ( 0 , 0 , 500 , 500 )
context.beginPath()
context.arc(256-zoom/Math.sqrt(2), 256-zoom/Math.sqrt(2), zoom, 0, 2 * Math.PI, false)
context.closePath()
context.lineWidth = 5
context.strokeStyle = '#003300'
context.stroke()
context.beginPath()
context.arc(256,256,5, 0, 2*Math.PI)
context.closePath()
context.fillStyle = 'red'
context.fill()
})
require=function(e,t,n){function r(n,s){if(!t[n]){if(!e[n]){var o="function"==typeof require&&require;if(!s&&o)return o(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var a=t[n]={exports:{}};e[n][0].call(a.exports,function(t){var i=e[n][1][t];return r(i?i:t)},a,a.exports)}return t[n].exports}for(var i="function"==typeof require&&require,s=0;n.length>s;s++)r(n[s]);return r}({raf:[function(e,t){t.exports=e("FOtTOL")},{}],FOtTOL:[function(e,t){(function(){function n(e){function t(){var r=n.now(),a=r-i;i=r,s.emit("data",a),s.paused||o(t,e)}var i=n.now(),s=new r;return s.pause=function(){s.paused=!0},s.resume=function(){s.paused=!1},o(t,e),s}t.exports=n;var r=e("events").EventEmitter,i="undefined"==typeof window?this:window,s=i.performance&&i.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date},o=i.requestAnimationFrame||i.webkitRequestAnimationFrame||i.mozRequestAnimationFrame||i.msRequestAnimationFrame||i.oRequestAnimationFrame||(i.setImmediate?function(e){setImmediate(e)}:function(e){setTimeout(e,0)});n.polyfill=o,n.now=s})()},{events:1}],2:[function(e,t){var n=t.exports={};n.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){if(e.source===window&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var t=n.shift();t()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw Error("process.chdir is not supported")}},{}],1:[function(e,t,n){(function(e){function t(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;e.length>n;n++)if(t===e[n])return n;return-1}e.EventEmitter||(e.EventEmitter=function(){});var r=n.EventEmitter=e.EventEmitter,i="function"==typeof Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},s=10;r.prototype.setMaxListeners=function(e){this._events||(this._events={}),this._events.maxListeners=e},r.prototype.emit=function(e){if("error"===e&&(!this._events||!this._events.error||i(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var t=this._events[e];if(!t)return!1;if("function"==typeof t){switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);t.apply(this,n)}return!0}if(i(t)){for(var n=Array.prototype.slice.call(arguments,1),r=t.slice(),s=0,o=r.length;o>s;s++)r[s].apply(this,n);return!0}return!1},r.prototype.addListener=function(e,t){if("function"!=typeof t)throw Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",e,t),this._events[e])if(i(this._events[e])){if(!this._events[e].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:s,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),console.trace())}this._events[e].push(t)}else this._events[e]=[this._events[e],t];else this._events[e]=t;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){var n=this;return n.on(e,function r(){n.removeListener(e,r),t.apply(this,arguments)}),this},r.prototype.removeListener=function(e,n){if("function"!=typeof n)throw Error("removeListener only takes instances of Function");if(!this._events||!this._events[e])return this;var r=this._events[e];if(i(r)){var s=t(r,n);if(0>s)return this;r.splice(s,1),0==r.length&&delete this._events[e]}else this._events[e]===n&&delete this._events[e];return this},r.prototype.removeAllListeners=function(e){return 0===arguments.length?(this._events={},this):(e&&this._events&&this._events[e]&&(this._events[e]=null),this)},r.prototype.listeners=function(e){return this._events||(this._events={}),this._events[e]||(this._events[e]=[]),i(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]}})(e("__browserify_process"))},{__browserify_process:2}]},{},[]);var raf=require("raf"),canvas=document.createElement("canvas");canvas.width=500,canvas.height=500,document.body.appendChild(canvas);var context=canvas.getContext("2d"),zoom=10;raf(canvas).on("data",function(e){zoom+=.1*e,context.clearRect(0,0,500,500),context.beginPath(),context.arc(256-zoom/Math.sqrt(2),256-zoom/Math.sqrt(2),zoom,0,2*Math.PI,!1),context.closePath(),context.lineWidth=5,context.strokeStyle="#003300",context.stroke(),context.beginPath(),context.arc(256,256,5,0,2*Math.PI),context.closePath(),context.fillStyle="red",context.fill()});
<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