diff options
| author | Jules Laplace <jules@okfoc.us> | 2013-02-23 20:01:04 -0800 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2013-02-23 20:01:04 -0800 |
| commit | af0a54f6b5738272362bec1a2fb62e09bf719e3b (patch) | |
| tree | 9445544562041196a0c05e5645f79d036b03082d /public/js/draw.js | |
| parent | c1ab3ea0daff8c40983893d00160ec4dfb8c0f1f (diff) | |
pull in drawing stuff
Diffstat (limited to 'public/js/draw.js')
| -rw-r--r-- | public/js/draw.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/public/js/draw.js b/public/js/draw.js index e69de29..5cc4163 100644 --- a/public/js/draw.js +++ b/public/js/draw.js @@ -0,0 +1,44 @@ +var drawing = false; +var workspace = document.getElementById("workspace"); +workspace.width = window.innerWidth * 0.9; +workspace.height = window.innerHeight; +workspace.id = "workspace"; +var workspaceCtx = workspace.getContext('2d'); +var lastpoint; + +workspace.onmousedown = function(e){ + drawing = true; +} +document.onmousemove = function(e){ + if (drawing) { + newpoint = new Point(e); + if (lastpoint) { + draw(lastpoint, newpoint); + } + lastpoint = newpoint; + } +} +window.onmouseup = function(){ + if (drawing) { + drawing = false; + lastpoint = null; + } +} +function draw(start, end){ + var halfBrushW = brush.width/2; + var halfBrushH = brush.height/2; + + var distance = parseInt( Trig.distanceBetween2Points( start, end ) ); + var angle = Trig.angleBetween2Points( start, end ); + + for ( var z=0; (z<=distance || z==0); z += 2 ) { + var x = start.x + (Math.sin(angle) * z) - halfBrushW; + var y = start.y + (Math.cos(angle) * z) - halfBrushH; + workspaceCtx.drawImage(brush.canvas, x, y); + } +} + +function Point(e) { + this.x = e.pageX - workspace.offsetLeft; + this.y = e.pageY - workspace.offsetTop; +} |
