Created
February 3, 2015 03:56
-
-
Save Lanny/3e4a21b8e12257a51e58 to your computer and use it in GitHub Desktop.
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
int MARGIN = 30, | |
HEAD_SIZE = 200, // Jenkins, you bigheaded bastard | |
DRUM_ROWS = 3, | |
DRUM_COLS = 3, | |
SPACING = 10; | |
ArrayList<DrumHead> drums = new ArrayList<DrumHead>(); | |
ArrayList<PressArea> pressAreas = new ArrayList<PressArea>(); | |
class PressArea { | |
int top, left, bottom, right; | |
ArrayList<PressArea> subAreas; | |
boolean responsible(int x, int y) { | |
return (x > left && x < right) && (y > top && y < bottom); | |
} | |
void delegate(int x, int y) { | |
println("Delegated!"); | |
for (PressArea area : subAreas) { | |
if (area.responsible(x, y)) { | |
area.onPress(x, y); | |
} | |
} | |
} | |
void onPress(int x, int y) { | |
return; | |
} | |
} | |
class DrumHead extends PressArea { | |
boolean active; | |
DrumHead(int top, int left) { | |
this.top = top; | |
this.left = left; | |
this.right = left + HEAD_SIZE; | |
this.bottom = top + HEAD_SIZE; | |
} | |
void draw() { | |
fill(this.active?100:200); | |
rect(this.top, this.left, HEAD_SIZE, HEAD_SIZE, 10); | |
} | |
void onPress(int x, int y) { | |
println("Drum struck"); | |
this.active = true; | |
} | |
} | |
class DrumsArea extends PressArea { | |
DrumsArea() { | |
this.bottom = height - MARGIN; | |
this.top = this.bottom - DRUM_COLS * (HEAD_SIZE + SPACING); | |
this.right = width - MARGIN; | |
this.left = this.right - DRUM_ROWS * (HEAD_SIZE + SPACING); | |
this.subAreas = new ArrayList<PressArea>(); | |
for (PressArea drum : drums) { | |
this.subAreas.add(drum); | |
} | |
} | |
void onPress(int x, int y) { | |
println("DrumsArea onPress fired"); | |
this.delegate(x, y); | |
println("DrumsArea onPress done"); | |
} | |
} | |
void setup() { | |
background(0, 0, 0); | |
DrumHead head; | |
int x, y; | |
for (int row = 0; row < DRUM_ROWS; row++) { | |
for (int col = 0; col < DRUM_COLS; col++) { | |
x = width - ((row + 1) * (HEAD_SIZE + SPACING)) - MARGIN; | |
y = height - ((col + 1) * (HEAD_SIZE + SPACING)) - MARGIN; | |
head = new DrumHead(x, y); | |
drums.add(head); | |
} | |
} | |
pressAreas.add(new DrumsArea()); | |
} | |
void mousePressed() { | |
println("press registered"); | |
println("X:" + mouseX + ", Y:" + mouseY); | |
//for (PressArea area : pressAreas) { | |
// println("top level press delegation"); | |
// area.onPress(mouseX, mouseY); | |
//} | |
println("top level press loop complete"); | |
} | |
void draw() { | |
for (DrumHead drum : drums) { | |
drum.draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment