-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
40 lines (34 loc) · 1.14 KB
/
index.ts
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
type Dim = {nRow: number, nCol: number};
class CanvasApp {
private canvas: HTMLCanvasElement | null;
private ctx: CanvasRenderingContext2D | null;
public dim: Dim;
constructor() {
let canvas = document.getElementById('raycast') as HTMLCanvasElement;
let ctx = canvas.getContext("2d");
this.dim = {nRow: 7, nCol: 7};
ctx.lineWidth = 0.05;
ctx.fillStyle = "grey";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "black";
this.canvas = canvas;
this.ctx = ctx;
this.ctx.scale(
canvas.height / this.dim.nCol,
canvas.width / this.dim.nRow,
);
this.drawGrid(this.dim);
}
private drawGrid(dim: Dim) {
for (let iRow = 0; iRow <= dim.nRow; iRow++) {
this.ctx.moveTo(0, iRow);
this.ctx.lineTo(this.canvas.width, iRow);
this.ctx.stroke();
}
for (let iCol= 0; iCol <= dim.nCol; iCol++) {
this.ctx.moveTo(iCol, 0);
this.ctx.lineTo(iCol, this.canvas.height);
this.ctx.stroke();
}
}
}