Last active
April 1, 2018 23:52
-
-
Save sirdarthvader/6edf8ab9eb359e86b99e9ec65abed548 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
let hue = 0; | |
let direction = true; | |
function draw (e) { | |
if(!isDrawing) return ; | |
console.log(e); | |
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`; | |
ctx.beginPath(); | |
ctx.moveTo(lastX, lastY); | |
ctx.lineTo(e.offsetX, e.offsetY); | |
ctx.stroke(); | |
[lastX, lastY] = [e.offsetX, e.offsetY]; | |
hue++; | |
if(hue>=360){ | |
hue = 0; | |
} | |
if(ctx.lineWidth >= 75 || ctx.lineWidth <= 1) { | |
direction = !direction; | |
} | |
if(direction){ | |
ctx.lineWidth++; | |
} else { | |
ctx.lineWidth = 1; | |
} | |
} | |
canvas.addEventListener('mousemove', draw); | |
canvas.addEventListener('mousedown', (e) => { | |
isDrawing = true; | |
[lastX, lastY] = [e.offsetX, e.offsetY]; | |
}); | |
canvas.addEventListener('mouseup', ()=> isDrawing = false); | |
canvas.addEventListener('mouseout', () => isDrawing = false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment