-
Notifications
You must be signed in to change notification settings - Fork 1
/
v-drawer.js
59 lines (48 loc) · 1.7 KB
/
v-drawer.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Drawer
{
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Setup
constructor(canvas)
{
this.canvas_ = canvas;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Methods
clear()
{
let context = this.canvas_.getContext("2d");
context.clearRect(0, 0, this.canvas_.width, this.canvas_.height);
}
drawLineFromTo(from, to, color, thickness)
{
let context = this.canvas_.getContext("2d");
context.strokeStyle = color;
context.lineWidth = thickness;
//context.lineJoin = round;
context.beginPath();
context.moveTo(from[0], from[1]);
//Smoother line
//Source: https://stackoverflow.com/questions/7054272/how-to-draw-smooth-curve-through-n-points-using-javascript-html5-canvas/7058606#7058606
var x = (from[0] + to[0]) / 2;
var y = (from[1] + to[1]) / 2;
// curve through the last two points
context.quadraticCurveTo(from[0], from[1], x, y);
context.quadraticCurveTo(from[0], from[1], to[0], to[1]);
context.stroke();
}
drawBorder()
{
let context = this.canvas_.getContext("2d");
context.strokeStyle = '#00ffff';
context.lineWidth = 6;
context.strokeRect(0, 0, this.canvas_.width, this.canvas_.height);
}
clearBorder()
{
let context = this.canvas_.getContext("2d");
context.clearRect(0, 0, this.canvas_.width, 3);
context.clearRect(0, 0, 3, this.canvas_.height);
context.clearRect(0, this.canvas_.height - 3, this.canvas_.width, this.canvas_.height);
context.clearRect(this.canvas_.width - 3, 0, this.canvas_.width, this.canvas_.height);
}
}