back to blue..
in
Programming Questions
•
1 years ago
click ellipse once it turns from blue to red; how can i make it so another click makes it go back to blue again? (sorry, insert code function not working...)
Button buttons;
Button buttons1;
void setup() {
size(500, 500);
smooth();
buttons= new Button(50, 100, random (20, 80), color(0, 0, 255));
buttons1= new Button(80, 180, random (20, 80), color(0, 0, 255));
}
void draw() {
buttons.display();
buttons1.display();
buttons.rollOver();
buttons1.rollOver();
}
class Button {
float x;
float y;
float radius;
color c;
boolean click=false;
float x;
float y;
float radius;
color c;
boolean click=false;
Button(float _x, float _y, float _radius, color _c) {
x=_x;
y=_y;
radius=_radius;
c=_c;
}
x=_x;
y=_y;
radius=_radius;
c=_c;
}
void display() {
if (click) {
fill (255, 0, 0);
}
else {
fill(c);
}
ellipse (x, y, radius, radius);
}
if (click) {
fill (255, 0, 0);
}
else {
fill(c);
}
ellipse (x, y, radius, radius);
}
void rollOver() {
if (sqrt(sq(mouseX-x)+sq(mouseY-y))<=radius&&mousePressed ) {
click=true;
}
}
}
if (sqrt(sq(mouseX-x)+sq(mouseY-y))<=radius&&mousePressed ) {
click=true;
}
}
}
1