-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComponent.js
executable file
·131 lines (66 loc) · 1.89 KB
/
Component.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
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
const canvas = document.querySelector('canvas');
canvas.setAttribute('height', window.innerHeight/1.5);
canvas.setAttribute('width', window.innerWidth/1.5);
const ctx = canvas.getContext('2d');
function deg (degrees) {
return (degrees * (Math.PI/180)) - Math.PI/2;
}
function Circle(type, color) {
this.x = (canvas.width)/2;
this.y = (canvas.height)/2;
this.rad = () => {
if(type === 'minutes'){
return (canvas.width/3)+15;
}else{
return canvas.width/3;
}
};
this.color = color;
this.type = type;
this.time = ()=>{
let date = new Date();
if(type === 'minutes') {
return date.getMinutes();
}else{
return date.getSeconds();
}
};
this.draw = function(changeColor) {
ctx.beginPath();
ctx.strokeStyle = changeColor === undefined ? this.color : changeColor;
ctx.lineWidth = 8;
ctx.lineCap = 'round';
ctx.arc(this.x, this.y, this.rad(), -Math.PI, deg(this.time())*6, false);
ctx.stroke();
ctx.closePath();
};
}
function getZero(number){
if(number < 10){
return `0${number}`;
}else{
return number;
}
}
function TextClock(){
let date = new Date();
let sc = date.getSeconds();
let mn = date.getMinutes();
let hr = date.getHours();
let text = `${getZero(hr)} : ${getZero(mn)} : ${getZero(sc)}`;
this.x = (canvas.width/2)-(ctx.measureText(text).width)/2;
this.y = canvas.height/2;
ctx.beginPath();
ctx.fillStyle = '#fff';
ctx.font = "25px -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif";
ctx.fillText(text, this.x, this.y);
ctx.closePath();
}
function BorderClock(color) {
ctx.beginPath();
ctx.strokeStyle = color;
ctx.lineWidth = 10;
ctx.arc(canvas.width/2, canvas.height/2, (canvas.width/3)+30, 0, Math.PI*2, false);
ctx.stroke();
ctx.closePath();
}