-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite.js
43 lines (35 loc) · 1.04 KB
/
rewrite.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
//taken from https://stackoverflow.com/questions/4288253/html5-canvas-100-width-height-of-viewport
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var radius = 2;
var dragging = false;
var alert;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
context.lineWidth = radius * 2;
function disengage() {
"use strict";
dragging = false;
context.beginPath();
}
function putPoint(event) {
"use strict";
if (dragging) {
context.lineTo(event.clientX, event.clientY);
context.stroke();
context.beginPath();
context.arc(event.clientX, event.clientY, radius, 0, 2 * Math.PI);
context.fill();
context.beginPath();
context.moveTo(event.clientX, event.clientY);
}
}
function engage() {
"use strict";
dragging = true;
putPoint();
}
canvas.addEventListener("mousedown", engage);
canvas.addEventListener("mousemove", putPoint);
canvas.addEventListener("mouseup", disengage);
alert("click and drag to draw on drawing board ");