Last active
March 26, 2020 18:39
-
-
Save richarddprasad/6a014f2d6dd97e3090d7b1110b6f1400 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
function handleMouseDown(evt: MouseEvent) { | |
mouseDown = true; | |
start = { | |
x: evt.clientX - canvasOffsetLeft, | |
y: evt.clientY - canvasOffsetTop, | |
}; | |
end = { | |
x: evt.clientX - canvasOffsetLeft, | |
y: evt.clientY - canvasOffsetTop, | |
}; | |
} | |
function handleMouseMove(evt: MouseEvent) { | |
if (mouseDown && context) { | |
start = { | |
x: end.x, | |
y: end.y, | |
}; | |
end = { | |
x: evt.clientX - canvasOffsetLeft, | |
y: evt.clientY - canvasOffsetTop, | |
}; | |
// Draw our path | |
context.beginPath(); | |
context.moveTo(start.x, start.y); | |
context.lineTo(end.x, end.y); | |
context.strokeStyle = '#00f'; | |
context.lineWidth = 3; | |
context.stroke(); | |
context.closePath(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment