Skip to content

Instantly share code, notes, and snippets.

@hughsk
Forked from NHQ/ctx.js
Created February 16, 2014 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughsk/9041690 to your computer and use it in GitHub Desktop.
Save hughsk/9041690 to your computer and use it in GitHub Desktop.
// the base module
module.exports = function(canvas){
if('string' == typeof canvas) canvas = dcoument.getElementById(canvas)
touchdown.start(canvas)
var ctx = window.ctx = canvas.getContext('2d')
var pen = basic(ctx)
ctx.translate(0.5, 0.5)
ctx.lineWidth = 10
ctx.globalCompositeOperation = 'destination-over';
ctx.strokeStyle = 'rgba(50, 205, 33, .31)'
canvas.addEventListener('touchdown', function(e){pen.down(e.detail)})
canvas.addEventListener('deltavector', function(e){pen.move(e.detail)})
canvas.addEventListener('liftoff', function(e){pen.up(e.detail)})
}
// the pen module
var trig = require('../trig')
module.exports = function(ctx, denit){
var prev = [0,0]
return {
down: touchdown,
move: deltavector,
up: liftoff
}
function touchdown(evt){
ctx.beginPath()
prev[0] = evt.x
prev[1] = evt.y
}
function deltavector(evt){
ctx.beginPath()
ctx.moveTo(prev[0], prev[1])
ctx.lineTo(evt.x, evt.y)
ctx.stroke()
ctx.closePath()
prev[0] = evt.x
prev[1] = evt.y
}
function liftoff(evt){
}
}
@minseobV
Copy link

ctx e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment