-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
45 lines (37 loc) · 973 Bytes
/
background.js
File metadata and controls
45 lines (37 loc) · 973 Bytes
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
function Background (context, settings) {
const _INITIAL_SETTINGS = {
bgColor: '#000000',
lineColor: '#ffffff',
lineWidth: 1
};
const {
bgColor,
lineColor,
lineWidth
} = { ..._INITIAL_SETTINGS, ...settings };
let _width = 0, _height = 0, _tileSize = 0;
this.setDimensions = function (width, height, tileSize) {
_width = width;
_height = height;
_tileSize = tileSize;
}
function drawLine ( begin, end ) {
context.strokeStyle = lineColor;
context.lineWidth = lineWidth;
context.beginPath();
context.moveTo(...begin);
context.lineTo(...end);
context.stroke();
}
this.draw = function () {
context.fillStyle = bgColor;
context.fillRect(0, 0, _width, _height);
for (let i = _tileSize; i < _width; i+=_tileSize) {
drawLine([i, 0], [i, _height]);
drawLine([0, i], [_width, i]);
}
}
this.clear = function () {
context.clearRect(0, 0, _width, _height);
}
}