@@ -5,48 +5,125 @@ import document from "document";
5
5
import clock from "clock" ;
6
6
clock . granularity = "seconds" ;
7
7
8
+ //grab screen elements
8
9
let background = document . getElementById ( "background" ) ;
9
- let play = document . getElementById ( "playButton" ) ;
10
- let pause = document . getElementById ( "pauseButton" ) ;
10
+ let backgroundColor = document . getElementsByClassName ( "backgroundColor" )
11
11
let progressArc = document . getElementById ( "progressArc" ) ;
12
+ let backgroundArc = document . getElementById ( "backgroundArc" ) ;
12
13
let countdown = document . getElementById ( "countdown" ) ;
13
14
let sprintCounter = document . getElementById ( "sprintCounter" ) ;
14
-
15
- let currentIndex = background . value ;
15
+ let playPauseButton = document . getElementById ( "playPauseButton" ) ;
16
+ let playPauseIcon = playPauseButton . getElementById ( "combo-button-icon" ) ;
17
+ let playPauseIconPressed = playPauseButton . getElementById ( "combo-button-icon-press" ) ;
18
+ let oldBackground = background . value ;
16
19
background . value = 0 ;
17
20
21
+
18
22
let intervalInSeconds = 1500 ;
19
23
let formattedHours = 0 ;
20
24
let formattedMinutes = 0 ;
21
25
let formattedSeconds = 0 ;
22
26
let seconds = intervalInSeconds ;
27
+ let counting = false ;
23
28
24
29
function secondsToAngle ( seconds ) {
25
30
//degree per second * elapsedseconds
26
31
return ( 360 / intervalInSeconds ) * seconds ;
27
32
}
28
33
29
34
function progress ( ) {
30
- seconds -- ;
31
-
32
- //calculate and update angle
33
- let a = secondsToAngle ( intervalInSeconds - seconds ) ;
34
- progressArc . sweepAngle = a ;
35
-
36
- //calculate time left
37
- formattedHours = Math . floor ( ( seconds / 60 / 60 ) % 60 ) ;
38
- formattedMinutes = Math . floor ( ( seconds / 60 ) % 60 ) ;
39
- formattedSeconds = Math . floor ( seconds % 60 ) ;
40
-
41
- //pad with 0
42
- formattedHours = formattedHours < 10 ? "0" + formattedHours : formattedHours ;
43
- formattedMinutes = formattedMinutes < 10 ? "0" + formmatedMinutes : formattedMinutes ;
44
- formattedSeconds = formattedSeconds < 10 ? "0" + formattedSeconds : formattedSeconds ;
45
-
46
- //update countdown text
47
- countdown . text = `${ formattedHours } :${ formattedMinutes } :${ formattedSeconds } ` ;
35
+ if ( counting ) {
36
+ seconds -- ;
37
+
38
+ //calculate and update angle
39
+ let a = secondsToAngle ( intervalInSeconds - seconds ) ;
40
+ progressArc . sweepAngle = a ;
41
+
42
+ //calculate time left
43
+ formattedHours = Math . floor ( ( seconds / 60 / 60 ) % 60 ) ;
44
+ formattedMinutes = Math . floor ( ( seconds / 60 ) % 60 ) ;
45
+ formattedSeconds = Math . floor ( seconds % 60 ) ;
46
+
47
+ //pad with 0
48
+ formattedHours = formattedHours < 10 ? "0" + formattedHours : formattedHours ;
49
+ formattedMinutes = formattedMinutes < 10 ? "0" + formmatedMinutes : formattedMinutes ;
50
+ formattedSeconds = formattedSeconds < 10 ? "0" + formattedSeconds : formattedSeconds ;
51
+
52
+ //update countdown text
53
+ countdown . text = `${ formattedHours } :${ formattedMinutes } :${ formattedSeconds } ` ;
54
+ }
48
55
}
49
56
50
57
clock . ontick = ( ) => progress ( ) ;
51
58
52
- play . onactivate = ( evt ) => { }
59
+ playPauseButton . onactivate = ( evt ) => {
60
+ //countingdown
61
+ if ( counting ) {
62
+ counting = false
63
+ playPauseIcon . image = "play.png" ;
64
+ playPauseIconPressed . image = "play_press.png" ;
65
+ } //paused
66
+ else {
67
+ counting = true ;
68
+ playPauseIcon . image = "pause.png" ;
69
+ playPauseIconPressed . image = "pause_press.png" ;
70
+ }
71
+
72
+ }
73
+
74
+
75
+ //style functions
76
+ setInterval ( ( ) => {
77
+ if ( background . value != oldBackground ) {
78
+ applyStyle ( background . value ) ;
79
+ oldBackground = background . value ;
80
+ } } , 100 ) ;
81
+
82
+ function applyStyle ( value ) {
83
+ let colorProfile = style [ value ] ;
84
+ backgroundColor [ value ] . style . fill = colorProfile . background ;
85
+ progressArc . style . fill = colorProfile . accentColor ;
86
+ backgroundArc . style . fill = colorProfile . backgroundArc ;
87
+ countdown . style . fill = colorProfile . accentColor ;
88
+ playPauseButton . style . fill = colorProfile . accentColor ;
89
+ // pauseButton.style.fill = colorProfile.accentColor;
90
+ sprintCounter . style . fill = colorProfile . baseColor ;
91
+ }
92
+
93
+ const style = [
94
+ { background : "#000" ,
95
+ baseColor : "#fff" ,
96
+ accentColor : "#FF9F1E" ,
97
+ backgroundArc : "#636366"
98
+ } ,
99
+ { background : "#000" ,
100
+ baseColor : "#fff" ,
101
+ accentColor : "#00FFFF" ,
102
+ backgroundArc : "#636366"
103
+ } ,
104
+ { background : "#000" ,
105
+ baseColor : "#fff" ,
106
+ accentColor : "#48f442" ,
107
+ backgroundArc : "#636366"
108
+ } ,
109
+ { background : "#000" ,
110
+ baseColor : "#fff" ,
111
+ accentColor : "#f727ca" ,
112
+ backgroundArc : "#636366"
113
+ } ,
114
+ { background : "#44090C" ,
115
+ baseColor : "#fff" ,
116
+ accentColor : "#fff" ,
117
+ backgroundArc : "#636366"
118
+ } ,
119
+ { background : "#51a3a3" ,
120
+ baseColor : "#fff" ,
121
+ accentColor : "#dfcc74" ,
122
+ backgroundArc : "#636366"
123
+ } ,
124
+ { background : "#0b032d" ,
125
+ baseColor : "#fff" ,
126
+ accentColor : "#f67e7d" ,
127
+ backgroundArc : "#636366"
128
+ }
129
+ ] ;
0 commit comments