-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.js
69 lines (48 loc) · 1.34 KB
/
clock.js
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
// clock.js
var DEBUG = true;
var canvas;
var ctx;
var clockFace;
// constants
var boxWidth = 100;
var textRadius = null;
var hourRad = Math.PI / 6.0;
var minuteRad = Math.PI / 30.0;
var secondRad = Math.PI / 30.0;
var centerPos = 300;
function drawCurrent() {
resize_to_window();
clockFace.setSize(boxWidth);
clockFace.clearCtx();
var clock = new Clock();
clockFace.drawHands(clock);
clockFace.drawFace();
window.requestAnimationFrame(drawCurrent);
}
function scale_constants() {
centerPos = boxWidth / 2.0;
textRadius = centerPos * 0.75;
hourHandRadius = centerPos * 0.4;
minuteHandRadius = centerPos * 0.6;
secondHandRadius = centerPos * 0.7;
}
function resize_to_window() {
var windowWidth = window.innerWidth;
var windowHieght = window.innerHeight;
boxWidth = windowWidth > windowHieght
? windowHieght : windowWidth;
boxWidth *= 0.95;
ctx.canvas.style.width = window.boxWidth + 'px';
ctx.canvas.style.height = window.boxWidth + 'px';
ctx.canvas.width = window.boxWidth * window.devicePixelRatio;
ctx.canvas.height = window.boxWidth * window.devicePixelRatio;
boxWidth *= window.devicePixelRatio;
scale_constants();
}
function clock_init() {
canvas = document.getElementById('clock_widget');
ctx = canvas.getContext('2d');
clockFace = new ClockFace(ctx);
window.requestAnimationFrame(drawCurrent);
}
clock_init()