Created
February 2, 2014 22:12
-
-
Save anonymous/8775680 to your computer and use it in GitHub Desktop.
test
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; | |
void setup() { | |
size(640, 360); | |
frameRate(32); | |
background(0); | |
int id_counter = 0; | |
int dim = 20; | |
int pox, poy; | |
triggers = new Trigger[12]; | |
for (int y = 0; y < 3; y += 1) { | |
for (int x = 0; x < 4; 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[id_counter++] = new Trigger(pos, id_counter, ran_val); | |
} | |
} | |
} | |
void draw() { | |
background(0); | |
for (int i = 0; i < triggers.length; i+=1) { | |
int ran_val = int(round(random(1))); | |
if (triggers[i].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[i].flip_state(); | |
value = 0; | |
} | |
} | |
triggers[i].draw(); | |
} | |
} | |
void mouseClicked() { | |
if (value == 0) { | |
value = 1; | |
} | |
println("yes!"); | |
} | |
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,33); | |
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