-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock-object.js
More file actions
36 lines (29 loc) · 871 Bytes
/
clock-object.js
File metadata and controls
36 lines (29 loc) · 871 Bytes
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
// Clock Object
//
const HOUR_RAD = Math.PI / 6.0;
const MINUTE_RAD = Math.PI / 30.0;
const SECOND_RAD = Math.PI / 30.0;
function Clock() {
this.updateTime();
}
Clock.prototype.updateTime = function() {
this.time = new Date();
this.extractTime();
this.recalculateAngles();
}
Clock.prototype.extractTime = function() {
this.hour = this.time.getHours();
this.minute = this.time.getMinutes();
this.second = this.time.getSeconds();
this.millisec = this.time.getMilliseconds();
// This could be 24 hour?
this.hour %= 12;
}
Clock.prototype.recalculateAngles = function() {
var hourFrac = this.minute / 60.0;
var minuteFrac = this.second / 60.0;
var secFrac = this.millisec / 1000.0;
this.hourAngle = (this.hour + hourFrac) * HOUR_RAD;
this.minuteAngle = (this.minute + minuteFrac) * MINUTE_RAD;
this.secondAngle = (this.second + secFrac) * SECOND_RAD;
}