Created
October 19, 2011 17:42
-
-
Save raheelahmad/1299069 to your computer and use it in GitHub Desktop.
Midterm Exam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LineDrawer { | |
float x1, y1, x2, y2; | |
boolean movingForward; | |
void drawItself() { | |
line (x1, y1, x2, y2); | |
} | |
void update() { | |
if (movingForward) { | |
x1++; | |
x2++; | |
} | |
else { | |
x1--; | |
x2--; | |
} | |
} | |
void check() { | |
if (x2 >= width) | |
movingForward = false; | |
if (x1 <= 0) | |
movingForward = true; | |
} | |
} | |
LineDrawer[] lines; | |
void setup() { | |
size(500, 500); | |
smooth(); | |
lines = new LineDrawer[4]; | |
for (int i = 0; i < 4; i++) { | |
lines[i] = new LineDrawer(); | |
lines[i].x1 = 0; | |
lines[i].y1 = 60 * (i + 1); | |
lines[i].x2 = width/2; | |
lines[i].y2 = lines[i].y1; | |
lines[i].movingForward = true; | |
} | |
} | |
void draw() { | |
background(150); | |
for (int i=0; i < 4; i++) { | |
lines[i].drawItself(); | |
lines[i].update(); | |
lines[i].check(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment