Skip to content

Instantly share code, notes, and snippets.

@slambert
Last active October 8, 2015 12:27
Show Gist options
  • Save slambert/98c973f463a3ac725ebc to your computer and use it in GitHub Desktop.
Save slambert/98c973f463a3ac725ebc to your computer and use it in GitHub Desktop.
A timer to let people know how long they have talked and when to wrap it up.
/*
Version .03
A timer to show people how long they have talked.
## 2015-10-08 14.27.11
- fix last bit of red?
*/
// Variables
int time;
int wait = 90000; // 90 seconds
//int wait = 3000; // 3 seconds for testing
int currentTime;
boolean startStop;
boolean resetCheck = false;
// Sound
import processing.sound.*;
SoundFile file;
// Font
PFont LeagueGothicBig;
PFont LeagueGothicSmall;
// end Variables
void setup(){
smooth();
noStroke();
frameRate(15); // no need to stress the GPU for this
fullScreen();
//size(250,250); // for testing
time = millis(); //store the current time at setup
// SOUND SETUP
// Load a soundfile from the /data folder of the sketch
file = new SoundFile(this, "time.aif");
// FONTS SETUP
// uncomment the following two lines to get a list of available fonts
// String[] fontList = PFont.list();
// println(fontList);
LeagueGothicBig = createFont("LeagueGothic-Regular", 64, true);
LeagueGothicSmall = createFont("LeagueGothic-Regular", 24, true);
} // end setup
void draw(){
background(255); //white
// Time check!
currentTime = millis() - time;
showInstructions();
//showCounter();
// Time is Up!
// if we're out of time
if(millis() - time >= wait){
background(255,0,0); // screen goes red
fill(255);
textAlign(CENTER, CENTER);
textFont(LeagueGothicBig);
text("FINISH YOUR SENTENCE", width/2, height/2);
// Play a sound!
if (resetCheck == false){ // if the sketch hasn't been reset
//println("resetCheck = " + resetCheck);
file.play(); // play the sound
resetCheck = !resetCheck; // mark it played
}
// Mark that it made it to the end
startStop = !startStop; //if it is, do something
wait = wait+1; // keep counting
}
int cWidth = colorWidth(currentTime);
//draw a visual cue
if (cWidth <= 217){ // green
fill(0,255,0,255-cWidth); // fade it out as it goes
//println(colorWidth);
} else { // go red when it gets far
fill(255,0,0,cWidth);
//println(colorWidth);
}
rect(0+timeWidth(currentTime),height/2,width-timeWidth(currentTime),1);
//println(timeWidth);
}
// KEYBOARD INPUTS
void keyReleased() {
// RESTART
if (key == 's') {
println("Start/Stop");
startStop = !startStop;
time = millis();//also update the stored time
resetCheck = false;
}
// Reset function
if (key == 'r') {
background(125);
resetCheck = !resetCheck;
}
} // end keyReleased
void showCounter(){
// show a counter at the bottom
textFont(LeagueGothicSmall);
//int displayCount = currentTime;
//displayCount = (wait - displayCount) /1000;
fill(192);
textAlign(RIGHT, CENTER);
text(currentTime /1000 + " seconds", width - width/5, height - 40);
// reset
textAlign(LEFT, CENTER);
} // end ShowCounter
void showInstructions(){
// show instructions on the screen
fill(125);
textAlign(LEFT, CENTER);
textFont(LeagueGothicBig);
text("1. Name", width/4, height/5);
text("2. Organization", width/4, height/5 +72);
text("3. Creative side", width/4, height/5 +144);
text("4. Moment you \"stepped off the curb\"", width/4, height/5 +216);
} // end showInstructions
int timeWidth(int currentTime_){
// remap timer to the width of the sketch
float tw = map(currentTime_, 0, wait, 0, width); // map the clock to the width of the sketch
int rtw = round(tw);
return rtw;
} // end timeWidth
int colorWidth(int currentTime_){
// remap timer to a color range of 0-255
float cw = map(currentTime_, 0, wait, 0, 255);
int rcw = round(cw);
return rcw;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment