-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (54 loc) · 1.69 KB
/
Copy pathindex.js
File metadata and controls
68 lines (54 loc) · 1.69 KB
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
61
62
63
64
65
66
67
68
(function() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var drawGrid = function(ctx, cols, rows, width, height) {
var gridWidth = Math.floor(width / cols);
var gridHeight = Math.floor(height / rows);
ctx.strokeRect(1, 1, width - 2, height - 2);
for (var i = 1; i < cols; i++) {
ctx.beginPath();
ctx.moveTo(gridWidth * i, 0);
ctx.lineWidth = 0.5;
ctx.lineTo(gridWidth * i, height);
ctx.stroke();
}
for (var i = 1; i < rows; i++) {
ctx.beginPath();
ctx.moveTo(0, gridHeight * i);
ctx.lineWidth = 0.5;
ctx.lineTo(width, gridHeight * i);
ctx.stroke();
}
};
var drawBlock = function(ctx, count, cols, rows, width, height) {
var gridWidth = Math.floor(width / cols);
var gridHeight = Math.floor(height / rows);
ctx.fillStyle = "red";
var row = 0;
var col = 0
for (var i = 0; i< count; i++) {
ctx.fillRect(col * gridWidth, 4 + gridHeight * row, gridWidth, gridHeight - 8);
col++;
if (col == cols) {
col = 0;
row++;
}
}
};
var calcMonth = function(year, month, day) {
var now = new Date();
var birth = new Date(year, month - 1, day);
var end = now.getFullYear() - 1;
var start = birth.getFullYear() + 1;
var years = end - start;
var result = years * 12;
var startMonths = 12 - birth.getMonth() - 1;
var endMonths = now.getMonth() + 1;
result += startMonths + endMonths;
return result;
};
var count = calcMonth(1986, 10, 22);
console.log("count = " + count);
drawBlock(ctx, count, 30, 30, 600, 600);
drawGrid(ctx, 30, 30, 600, 600);
}).call(this);