-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathgrid.js
60 lines (48 loc) · 1.37 KB
/
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
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
function Canvas(tag) {
this.canvas = document.getElementById(tag);
this.ctx = this.canvas.getContext("2d");
}
Canvas.prototype.Width = function () {
return this.canvas.width;
}
Canvas.prototype.Height = function () {
return this.canvas.height;
}
Canvas.prototype.SaveState = function () {
this.ctx.save();
}
Canvas.prototype.RestoreState = function () {
this.ctx.restore();
}
Canvas.prototype.Box = function (x1, y1, w, h, style) {
this.ctx.fillStyle = style;
this.ctx.fillRect(x1, y1, w, h);
}
Canvas.prototype.Move = function (x) {
this.canvas.style.position = "absolute";
this.canvas.style.left = x + "px";
}
Canvas.prototype.Graph = function (array) {
this.ctx.Box;
}
function Grid(canvas, grid_width, grid_height, default_style) {
this.canvas = canvas;
this.grid_height = grid_height;
this.grid_width = grid_width;
}
Grid.prototype.BlockHeight = function () {
return this.canvas.Height() / this.grid_height;
}
Grid.prototype.BlockWidth = function () {
return this.canvas.Width() / this.grid_width;
}
Grid.prototype.Plot = function (x, y, style) {
this.canvas.Box(x * this.BlockWidth(),
y * this.BlockHeight(),
this.BlockWidth(),
this.BlockHeight(),
style);
}
Grid.prototype.Clear = function (style) {
this.canvas.Box(0, 0, this.canvas.Width(), this.canvas.Height(), style);
}