Skip to content

Instantly share code, notes, and snippets.

@hemanth
Created February 24, 2015 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemanth/a16d9e7380ca40a7dd96 to your computer and use it in GitHub Desktop.
Save hemanth/a16d9e7380ca40a7dd96 to your computer and use it in GitHub Desktop.
requirebin sketch
clear = require('clear-canvas');
//canvas setup
var canvas = document.createElement('canvas');
canvas.width = '500';
canvas.height = '300';
canvas.style.outline = "1px solid black";
document.body.appendChild(canvas);
// Get the context.
var ctx = canvas.getContext('2d');
// Draw a triangle.
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(200,20);
ctx.lineTo(120,120);
ctx.closePath();
ctx.stroke();
// Clear the canvas after 1000ms.
setTimeout( function() {clear(ctx, true);}.bind(this), 1000);
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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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}({"clear-canvas":[function(require,module,exports){"use strict";module.exports=function(ctx){var saveTransform=arguments[1]===undefined?true:arguments[1];if(saveTransform){ctx.save();ctx.setTransform(1,0,0,1,0,0)}ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height);if(saveTransform){ctx.restore()}}},{}]},{},[]);clear=require("clear-canvas");var canvas=document.createElement("canvas");canvas.width="500";canvas.height="300";canvas.style.outline="1px solid black";document.body.appendChild(canvas);var ctx=canvas.getContext("2d");ctx.beginPath();ctx.moveTo(20,20);ctx.lineTo(200,20);ctx.lineTo(120,120);ctx.closePath();ctx.stroke();setTimeout(function(){clear(ctx,true)}.bind(this),1e3);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"clear-canvas": "1.0.0"
}
}
<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