var Biorhythm = {
byear: 2000,
bmonth: 1,
bday: 1,
syear: 2000,
smonth: 1,
sday: 1,
cv: undefined,
ctx: undefined,
init: function() {
this.cv = document.createElement('canvas');
this.cv.width = 900;
this.cv.height = 200;
this.ctx = this.cv.getContext('2d');
},
setDate: function(y1,m1,d1,y2,m2,d2) {
this.byear = y1;
this.bmonth = m1;
this.bday = d1;
this.syear = y2;
this.smonth = m2;
this.sday = d2;
},
calc: function() {
var elm = document.getElementById('result');
if (elm.childNodes.item(0)) {
elm.removeChild(elm.childNodes.item(0));
}
this.init();
elm.appendChild(this.cv);
this.drawRule();
this.drawBio();
},
drawRule: function() {
this.ctx.strokeStyle = 'rgb(180,180,180)';
for (var x = 0; x < 900; x += 12) {
this.ctx.beginPath();
this.ctx.moveTo(12.5 + x,21);
this.ctx.lineTo(12.5 + x,180);
this.ctx.stroke();
}
this.ctx.strokeStyle = 'rgb(120,120,120)';
this.ctx.beginPath();
this.ctx.moveTo(24.5,20);
this.ctx.lineTo(24.5,180);
this.ctx.stroke();
this.ctx.strokeStyle = 'rgb(120,120,120)';
this.ctx.beginPath();
this.ctx.moveTo(0,100.5);
this.ctx.lineTo(900,100.5);
this.ctx.stroke();
this.ctx.beginPath();
this.ctx.moveTo(0,20.5);
this.ctx.lineTo(900,20.5);
this.ctx.stroke();
this.ctx.beginPath();
this.ctx.moveTo(0,180.5);
this.ctx.lineTo(900,180.5);
this.ctx.stroke();
this.ctx.strokeStyle = 'rgb(180,180,180)';
this.ctx.beginPath();
this.ctx.moveTo(0,60.5);
this.ctx.lineTo(900,60.5);
this.ctx.stroke();
this.ctx.beginPath();
this.ctx.moveTo(0,140.5);
this.ctx.lineTo(900,140.5);
this.ctx.stroke();
this.ctx.strokeStyle = 'rgb(120,120,120)';
this.ctx.font = '11px sans-serif';
var da = new Date(this.syear, this.smonth - 1, this.sday);
for (var i = 0; i < 72; i += 4) {
this.ctx.fillText((da.getMonth() + 1) + '/' + da.getDate(), 22 + (i * 12), 199);
da.setDate(da.getDate() + 4);
this.ctx.beginPath();
this.ctx.moveTo(24.5 + (i * 12), 180);
this.ctx.lineTo(24.5 + (i * 12), 187);
this.ctx.stroke();
}
},
drawBio: function() {
var dat1 = new Date(this.byear, this.bmonth - 1, this.bday);
var dat2 = new Date(this.syear, this.smonth - 1, this.sday);
var diff = (dat2.getTime() - dat1.getTime()) / (1000 * 60 * 60 * 24) - 2;
var bioP = diff % 23;
var bioS = diff % 28;
var bioI = diff % 33;
this.ctx.beginPath();
this.ctx.strokeStyle = 'rgb(0,255,0)';
this.ctx.moveTo(-100,100);
for (var x = 0; x < 900; x++) {
var xx = x + (bioP * 12);
this.ctx.lineTo(x, Math.sin((xx / 23) * Math.PI / 180 * 30) * -80 + 100.5);
}
this.ctx.stroke();
this.ctx.beginPath();
this.ctx.strokeStyle = 'rgb(255,0,0)';
this.ctx.moveTo(-100,100);
for (var x = 0; x < 900; x++) {
var xx = x + (bioS * 12);
this.ctx.lineTo(x, Math.sin((xx / 28) * Math.PI / 180 * 30) * -80 + 100.5);
}
this.ctx.stroke();
this.ctx.beginPath();
this.ctx.strokeStyle = 'rgb(0,0,255)';
this.ctx.moveTo(-100,100);
for (var x = 0; x < 900; x++) {
var xx = x + (bioI * 12);
this.ctx.lineTo(x, Math.sin((xx / 33) * Math.PI / 180 * 30) * -80 + 100.5);
}
this.ctx.stroke();
},
dummy: undefined
};
JavaScript
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111