-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (28 loc) · 840 Bytes
/
app.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
38
39
40
41
42
43
var canvas = document.getElementById("draw");
var ctx = canvas.getContext("2d");
resize();
function resize() {
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
}
var pos = { x: 0, y: 0 };
function setPosition(e) {
pos.x = e.clientX;
pos.y = e.clientY;
}
function draw(e) {
if (e.buttons !== 1) return;
var color = document.getElementById("hex").value;
ctx.beginPath();
ctx.lineWidth = 20;
ctx.lineCap = "round";
ctx.strokeStyle = color;
ctx.moveTo(pos.x, pos.y);
setPosition(e);
ctx.lineTo(pos.x, pos.y);
ctx.stroke();
}
window.addEventListener("resize", resize);
document.addEventListener("mousemove", draw);
document.addEventListener("mousedown", setPosition);
document.addEventListener("mouseenter", setPosition);