Skip to content

Instantly share code, notes, and snippets.

@austinbv
Created October 19, 2011 14:07
Show Gist options
  • Save austinbv/1298389 to your computer and use it in GitHub Desktop.
Save austinbv/1298389 to your computer and use it in GitHub Desktop.
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)
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