-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.js
executable file
·33 lines (31 loc) · 897 Bytes
/
grid.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
var quaterLine = 'rgba(0, 0, 0, 0.05)';
var halfLine = 'rgba(0, 0, 0, 0.1)';
var fullLine = 'rgba(0, 0, 0, 0.2)';
function setLineColor(ctx, i) {
if (i % 100 == 0) {
ctx.strokeStyle = fullLine;
} else if (i % 100 == 50) {
ctx.strokeStyle = halfLine;
} else {
ctx.strokeStyle = quaterLine;
}
}
window.makeGrid = function(canvas) {
let ctx = canvas.getContext('2d');
ctx.setLineDash([4, 4]);
ctx.lineDashOffset = 0.3;
for (let i = canvas.width; i >= 0; i -= 25) {
setLineColor(ctx, i);
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i, canvas.height);
ctx.stroke();
}
for (let i = canvas.height; i >= 0; i -= 25) {
setLineColor(ctx, i);
ctx.beginPath();
ctx.moveTo(0, i);
ctx.lineTo(canvas.width, i);
ctx.stroke();
}
}