Skip to content

Instantly share code, notes, and snippets.

@nataliefreed
Created February 8, 2016 00:50
Show Gist options
  • Save nataliefreed/05e7bdbd4b16dbbfa789 to your computer and use it in GitHub Desktop.
Save nataliefreed/05e7bdbd4b16dbbfa789 to your computer and use it in GitHub Desktop.
float totalMinutes = 60;
float minutesPerStation = 15;
StringList programmers;
int numStations;
int rotation = 0;
float timer = -1*minutesPerStation*60*1000; //so we start right away
String displayText = "Press any key to start!";
boolean running = false;
int backgroundColor = 255;
void setup() {
size(1200, 700);
textAlign(CENTER, CENTER);
colorMode(HSB);
PFont font = createFont("HelveticaNeue", 36, true);
textFont(font);
fill(0);
String studentString = "Banana Apple Pear Orange Grape Strawberry Raspberry Peach Tangerine";
String[] students = studentString.split(" ");
float numRotations = totalMinutes / minutesPerStation;
String teacher = "Potato";
numStations = ceil(students.length / 2.0);
boolean teacherIncluded = (students.length % 2) != 0;
programmers = new StringList(students);
if (teacherIncluded) {
programmers.append(teacher);
}
programmers.shuffle();
}
void draw() {
background(backgroundColor);
text(displayText, width/2, height/2);
if(running) {
text(round(minutesPerStation*60*1000 - (millis() - timer))/1000, width/2, height - 50);
if(millis() - timer > minutesPerStation*60*1000) { //if timer elapsed
backgroundColor = color(random(0, 255), 100, 200);
displayText = "";
for(int station=0;station<numStations;station++) {
displayText = displayText + getNextPairings(rotation, station) + '\n';
}
rotation++;
timer = millis();
}
}
}
String getNextPairings(int rotation, int station) {
String text;
int group1Shift = ceil(rotation/2.0);
int group2Shift = -1*floor(rotation/2.0);
String programmer1 = programmers.get((station+group1Shift) % numStations);
String programmer2 = programmers.get(numStations+(posMod(station+group2Shift, numStations)));
if (rotation%2==0) {
text = "At station " + station + ", " + programmer2 + " is the driver and " + programmer1 + " is the navigator.";
} else {
text = "At station " + station + ", " + programmer1 + " is the driver and " + programmer2 + " is the navigator.";
}
return text;
}
//always positive version of modulo
int posMod(int val, int divisor) {
int mod = val % divisor;
if (mod < 0) {
mod += divisor;
}
return mod;
}
void keyPressed() {
if(running) {
timer = -1*minutesPerStation*60*1000; //switch right away
}
else {
running = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment