return to original size
in
Programming Questions
•
1 years ago
double clicking on a circle doubles its radius.
the 'originalSize' function is meant to return circle to original size when its double clicked again:
it isn't working though..any ideas why?
- Button[] buttons = new Button[60];
- boolean somethingSelected = false;
- void setup() {
- size(800, 300);
- smooth();
- for (int i = 0; i < buttons.length; i++) {
- buttons[i]= new Button(random(width), random(height), random(20, 80), color(random(255), random(255), random(255), 100), 0.5);
- }
- }
- void draw() {
- background(85);
- for (int i = 0; i < buttons.length; i++) {
- buttons[i].display();
- }
- }
- void mousePressed() {
- somethingSelected = false;
- for (int i = 0; i < buttons.length; i++) {
- buttons[i].rollOver();
- buttons[i].doubleclick();
- buttons[i].originalSize();
- }
- }
- void mouseDragged() {
- for (int i = 0; i < buttons.length; i++) buttons[i].bDragged();
- }
- void mouseReleased() {
- for (int i = 0; i < buttons.length; i++) buttons[i].bReleased();
- }
- class Button {
- float x;
- float y;
- float rad;
- color c;
- float s;
- boolean click = false;
- boolean drag = true;
- boolean dclick=false;
- boolean originalSize=false;
- Button(float _x, float _y, float _radius, color _c, float _s) {
- x=_x;
- y=_y;
- rad=_radius;
- c=_c;
- s=_s;
- }
- void display() {
- if (click) {
- fill (255, 0, 0);
- strokeWeight(3);
- }
- else {
- fill(c);
- strokeWeight(s);
- }
- ellipse (x, y, rad, rad);
- rad= constrain(rad, rad, rad*2);
- }
- void rollOver() {
- if (sqrt(sq(mouseX-x)+sq(mouseY-y)) <= rad/2 && somethingSelected == false) {
- click = true;
- drag = true;
- }
- }
- void doubleclick() {
- if (sqrt(sq(mouseX-x)+sq(mouseY-y)) <= rad/2 && somethingSelected == false&&mouseEvent.getClickCount()==2) {
- rad=rad*2;
- //rad= constrain(rad,rad,rad*2);
- }
- }
- void originalSize() {
- if (sqrt(sq(mouseX-x)+sq(mouseY-y)) <= rad/2 && somethingSelected == false&& key=='r'&& dclick==true )
- {
- println ("half");
- rad=rad/2;
- }
- }
- void bDragged() {
- if (drag) {
- x = mouseX;
- y = mouseY;
- }
- }
- void bReleased() {
- click = false;
- drag = false;
- }
- }
1