diff options
Diffstat (limited to 'public/js/draw.js')
| -rw-r--r-- | public/js/draw.js | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/public/js/draw.js b/public/js/draw.js index 14a112d..d97dba1 100644 --- a/public/js/draw.js +++ b/public/js/draw.js @@ -6,15 +6,14 @@ $(function(){ var workspaceCtx = workspace.getContext('2d'); var lastpoint; - workspaceCtx.fillStyle = "#fff"; - workspaceCtx.fillRect(0,0,workspace.width,workspace.height); + clearWorkspace(); var offset = $(workspace).offset(); - workspace.onmousedown = function(e){ + $(workspace).mousedown(function(e){ drawing = true; - } - document.onmousemove = function(e){ + }); + $(window).mousemove(function(e){ if (drawing) { newpoint = new Point(e, offset); if (lastpoint) { @@ -22,17 +21,35 @@ $(function(){ } lastpoint = newpoint; } - } - window.onmouseup = function(){ + }); + $(window).mouseup(function(){ if (drawing) { drawing = false; lastpoint = null; } + }); + function clearWorkspace(){ + workspaceCtx.fillStyle = "#fff"; + workspaceCtx.fillRect(0,0,workspace.width,workspace.height); } + $("#save-drawing").click(function(){ + var uri = workspace.toDataURL("image/png").replace("data:image/png;base64,",""); + console.log(uri.length); + console.log(atob(uri).length); + + var params = { + image: uri, + nick: Game.nick + }; + $.post("/upload", params, function(){ + console.log("saved"); + }); + clearWorkspace(); + }); + function draw(start, end){ var halfBrushW = brush.width/2; var halfBrushH = brush.height/2; - console.log(start.x, end.x); var distance = parseInt( Trig.distanceBetween2Points( start, end ) ); var angle = Trig.angleBetween2Points( start, end ); for ( var z=0; (z<=distance || z==0); z += 2 ) { |
