Created
October 19, 2011 14:07
-
-
Save austinbv/1298389 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
mouse_draw = (e) -> | |
position = find_position(@) | |
e._x = e.clientX - position.x | |
e._y = e.clientY - position.y | |
$('#x').text(e._x) | |
$('#y').text(e._y) | |
if currentTool() == 'eraser' | |
$('#drawing').hide() | |
func = Narwhal.tools[currentTool()][e.type] | |
if func? | |
func(e) | |
$ -> | |
$("#drawing").bind('mousedown mousemove mouseup', mouse_draw) | |
This file contains hidden or 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
Narwhal.tools.pencil = | |
started: false | |
shape: null | |
mousedown: (e) -> | |
$("#drawing").draw((ctx) -> | |
ctx.beginPath() | |
ctx.strokeStyle = "#000" | |
ctx.lineWidth = Narwhal.global_width | |
ctx.lineCap = 'round' | |
ctx.moveTo(e._x, e._y) | |
) | |
@started = true | |
@shape = new Narwhal.Squiggle({x: e._x, y: e._y}) | |
return | |
mousemove: (e) -> | |
if @started | |
@shape.addPoints({x: e._x, y: e._y}) | |
$("#drawing").draw((ctx) -> | |
ctx.lineTo(e._x, e._y) | |
ctx.stroke() | |
) | |
mouseup: (e) -> | |
if @started | |
@started = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment