-
-
Save hughsk/9041690 to your computer and use it in GitHub Desktop.
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
// 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){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ctx e