Skip to content

Instantly share code, notes, and snippets.

@ybakos
Created March 19, 2014 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ybakos/9641971 to your computer and use it in GitHub Desktop.
Save ybakos/9641971 to your computer and use it in GitHub Desktop.
Global variables and functions that need refactored into classes. And an opportunity for composition.
// YOUR NAME
// Refactoring global variables and functions into appropriate classes.
// And an exploration of composition.
int carX;
int carY;
int carW;
int carH;
int engineX;
int engineY;
int engineW;
int engineH;
void setup() {
size(500, 500);
carX = width / 4;
carY = height / 2;
carW = 250;
carH = 100;
engineX = carX + 30;
engineY = carY + 30;
engineW = 50;
engineH = 20;
}
void draw() {
drawCar();
drawEngine();
}
void drawCar() {
fill(200);
rect(carX, carY, carW, carH);
fill(33);
text("car", carX, carY + 10);
}
void drawEngine() {
fill(100);
rect(engineX, engineY, engineW, engineH);
fill(255);
text("engine", engineX, engineY + 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment