質問編集履歴
1
書式の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,178 +4,310 @@
|
|
4
4
|
|
5
5
|
> ```javascript
|
6
6
|
|
7
|
+
|
8
|
+
|
7
9
|
<!DOCTYPE html>
|
8
10
|
|
11
|
+
|
12
|
+
|
9
13
|
<html>
|
10
14
|
|
15
|
+
|
16
|
+
|
11
17
|
<head>
|
12
18
|
|
19
|
+
|
20
|
+
|
13
21
|
<meta charset="UTF-8">
|
14
22
|
|
23
|
+
|
24
|
+
|
15
25
|
<title>アナログ時計</title>
|
16
26
|
|
27
|
+
|
28
|
+
|
17
29
|
<script>
|
18
30
|
|
31
|
+
|
32
|
+
|
19
33
|
var canvas, context;
|
20
34
|
|
35
|
+
|
36
|
+
|
21
37
|
var x0 = 300, y0 = 300;
|
22
38
|
|
39
|
+
|
40
|
+
|
23
41
|
var win = null;
|
24
42
|
|
43
|
+
|
44
|
+
|
25
45
|
var PI = Math.PI;
|
26
46
|
|
27
47
|
|
28
48
|
|
29
|
-
|
30
|
-
|
31
49
|
var dateArray = new Array();
|
32
50
|
|
51
|
+
|
52
|
+
|
33
53
|
var hourArray = new Array();
|
34
54
|
|
55
|
+
|
56
|
+
|
35
57
|
var monthArray = ["Dec","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov"];
|
36
58
|
|
59
|
+
|
60
|
+
|
37
61
|
var dayArray = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
|
38
62
|
|
39
63
|
|
40
64
|
|
41
65
|
function init() {
|
42
66
|
|
67
|
+
|
68
|
+
|
43
69
|
canvas = document.getElementById("clock");
|
44
70
|
|
71
|
+
|
72
|
+
|
45
73
|
context = canvas.getContext("2d");
|
46
74
|
|
47
75
|
|
48
76
|
|
49
77
|
for (var i=0; i<12; i++) hourArray[i] = (i+11)%12+1;
|
50
78
|
|
79
|
+
|
80
|
+
|
51
81
|
for (var i=0; i<31; i++) dateArray[i] = (i+30)%31+1;
|
52
82
|
|
53
83
|
|
54
84
|
|
55
85
|
setInterval(draw,100);
|
56
86
|
|
87
|
+
|
88
|
+
|
57
89
|
}
|
58
90
|
|
59
91
|
|
60
92
|
|
61
93
|
fonction draw() {
|
62
94
|
|
95
|
+
|
96
|
+
|
63
97
|
var now=new Date();
|
64
98
|
|
99
|
+
|
100
|
+
|
65
101
|
var month=now.getMonth();
|
66
102
|
|
103
|
+
|
104
|
+
|
67
105
|
var date=now.getDate();
|
68
106
|
|
107
|
+
|
108
|
+
|
69
109
|
var day=now.getDay();
|
70
110
|
|
111
|
+
|
112
|
+
|
71
113
|
var hour=now.getHours();
|
72
114
|
|
115
|
+
|
116
|
+
|
73
117
|
var minute=now.getMinutes();
|
74
118
|
|
119
|
+
|
120
|
+
|
75
121
|
var second=now.getSeconds();
|
76
122
|
|
77
123
|
|
78
124
|
|
79
125
|
context.fillStyle=document.getElementById("backColor").value;
|
80
126
|
|
127
|
+
|
128
|
+
|
81
129
|
context.fillRect(0,0,canvas.width,canvas.height);
|
82
130
|
|
83
131
|
|
84
132
|
|
85
133
|
var timeColor=document.getElementById("timeColor").value;
|
86
134
|
|
135
|
+
|
136
|
+
|
87
137
|
drawCircle(x0,y0,280,10,timeColor)
|
88
138
|
|
139
|
+
|
140
|
+
|
89
141
|
context.fillStyle=document.getElementById("clockColor").value;
|
90
142
|
|
143
|
+
|
144
|
+
|
91
145
|
context.fill();
|
92
146
|
|
147
|
+
|
148
|
+
|
93
149
|
drawDial(hourArray,245,12,timeColor,"bold 48px arial");
|
94
150
|
|
95
151
|
|
96
152
|
|
97
153
|
var dateColor=document.getElementById("dateColor").value;
|
98
154
|
|
155
|
+
|
156
|
+
|
99
157
|
drawCircle(x0,y0,160,2,dateColor)
|
100
158
|
|
159
|
+
|
160
|
+
|
101
161
|
drawCircle(x0,y0,200,2,dateColor)
|
102
162
|
|
163
|
+
|
164
|
+
|
103
165
|
drawCircle(x0,y0,110,2,dateColor)
|
104
166
|
|
167
|
+
|
168
|
+
|
105
169
|
drawDial(monthArray,135,12,dateColor,"bold 18px arial");
|
106
170
|
|
171
|
+
|
172
|
+
|
107
173
|
drawDial(dateArray,180,31,dateColor,"bold 28px arial");
|
108
174
|
|
175
|
+
|
176
|
+
|
109
177
|
drawDial(dayArray,90,7,dateColor,"bold 18px arial");
|
110
178
|
|
111
179
|
|
112
180
|
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
113
185
|
var dateHandColor=document.getElementById("dateHandColor").value;
|
114
186
|
|
187
|
+
|
188
|
+
|
115
189
|
drawHand(month+1,12,113,22,3,dateHandColor);
|
116
190
|
|
191
|
+
|
192
|
+
|
117
193
|
drawHand(date,31,158,22,3,dateHandColor);
|
118
194
|
|
195
|
+
|
196
|
+
|
119
197
|
drawHand(day,7,68,22,3,dateHandColor);
|
120
198
|
|
121
199
|
|
122
200
|
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
123
205
|
var timeHandColor=document.getElementById("timeHandColor").value;
|
124
206
|
|
207
|
+
|
208
|
+
|
125
209
|
drawHand(hour+minute/60,12,200,0,10,timeHandColor);
|
126
210
|
|
211
|
+
|
212
|
+
|
127
213
|
drawHand(minute+second/60,60,240,0,6,timeHandColor);
|
128
214
|
|
215
|
+
|
216
|
+
|
129
217
|
drawHand(second,60,260,0,3,timeHandColor);
|
130
218
|
|
219
|
+
|
220
|
+
|
131
|
-
}
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
132
226
|
|
133
227
|
|
134
228
|
|
135
229
|
function drawCircle(x,y,r,width,color) {
|
136
230
|
|
231
|
+
|
232
|
+
|
137
233
|
context.lineWidth=width;
|
138
234
|
|
235
|
+
|
236
|
+
|
139
237
|
context.strokeStyle=color;
|
140
238
|
|
239
|
+
|
240
|
+
|
141
241
|
context.beginPath();
|
142
242
|
|
243
|
+
|
244
|
+
|
143
245
|
context.arc(x,y,r,0,2*PI);
|
144
246
|
|
247
|
+
|
248
|
+
|
145
249
|
context.stroke();
|
146
250
|
|
251
|
+
|
252
|
+
|
147
253
|
}
|
148
254
|
|
149
255
|
|
150
256
|
|
151
257
|
function drawDial(array,r,segment,color,font) {
|
152
258
|
|
259
|
+
|
260
|
+
|
153
261
|
context.textAlign="center";
|
154
262
|
|
263
|
+
|
264
|
+
|
155
265
|
context.textBaseline="middle";
|
156
266
|
|
267
|
+
|
268
|
+
|
157
269
|
context.fillStyle=color;
|
158
270
|
|
271
|
+
|
272
|
+
|
159
273
|
context.font=font;
|
160
274
|
|
275
|
+
|
276
|
+
|
161
277
|
var x,y;
|
162
278
|
|
279
|
+
|
280
|
+
|
163
281
|
for(var i=0;i<segment;i++){
|
164
282
|
|
283
|
+
|
284
|
+
|
165
285
|
x=x0+r*Math.cos(i/segment*2*PI-1/2*PI);
|
166
286
|
|
287
|
+
|
288
|
+
|
167
289
|
y=y0+r*Math.sin(i/segment*2*PI-1/2*PI);
|
168
290
|
|
291
|
+
|
292
|
+
|
169
293
|
context.fillText(array[i],x,y);
|
170
294
|
|
295
|
+
|
296
|
+
|
171
297
|
}
|
172
298
|
|
299
|
+
|
300
|
+
|
173
|
-
}
|
301
|
+
}
|
302
|
+
|
303
|
+
|
174
304
|
|
175
305
|
|
176
306
|
|
177
307
|
function drawHand(angle,segment,length,r,width,color) {
|
178
308
|
|
309
|
+
|
310
|
+
|
179
311
|
var x,y;
|
180
312
|
|
181
313
|
|
@@ -184,140 +316,272 @@
|
|
184
316
|
|
185
317
|
y=y0+length*Math.sin(angle/segment*2*PI-1/2*PI);
|
186
318
|
|
319
|
+
|
320
|
+
|
187
321
|
context.lineCap="round";
|
188
322
|
|
323
|
+
|
324
|
+
|
189
325
|
context.lineWidth=width;
|
190
326
|
|
327
|
+
|
328
|
+
|
191
329
|
context.strokeStyle=color;
|
192
330
|
|
331
|
+
|
332
|
+
|
193
333
|
context.beginPath();
|
194
334
|
|
335
|
+
|
336
|
+
|
195
337
|
context.moveTo(x0,y0);
|
196
338
|
|
339
|
+
|
340
|
+
|
197
341
|
context.lineTo(x,y);
|
198
342
|
|
343
|
+
|
344
|
+
|
199
345
|
context.stroke();
|
200
346
|
|
201
347
|
|
202
348
|
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
203
353
|
if(r>0){
|
204
354
|
|
355
|
+
|
356
|
+
|
205
357
|
x=x0+(length+r)*Math.cos(angle/segment*2*PI-1/2*PI);
|
206
358
|
|
359
|
+
|
360
|
+
|
207
361
|
y=y0+(length+r)*Math.sin(angle/segment*2*PI-1/2*PI);
|
208
362
|
|
363
|
+
|
364
|
+
|
209
365
|
drawCircle(x,y,r,5,color);
|
210
366
|
|
367
|
+
|
368
|
+
|
211
369
|
}
|
212
370
|
|
371
|
+
|
372
|
+
|
213
|
-
}
|
373
|
+
}
|
374
|
+
|
375
|
+
|
214
376
|
|
215
377
|
|
216
378
|
|
217
379
|
function openWindow() {
|
218
380
|
|
381
|
+
|
382
|
+
|
219
383
|
var w=document.getElemntById("winWidth").value;
|
220
384
|
|
385
|
+
|
386
|
+
|
221
387
|
var h=document.getElemntById("winHeight").value;
|
222
388
|
|
223
389
|
|
224
390
|
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
225
395
|
if(win != null) {
|
226
396
|
|
397
|
+
|
398
|
+
|
227
399
|
win.onunload=null;
|
228
400
|
|
401
|
+
|
402
|
+
|
229
403
|
win.close() ;
|
230
404
|
|
405
|
+
|
406
|
+
|
231
407
|
}
|
232
408
|
|
409
|
+
|
410
|
+
|
233
411
|
win=window.open("","","width="+w+",height="+h+",resizable=yes");
|
234
412
|
|
413
|
+
|
414
|
+
|
235
415
|
win.document.title="アナログ時計";
|
236
416
|
|
417
|
+
|
418
|
+
|
237
419
|
win.document.body.style.margin=0;
|
238
420
|
|
421
|
+
|
422
|
+
|
239
423
|
win.onresize=resizeClock;
|
240
424
|
|
425
|
+
|
426
|
+
|
241
427
|
win.onunload=resetClock;
|
242
428
|
|
243
429
|
|
244
430
|
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
245
435
|
var newCanvas=canvas.cloneNode(false);
|
246
436
|
|
437
|
+
|
438
|
+
|
247
439
|
win.document.body.innerHTML=newCanvas.outerHTML;
|
248
440
|
|
249
441
|
|
250
442
|
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
251
447
|
context.clearRect(0,0,canvas.width,canvas.height);
|
252
448
|
|
449
|
+
|
450
|
+
|
253
451
|
canvas=win.document.getElementById("clock");
|
254
452
|
|
453
|
+
|
454
|
+
|
255
455
|
context=canvas.getContext("2d");
|
256
456
|
|
457
|
+
|
458
|
+
|
257
459
|
resizeClock();
|
258
460
|
|
461
|
+
|
462
|
+
|
259
|
-
}
|
463
|
+
}
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
260
468
|
|
261
469
|
|
262
470
|
|
263
471
|
function resizeClock() {
|
264
472
|
|
473
|
+
|
474
|
+
|
265
475
|
canvas.style.width=win.innerWidth+"px";
|
266
476
|
|
477
|
+
|
478
|
+
|
267
479
|
canvas.style.heigth=win.innerHeight+"px";
|
268
480
|
|
481
|
+
|
482
|
+
|
269
|
-
}
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
270
488
|
|
271
489
|
|
272
490
|
|
273
491
|
function resetClock() {
|
274
492
|
|
493
|
+
|
494
|
+
|
275
495
|
canvas=document.getElementById("clock");
|
276
496
|
|
497
|
+
|
498
|
+
|
277
499
|
context=canvas.getContext("2d");
|
278
500
|
|
501
|
+
|
502
|
+
|
279
|
-
}
|
503
|
+
}
|
504
|
+
|
505
|
+
|
280
506
|
|
281
507
|
</script>
|
282
508
|
|
509
|
+
|
510
|
+
|
283
511
|
</head>
|
284
512
|
|
513
|
+
|
514
|
+
|
285
515
|
<body onload="init()">
|
286
516
|
|
517
|
+
|
518
|
+
|
287
519
|
<p>アナログ時計</p>
|
288
520
|
|
521
|
+
|
522
|
+
|
289
523
|
背景:<input type="color" id="backColor" value="#202020">
|
290
524
|
|
525
|
+
|
526
|
+
|
291
527
|
時計内背景:<input type="color" id="backColor" value="#000000">
|
292
528
|
|
529
|
+
|
530
|
+
|
293
531
|
時分秒文字盤:<input type="color" id="backColor" value="#FFFFFF">
|
294
532
|
|
533
|
+
|
534
|
+
|
295
535
|
時分秒針:<input type="color" id="backColor" value="#55f0e0">
|
296
536
|
|
537
|
+
|
538
|
+
|
297
539
|
月日曜日文字盤<input type="color" id="backColor" value="#B09080">
|
298
540
|
|
541
|
+
|
542
|
+
|
299
543
|
月日曜日針:<input type="color" id="backColor" value="#FF5555">
|
300
544
|
|
545
|
+
|
546
|
+
|
301
547
|
<hr>
|
302
548
|
|
549
|
+
|
550
|
+
|
303
551
|
ウインドウ幅:<input type="number" id="winWidth" value="300" step="100">
|
304
552
|
|
553
|
+
|
554
|
+
|
305
555
|
高さ:<input type="number" id="winHeigth" value="300" step="100">
|
306
556
|
|
557
|
+
|
558
|
+
|
307
559
|
<input type="button" value="別のウインドウで開く" onClick="openWindow()">
|
308
560
|
|
561
|
+
|
562
|
+
|
309
563
|
<hr>
|
310
564
|
|
565
|
+
|
566
|
+
|
311
567
|
<canvas id="clock" width="600" height="600"></canvas>
|
312
568
|
|
569
|
+
|
570
|
+
|
313
571
|
</body>
|
314
572
|
|
573
|
+
|
574
|
+
|
315
575
|
</html>
|
316
576
|
|
577
|
+
|
578
|
+
|
579
|
+
```
|
580
|
+
|
581
|
+
|
582
|
+
|
317
583
|
![イメージ説明](b365bf6971c0284b27b9fa0366c1d143.png)
|
318
584
|
|
319
585
|
|
320
586
|
|
321
587
|
色の表示選択までは出ているのですが、肝心のアナログ時計が表示されません。
|
322
|
-
|
323
|
-
```
|