Skip to content

Instantly share code, notes, and snippets.

@richarddprasad
Last active March 26, 2020 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddprasad/6a014f2d6dd97e3090d7b1110b6f1400 to your computer and use it in GitHub Desktop.
Save richarddprasad/6a014f2d6dd97e3090d7b1110b6f1400 to your computer and use it in GitHub Desktop.
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