-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
157 lines (123 loc) · 3.19 KB
/
script.js
File metadata and controls
157 lines (123 loc) · 3.19 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
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
var canvas = document.getElementById("can");
var ctx = canvas.getContext("2d");
var grd2 =ctx.createRadialGradient(250, 250, 200, 250, 250, 250);
// grd2.addColorStop(0.70, 'white');
grd2.addColorStop(0.5, '#cc33ff');
grd2.addColorStop(1, '#3333cc');
clockMaker();
function clockMaker() {
//circle
ctx.beginPath();
ctx.arc(250, 250, 250, 0,2* Math.PI);
ctx.fillStyle = 'black' ;
ctx.fill() ;
//clock face
var grd1 = ctx.createRadialGradient(250, 250, 200, 250, 250, 250);
grd1.addColorStop(0.70, 'white');
grd1.addColorStop(0.80, '#3333cc');
grd1.addColorStop(0.9, '#6666ff');
ctx.fillStyle = grd1;
ctx.fill();
//numbers pos
// for(var i=1 ; i<=12 ; i++) {
// ctx.beginPath();
// ctx.arc(250, 250, 236, Math.PI / 180 * (-2 + 30*(i-1)), Math.PI / 180 * (2 + 30*(i-1)));
// ctx.fillstyle = grd2 ;
// CanvasRenderingContext2D.fill() ;
// }
// ctx.beginPath();
// ctx.arc(250, 250, 236, Math.PI / 180 * (-100), Math.PI / 180 * (100));
// ctx.fillStyle = 'black' ;
// ctx.fill() ;
// ctx.fillstyle = grd2 ;
// ctx.fill() ;
ctx.fillStyle = grd2
var rec12 = ctx.fillRect(247,11,8,26);
ctx.fillStyle = grd2
var rec6 = ctx.fillRect(247,465,8,26);
ctx.fillStyle = grd2
var rec9 = ctx.fillRect(11,247,26,8);
ctx.fillStyle = grd2
var rec3 = ctx.fillRect(465,247,26,8);
ctx.save() ; //rec11
ctx.translate(135, 55);
ctx.rotate(-Math.PI/6) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec10
ctx.translate(54, 137);
ctx.rotate(-Math.PI/3) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec8
ctx.translate(54, 365);
ctx.rotate(Math.PI/3) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec7
ctx.translate(137, 446);
ctx.rotate(Math.PI/6) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec5
ctx.translate(362, 446);
ctx.rotate(-Math.PI/6) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec4
ctx.translate(445, 364);
ctx.rotate(-Math.PI/3) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec2
ctx.translate(445, 138);
ctx.rotate(Math.PI/3) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //rec1
ctx.translate(363, 55);
ctx.rotate(Math.PI/6) ;
ctx.fillRect(-4,-13,8,26);
ctx.fillStyle = grd2
ctx.restore();
ctx.beginPath();
ctx.arc(250, 250, 8,0, Math.PI *2);
ctx.fillStyle = "#3333cc" ;
ctx.fill();
}
function clock() {
ctx.clearRect(0, 0, 500, 500);
clockMaker() ;
var pi = Math.PI
var timeNow = new Date()
var sec = timeNow.getSeconds() ;
var min = timeNow.getMinutes() ;
var hour = timeNow.getHours() % 12 ;
var secAng = -( pi * 3 / 2 + ( pi / 180 ) * 6 * sec )
var minAng = ( pi + ( pi / 180 ) * 6 * min )
var hourAng = (pi + ( pi / 180 ) * 30 * hour + ( pi / 180 ) * 0.5 * min )
ctx.moveTo(250, 250);
ctx.lineTo( 250 + 210 * Math.cos (secAng) ,250 - 210 * Math.sin (secAng)) ;
ctx.stroke();
ctx.save() ; //minutes
ctx.translate(250, 250);
ctx.rotate(minAng) ;
ctx.fillRect(-3,0,6,175);
ctx.fillStyle = grd2
ctx.restore();
ctx.save() ; //hour
ctx.translate(250, 250);
ctx.rotate(hourAng) ;
ctx.fillRect(-4,0,8,100);
ctx.fillStyle = grd2
ctx.restore();
console.log(sec);
}
setInterval(clock,1000)