-
-
Save zeffii/8806808 to your computer and use it in GitHub Desktop.
Processing DrumMachine start
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
float[][] distances; | |
float maxDistance; | |
int spacer; | |
Trigger[][] triggers; | |
int value = 0; | |
int triggers_cols = 8; | |
int triggers_rows = 3; | |
void setup() { | |
size(640, 360); | |
frameRate(32); | |
background(0); | |
int id_counter = 0; | |
int dim = 20; | |
int pox, poy; | |
triggers = new Trigger[triggers_rows][triggers_cols]; | |
for (int y = 0; y < triggers_rows; y += 1) { | |
for (int x = 0; x < triggers_cols; x += 1) { | |
int ran_val = int(round(random(1))); | |
pox = int(30.0 * x); | |
poy = int(30.0 * y); | |
PVector pos = new PVector(pox, poy); | |
triggers[y][x] = new Trigger(pos, id_counter, ran_val); | |
} | |
} | |
} | |
void draw() { | |
background(0); | |
for (int y = 0; y < triggers_rows; y += 1) { | |
for (int x = 0; x < triggers_cols; x += 1) { | |
if (triggers[y][x].is_mouse_over() == 1){ | |
// there is a press, so use it and reset te value state to 0 for next press | |
if (value==1) { | |
triggers[y][x].flip_state(); | |
print_array(); | |
value = 0; | |
} | |
} | |
// needs to be drawn each frame for now | |
triggers[y][x].draw(); | |
} | |
} | |
} | |
void mouseClicked() { | |
if (value == 0) { | |
value = 1; | |
} | |
} | |
void print_array(){ | |
println("yes!"); | |
for (int y = 0; y < triggers_rows; y += 1) { | |
for (int x = 0; x < triggers_cols; x += 1) { | |
if (triggers[y][x].state == 1) { | |
print("1"); | |
} | |
else { | |
print("."); | |
} | |
} | |
println(); | |
} | |
} | |
class Trigger { | |
PVector pos; | |
int id; | |
int state; | |
color on_color; | |
color off_color; | |
color edge_color; | |
int dimx; | |
int dimy; | |
// must have different names than the object variables internally. | |
// seems a little stupid. | |
Trigger(PVector _pos, int _id, int _state){ | |
pos = _pos; | |
dimx = 20; | |
dimy = 20; | |
id = _id; | |
state = _state; | |
on_color = color(233,123,3); | |
off_color = color(133,123,3); | |
edge_color = color(133,223,233); | |
draw(_state); | |
} | |
void flip_state(){ | |
state = (state == 0) ? 1 : 0; | |
} | |
int is_mouse_over(){ | |
if (((mouseY < (pos.y + dimy)) && (mouseY > pos.y)) | |
&& (mouseX < (pos.x + dimx) && (mouseX > pos.x))) { | |
return 1; | |
} else { | |
return -1; | |
} | |
} | |
void draw(int state){ | |
color current_color = state == 1 ? on_color : off_color; | |
fill(current_color); | |
stroke(edge_color); | |
rect(pos.x, pos.y, dimx, dimy); | |
} | |
void draw(){ | |
draw(state); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment