-
Notifications
You must be signed in to change notification settings - Fork 0
/
orig_clock.html
199 lines (178 loc) · 5.36 KB
/
orig_clock.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="https://images.eq3.com/product-definitions/cjuedn73z05650162zt3g6fu8/instance/cjv6ukkqm02p30118culhn925/THUMBNAIL/4ad0d9c2-7dc6-40cc-9a61-df08bcce4e0e.jpg">
<title>Time</title>
</head>
<canvas id="canvas" width="400" height="400"
style="background-color:#333">
<div id="clock"></div>
</canvas>
<body>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height / 2;
ctx.translate(radius, radius);
radius = radius * 0.90
setInterval(drawClock, 1000);
function drawClock() {
drawFace(ctx, radius);
drawNumbers(ctx, radius);
drawTime(ctx, radius);
}
function drawFace(ctx, radius) {
var grad;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, 2*Math.PI);
ctx.fillStyle = 'white';
ctx.fill();
grad = ctx.createRadialGradient(0,0,radius*0.95, 0,0,radius*1.05);
grad.addColorStop(0, '#ff751a');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1, '#00ff00');
ctx.strokeStyle = grad;
ctx.lineWidth = radius*0.1;
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, radius*0.1, 0, 2*Math.PI);
ctx.fillStyle = '#00ff00';
ctx.fill();
}
function drawNumbers(ctx, radius) {
var ang;
var num;
ctx.font = radius*0.15 + "px arial";
ctx.textBaseline="middle";
ctx.textAlign="center";
for(num = 1; num < 13; num++){
ang = num * Math.PI / 6;
ctx.rotate(ang);
ctx.translate(0, -radius*0.85);
ctx.rotate(-ang);
ctx.fillText(num.toString(), 0, 0);
ctx.rotate(ang);
ctx.translate(0, radius*0.85);
ctx.rotate(-ang);
}
}
function drawTime(ctx, radius){
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
//hour
hour=hour%12;
hour=(hour*Math.PI/6)+
(minute*Math.PI/(6*60))+
(second*Math.PI/(360*60));
drawHand(ctx, hour, radius*0.5, radius*0.07);
//minute
minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));
drawHand(ctx, minute, radius*0.8, radius*0.07);
// second
second=(second*Math.PI/30);
drawHand(ctx, second, radius*0.9, radius*0.02);
}
function drawHand(ctx, pos, length, width) {
ctx.beginPath();
ctx.lineWidth = width;
ctx.lineCap = "round";
ctx.moveTo(0,0);
ctx.rotate(pos);
ctx.lineTo(0, -length);
ctx.stroke();
ctx.rotate(-pos);
}
</script>
<style type="text/css">
body {
font-family: Arial, San-Serif;
font-size: 10px;
}
#ws { width: 100%; }
@media(min-width: 780px){ #ws { max-width: 760px; margin: 0 auto; } }
#header {background:#ddd; padding: 5px;border-radius:.5em .5em 0 0;}
#content {background:white; padding: 5px; }
h1 {margin:0px;}
#header a{text-decoration:none;color:#888;}
#header a:hover {color:black;text-decoration:none;}
.bow {background:white;color:black;padding:0 .1em;}
.wob {background:black;color:white;padding:0 .1em;border-radius:50%;}
#lbg {background:white;}
#bc span, #bc a {display:inline-block;padding:.5em 1em;}
#bc span {background:white;border:1px solid #888; border-bottom: 1px solid white;}
#cid {float:left;}
#hsup {float:left;text-align:left;}
.ad-b {margin-top:1em;}
.clear {clear:both;}
#dclock {text-align:left;color:#000000;font-family: helvetica, arial, sans-serif;}
#timer {font-size:3em;}
form {margin-top:1em;}
.blink {display:inline-block;cursor:pointer;background:#ccc;border:1px solid #999;padding:0 5px;}
#clink {background:#eee;font-family:Consolas,Monaco,Courier New;}
</style>
<script type="text/javascript">
var timer, alarm;
function prepareSound(){
var butsnd = document.getElementById("bsnd");
if (butsnd.getAttribute("data-sound-loaded") == 0){
butsnd.setAttribute("data-sound-loaded", 1);
snd = document.getElementById('ce-snd');
snd.play();
snd.volume = 0.0;
snd.pause();
snd.volume = 1.0;
}
if (butsnd.getAttribute("data-sound-status") == 0){
butsnd.src = "/sound.png";
butsnd.setAttribute("data-sound-status", 1);
butsnd.setAttribute("title", "Sound On");
}
else {
butsnd.src = "/no-sound.png";
butsnd.setAttribute("data-sound-status", 0);
butsnd.setAttribute("title", "Sound Off");
}
}
function setAlarm(){
var mi = dselect.m.options.selectedIndex;
var m = dselect.m.options[mi].value;
clearTimeout(alarm);
alarm = setTimeout(function(){playBeep()},+m*1000*60);
}
function setClock(){
timer = setInterval(function (){
var d = new Date();
var h = d.getHours();
if (h>=12){h = h%12==0?12:h%12; a = 'PM';}
else { a = 'AM';}
var m = d.getMinutes();
var s = d.getSeconds();
document.getElementById("timer").innerHTML = '<span id="h">' + ('00'+h).slice(-2) + '</span>:<span id="m">' + ('00'+m).slice(-2)+ '</span>:<span id="s">' + ('00'+s).slice(-2) + '</span> '+a;
},
1000);
}
function playBeep(){
if (document.getElementById("bsnd").getAttribute("data-sound-status")==1){
snd = document.getElementById('ce-snd');
//snd.volume = 1.0;
snd.play();
snd.loop = true;
setTimeout(function () {snd.pause();}, 3000);
}
//reset change
dselect.m.options.selectedIndex = 0;
clearTimeout(alarm);
}
</script>
<div id="dclock">
<div id="timer"><script type="text/javascript">setClock();</script></div>
<form name="dselect" id="dselect">
<label>
<br/>
<audio id="ce-snd" preload="auto">
<source src="/beep.mp3" type='audio/mpeg; codecs="mp3"'>
<source src="/beep.ogg" type='audio/ogg; codecs="vorbis"'>
</audio>
</html>