-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
96 lines (85 loc) · 1.75 KB
/
sketch.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
var canvas;
var isTimerEnabled;
var isRunning;
var counter;
function setup() {
canvas = createCanvas(window.innerWidth, window.innerHeight);
canvasInit();
}
function draw() {
background(0);
updateTimer();
drawTimer();
taskAlarm();
}
function keyPressed() {
if(keyCode == 32 || keyCode == 13) { // spacebar or enter
isTimerEnabled = true;
isRunning = !isRunning;
}
else if (keyCode == 27) { // escape
counter = 0;
isTimerEnabled = false;
isRunning = false;
}
else if (keyCode == 84) { // 't'
alarm.play();
}
return 0;
}
function canvasInit()
{
counter = 0;
isTimerEnabled = false;
isRunning = false;
alarm = loadSound("/assets/alarm.mp3");
setInterval(clockTick, 1000);
}
function updateTimer()
{
totalseconds = counter;
s = Math.floor(totalseconds%60);
m = Math.floor((totalseconds/60)%60);
h = Math.floor(totalseconds/3600);
}
function clockTick()
{
if (isRunning) {
counter++;
}
}
function drawTimer()
{
if (isTimerEnabled) {
if (h > 0) {
timerText = h.toString() + ":";
}
else {
timerText = "";
}
timerText += m.toString().padStart(2, '0') + ":" + s.toString().padStart(2, '0');
}
else {
timerText = "BME09";
}
fill(255);
//ellipse(width/2,height/2,50,50);
textSize(width/4);
textAlign(CENTER, CENTER);
text(timerText, width/2, height/2);
}
function taskAlarm()
{
if (isTimerEnabled) {
switch(totalseconds) {
case 900:
case 1080:
case 1081:
case 1200:
case 1201:
case 1202: {
alarm.play();
}
}
}
}