-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (31 loc) · 913 Bytes
/
script.js
File metadata and controls
40 lines (31 loc) · 913 Bytes
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
38
39
40
window.addEventListener('load', () => {
const canvas = document.querySelector('#canvas');
const ctx = canvas.getContext('2d');
//Resizing
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
//Variables
let painting = false;
function StartPosition(e) {
painting = true;
Draw(e);
}
function FinishPosition() {
painting = false;
ctx.beginPath();
}
function Draw(e) {
if (!painting) return;
ctx.lineWidth = 10;
ctx.lineCap = "round";
ctx.strokeStyle = "red";
ctx.lineTo(e.clientX, e.clientY);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(e.clientX, e.clientY);
}
//EventListeners
canvas.addEventListener('mousedown', StartPosition)
canvas.addEventListener('mouseup', FinishPosition)
canvas.addEventListener('mousemove', Draw)
});