Skip to content

Instantly share code, notes, and snippets.

@slambert
Created March 11, 2017 14:27
Show Gist options
  • Save slambert/b31dc45fb4ece73cff78b392e51710d1 to your computer and use it in GitHub Desktop.
Save slambert/b31dc45fb4ece73cff78b392e51710d1 to your computer and use it in GitHub Desktop.
code to create a "start screen" - you can build off this to make multliple screens/stages in a sketch.
// Modulo Example w start screen
// Steve Lambert March 8, 2017
// v0.1
// initializing variables
int interval; // how often changes
int xPos;
int yPos;
int circleW = 50;
int stage = 0;
// FONT SETUP
PFont LeagueGothicBig;
PFont LeagueGothicSmall;
int fSizeBig = 34; // size of big font
int fSizeSml = 24; // size of small font
int textHeight = height/2;
String line1 = "PRESS ENTER TO START";
void setup() {
size(600,600);
smooth();
noStroke();
background(255);
LeagueGothicBig = createFont("LeagueGothic-Regular", fSizeBig, true);
LeagueGothicSmall = createFont("LeagueGothic-Regular", fSizeSml, true);
} // end setup
void draw(){
background(255);
if (stage == 0){
startScreen();
} else if (stage == 1) {
moduloSketch();
}
}
void keyReleased() {
if (key == RETURN || key == ENTER) {
println("Hit Return stage 0");
if (stage == 0){ // if on the start screen
stage = 1; // advance to the next stage
} else { // otherwise do nothing
} // end else
} // end CODED
else if (key == '0') { // if it's not coded, and it's 0
stage = 0; // reset
}
}
void startScreen() {
fill(255);
background(255, 0, 0);
textAlign(CENTER, CENTER);
textFont(LeagueGothicBig);
//textLeading(80); // Set leading to 10
text(line1, width/2, height/2);
}
void moduloSketch() {
ellipseMode(TOP);
// top circle
if (interval % 96 == 0) {
fill(0);
ellipse(xPos,yPos,circleW,circleW);
}
// 2nd circle
if (interval % 48 == 0) {
fill(51);
ellipse(xPos,yPos+(circleW*1),circleW,circleW);
}
// 3rd circle
if (interval % 24 == 0) {
fill(102);
ellipse(xPos,yPos+(circleW*2),circleW,circleW);
}
// 4th circle
if (interval % 12 == 0) {
fill(153);
ellipse(xPos,yPos+(circleW*3),circleW,circleW);
}
// 5th circle
if (interval % 6 == 0) {
fill(204);
ellipse(xPos,yPos+(circleW*4),circleW,circleW);
}
interval = interval+ 1; // count each loop!
// println("interval: "+interval);
xPos++; // increment xPos
// println("xPos: "+xPos);
if (xPos >= width){ // if it gets to the edge, move down 1 row
xPos = 0;
yPos = yPos + (circleW * 5);
}
if (yPos >= height){ // if it gets to the bottom, start at the top again
yPos = 0;
background(255);
}
} // end draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment