Created
March 26, 2020 18:16
-
-
Save richarddprasad/b969b32d231a4fe80a17100f60f30ee2 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 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 = `#${randomColor()}`; | |
context.lineWidth = 3; | |
context.stroke(); | |
context.closePath(); | |
} | |
} | |
function randomColor(): string { | |
const color = new Array<string>(6); | |
for (let i = 0; i < 6; i++) { | |
const val = Math.floor(Math.random() * 16); | |
if (val < 10) { | |
color[i] = val.toString(); | |
} else { | |
color[i] = String.fromCharCode(val + 87); | |
} | |
} | |
return color.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment