-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
37 lines (29 loc) · 771 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const colors = document.querySelectorAll(".col");
const canvas = document.querySelector(".drawing-pannel");
const ctx = canvas.getContext('2d');
const canvasOffsetX=canvas.offsetLeft;
const canvasOffsetY=canvas.offsetTop;
let isPainting=false;
let lineWidth=5;
let startX;
let startY;
canvas.addEventListener("mousedown", function(e) {
isPainting = true;
startX = e.clientX;
startY = e.clientY;
});
canvas.addEventListener('mousemove',draw)
function draw(e) {
console.log('draw');
if (! isPainting) return;
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(e.offsetX, e.offsetY);
ctx.stroke();
[lastX, lastY] = [e.offsetX, e.offsetY];
}
function stopDrawing()
{
console.log('stopDrawing');
isPainting=false;
}