-
Notifications
You must be signed in to change notification settings - Fork 1
/
canvas.js
43 lines (34 loc) · 991 Bytes
/
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
let width;
let height;
// Canvas related variables.
let canvas;
let c;
function resize_canvas(){
width = window.innerWidth;
height = window.innerHeight;
$("#canvas_background").css("width", width);
$("#canvas_background").css("height", height);
canvas.setAttribute("width", width);
canvas.setAttribute("height", height);
drawGrid();
}
function create_canvas(){
canvas = document.createElement("canvas");
c = canvas.getContext("2d");
resize_canvas();
}
function drawGrid(){
c.fillStyle = "#050505";
c.strokeStyle = "ghostwhite";
c.lineWidth = '0.15';
c.beginPath();
for(let i = X_OFFSET; i <= width; i += SQUARE_SIZE + X_OFFSET){
for(let j = Y_OFFSET; j <= height; j += SQUARE_SIZE + Y_OFFSET){
c.rect(i, j, SQUARE_SIZE, SQUARE_SIZE);
c.fillRect(i, j, SQUARE_SIZE, SQUARE_SIZE);
}
}
c.closePath();
c.stroke();
$("#canvas_background").append(canvas);
}