This repository was archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSlide.js
More file actions
84 lines (66 loc) · 2.45 KB
/
Copy pathSlide.js
File metadata and controls
84 lines (66 loc) · 2.45 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import COLORS from './COLORS.js';
export default class Slide {
constructor(canvas) {
this.canvas = canvas;
this.canvas.width = 800;
this.canvas.height = 650;
this.context = this.canvas.getContext('2d');
this.setColor(COLORS.background);
this.context.fillRect(0, 0, 800, 650);
this.setDefaultStyles();
}
setDefaultStyles() {
this.setColor(COLORS.light);
this.context.lineWidth = 2;
this.context.lineCap = 'round';
this.context.lineJoin = 'round';
this.context.font = '20px Architects Daughter';
this.context.textAlign = 'center';
this.context.textBaseline = 'middle';
}
setColor(color) {
this.context.strokeStyle = color;
this.context.fillStyle = color;
}
drawText(text, x, y, align) {
this.context.textAlign = align || 'center';
this.context.fillText(text, x, y);
}
drawMatrix(positionX, positionY, matrix) {
const height = matrix.length * 50;
const width = matrix[0].length * 50;
this.context.beginPath();
this.context.moveTo(positionX, positionY);
this.context.lineTo(positionX, positionY + height);
this.context.moveTo(positionX, positionY);
this.context.lineTo(positionX + 10, positionY);
this.context.moveTo(positionX, positionY + height);
this.context.lineTo(positionX + 10, positionY + height);
this.context.moveTo(positionX + width, positionY);
this.context.lineTo(positionX + width, positionY + height);
this.context.moveTo(positionX + width, positionY);
this.context.lineTo(positionX + width - 10, positionY);
this.context.moveTo(positionX + width, positionY + height);
this.context.lineTo(positionX + width - 10, positionY + height);
this.context.stroke();
for (let y = 0; y < matrix.length; y++) {
for (let x = 0; x < matrix[y].length; x++) {
this.drawText(
matrix[y][x],
positionX + x * 50 + 25,
positionY + y * 50 + 25,
'center'
);
}
}
}
drawNumber(number) {
this.setColor(COLORS.light);
this.drawText(number, 770, 620, 'right');
}
drawBox(x, y, width, height) {
this.context.beginPath();
this.context.rect(x, y, width, height);
this.context.stroke();
}
}