flashing colors-why?
in
Programming Questions
•
1 years ago
hi,
how come the colors are flashing once a circle has been clicked-i wan them to just to stay on one random color..
- Button[] buttons= new Button[50];
- void setup() {
- size(500, 500);
- background(175);
- for (int i=0;i<buttons.length;i++) {
- buttons[i]= new Button(random(0, width), random (0, height), random(0, 50), color(255));
- }
- }
- void draw() {
- for (int i=0;i<buttons.length;i++) {
- buttons[i].display();
- buttons[i].rollOver(mouseX, mouseY);
- }
- }
- class Button {
- float x;
- float y;
- float radius;
- color c;
- boolean clicked=false;
- Button(float _x, float _y, float _radius, color _c) {
- x=_x;
- y=_y;
- radius=_radius;
- c=_c;
- }
- void rollOver(int mx, int my) {
- if (sqrt(sq(mouseX-x)+sq(mouseY-y))<=radius&&mousePressed ) {
- clicked= true;
- }
- }
- void display() {
- if (clicked) {
- // fill(255,0,0);
- fill (random (0, 175));
- }
- else {
- fill(c);
- }
- ellipse(x, y, radius, radius);
- }
- }
1