-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
135 lines (120 loc) · 2.61 KB
/
index.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Digital Clock</title>
<style>
#clock{
text-align:center;
}
#myClock{
background-color:lightblue;
}
</style>
<script>
window.onload=displayTime;
var monthArr=["January","February","March","April","May","June","July","August","September","October","November","December"];
var dayArr=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
function displayTime() {
var d=new Date();
var date=d.getDate();
var day=dayArr[d.getDay()];
var month=monthArr[d.getMonth()];
var year=d.getFullYear();
var h=d.getHours();
var H=h;
var m=d.getMinutes();
var M=m;
var s=d.getSeconds();
var S=s;
var mer;
if(h==0&&m==0&&s==0)
mer="Midnight";
else if(h==12&&m==0&&s==0)
mer="Noon";
else if(h<12)
mer="AM";
else
mer="PM";
if(h==0)
h=12;
else if(h>0&&h<10)
h="0"+h;
else if(h>12&&h<22)
h="0"+(h-12);
else if(h>21)
h=h-12;
if(m<10)
m="0"+m;
if(s<10)
s="0"+s;
var canv=document.getElementById("myClock");
var pi=Math.PI;
canv.width=600;
canv.height=600;
var ctx=canv.getContext("2d");
ctx.arc(300,300,250,0,2*pi);
ctx.fillStyle="white";
ctx.fill();
ctx.arc(300,300,250,0,2*pi);
ctx.lineWidth=15;
ctx.strokeStyle="brown";
ctx.stroke();
for(var a=pi/2,b=12,r=215;a<pi*5/2;a+=pi/6,b--) {
ctx.font="40px arial";
ctx.fillStyle="black";
ctx.textAlign="center";
ctx.fillText(b,300+r*Math.cos(a),300-r*Math.sin(a)+15);
}
ctx.font="25px arial";
ctx.fillStyle="black";
ctx.textAlign="center";
ctx.fillText(day,300,190);
ctx.fillText(date+" "+month+" "+year,300,220);
ctx.fillText(h+":"+m+":"+s+" "+mer,300,420);
ctx.beginPath();
ctx.moveTo(300,300);
ctx.arc(300,300,8,0,2*pi);
ctx.fillStyle="red";
ctx.closePath();
ctx.fill();
ctx.beginPath();
r1=8;
r2=150;
a1=pi/2-2*pi/43200*(H*3600+M*60+S);
ctx.moveTo(300+r1*Math.cos(a1),300-r1*Math.sin(a1));
ctx.lineTo(300+r2*Math.cos(a1),300-r2*Math.sin(a1));
ctx.lineWidth=5;
ctx.strokeStyle="black";
ctx.closePath();
ctx.stroke();
ctx.beginPath();
R1=8;
R2=180;
a2=pi/2-2*pi/3600*(M*60+S);
ctx.moveTo(300+R1*Math.cos(a2),300-R1*Math.sin(a2));
ctx.lineTo(300+R2*Math.cos(a2),300-R2*Math.sin(a2));
ctx.lineWidth=5;
ctx.strokeStyle="black";
ctx.closePath();
ctx.stroke();
ctx.beginPath();
q=180;
a3=pi/2-2*pi/60*(S);
ctx.moveTo(300,300);
ctx.lineTo(300+q*Math.cos(a3),300-q*Math.sin(a3));
ctx.lineWidth=3;
ctx.strokeStyle="red";
ctx.closePath();
ctx.stroke();
setTimeout(displayTime,500);
}
</script>
</head>
<body>
<div id="clock">
<canvas id="myClock">
</canvas>
</div>
</body>
</html>