-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCountdown.pde
76 lines (68 loc) · 1.7 KB
/
Countdown.pde
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
class Countdown {
//requires Minim
AudioSnippet countdownBeep;
AudioPlayer dialogue;
int alphaNum = 150;
int secStart, secBeep;
int leaderCounter = 0;
int leaderCounterMax, leaderCounterBeep;
int leaderCircleSize = int(sW/2.2);
float leaderX = sW/2;
float leaderY = sH/2;
boolean beep = false;
boolean go = false;
PFont font;
int fontSize = int(leaderCircleSize * 0.9);
Countdown(int ss, int sb) {
secStart = ss;
secBeep = sb;
leaderCounterMax = secStart * fps;
leaderCounterBeep = (secStart-secBeep) * fps;
try{
countdownBeep = minim.loadSnippet("sounds/"+beepFile);
}catch(Exception e){
//
}
try{
if (dialogueFile!="none") dialogue = minim.loadFile("dialogue/"+dialogueFile);
}catch(Exception e){
//
}
font = createFont("Arial",fontSize);
}
void update() {
if(!go) {
rectMode(CORNER);
fill(200,alphaNum);
rect(0,0,sW,sH);
}
if(!beep) {
noStroke();
fill(255,alphaNum);
ellipseMode(CENTER);
ellipse(leaderX,leaderY,leaderCircleSize,leaderCircleSize);
fill(0,alphaNum);
textAlign(CENTER);
textFont(font,fontSize);
text(secStart-int(leaderCounter/fps),leaderX,leaderY+(fontSize/2.7));
if(leaderCounter==leaderCounterBeep) {
try{
countdownBeep.play();
}catch(Exception e){ }
beep=true;
}
}
if(leaderCounter<leaderCounterMax) {
leaderCounter++;
}
else if(leaderCounter==leaderCounterMax) {
go=true;
if(dialogueFile!="none") dialogue.play();
//leaderCounter++;
}
}
void stop() {
countdownBeep.close();
if(dialogueFile!="none") dialogue.close();
}
}