-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.js
45 lines (37 loc) · 1.31 KB
/
canvas.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
class Canvas {
constructor(className) {
this.canvas = (new CanvasCreation()).createHiDPICanvas(820, 820);
if (className != null) {
this.canvas.classList.add(className);
}
this.canvasContext = this.canvas.getContext("2d");
}
drawCircle(xCoordinate, yCoordinate, radius, fillColor, lineWidth, lineColor) {
this.canvasContext.beginPath();
this.canvasContext.arc(xCoordinate, yCoordinate, radius, 0, 2 * Math.PI);
if (fillColor != "unset") {
this.canvasContext.fillStyle = fillColor;
this.canvasContext.fill();
}
this.canvasContext.lineWidth = lineWidth;
this.canvasContext.strokeStyle = lineColor;
this.canvasContext.stroke();
}
drawLine(xStart, yStart, xEnd, yEnd) {
this.canvasContext.beginPath();
this.canvasContext.moveTo(xStart, yStart);
this.canvasContext.lineTo(xEnd, yEnd);
this.canvasContext.strokeStyle = "#000000";
this.canvasContext.stroke();
}
getMousePos(evt) {
var rect = this.canvas.getBoundingClientRect();
return {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
};
}
clear() {
this.canvasContext.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}