Code from page

2

Answers

  • edited April 2014

    code

  • you have two totally different programs in this one thread?

  • here i draw room insade which i will make network

  • very impressive

    you worked very hard

  • but i cant draw network with out room, i can draw (myself :D ) but the main idea send information about room from my robot on arduino board buid room and count area of room

  • can you help me with count?

  • here

    you mean count result = 12 ?

    Zwischenablage02aa

  • file-4327 yes look i draw a room inside which i make network and now i want to know area of black figure (walls or room which i make with line) i need AREA

  • square which write my program is wrong its cable length

  • I have no idea

  • make a new thread because it has nothing to do with the rest

  • may be side A ( big side) multiply B side (short) - side which we havent but i dont know how to do it(http://forum.processing.org/two/uploads/imageupload/079/NX74KAMZIB4A.jpg "file-4327")

  • please look this and i will start new thread in the morning

  • how to count area of rect if i draw big rect

  • I made a flood fill once

    remove all network

    leave room walls

    somebody could flood fill the room with red

    count all red afterwards

    but the room must be closed

  • edited April 2014

    ¯\ (°_o) /¯

  • edited April 2014

    you wrote

    how to count area of rect if i draw big rect

    when you draw one rect, afterwards you click a button "measure area" and then you click inside the area. Then it could be done.

    Is this what you want?

  • when i draw some figure i see legth of lines but i need area for example i drew rect and i need area of this rect but i have only legth of lines, i multiply big side on small side and get area of this figure

  • this works for the first two lines and multiplies them (like for a rect)

    int x, y, z, w ;
    float distTotal;
    ArrayList<Float> distances = new ArrayList();
    float currArea=0;
    
    void setup()
    {
      size(640, 360);
      background(111);
    }
    
    void draw()
    { 
      //  background(111);
    
      stroke(0);
    
      x= mouseX;
      y= mouseY;
    } // func 
    
    
    void mousePressed() {
      if (mousePressed) 
      {
        fill(255, 0, 0);
        rect(mouseX, mouseY, 5, 5);
        point(pmouseX, pmouseY);
    
        if (z>0 && w>0 && !keyPressed) {
          line(z, w, mouseX, mouseY );
          distances.add ( dist( z, w, mouseX, mouseY ) );
          distTotal = distTotal + dist( z, w, mouseX, mouseY )  ;
          println (distTotal);
          // area 
          println (distances);
          if (distances.size() == 2) 
          {
            currArea=distances.get(0)*distances.get(1); 
            text ( currArea, 14, 14);
          }
          // delete old text
          fill(111);
          noStroke();
          rect (0, 0, 170, 20);
          // bring in new text
          fill(255);
          text (int(distTotal)+"; area: "+ currArea, 12, 12);
        } // if 
    
        // delete 
        if (keyPressed && key=='q') {
          fill(111);
          noStroke();
          rect(mouseX-25, mouseY-25, 50, 50);
        } // if 
        else {  
          z=mouseX;
          w=mouseY;
        } // else
      } // if
    }
    // 
    
  • ArrayList<Float> distances = new ArrayList();

    what is this?

  • edited April 2014

    When you dunno something, look for it in Processing's reference 1st! [..]
    http://processing.org/reference/ArrayList.html

    Although for ArrayList<Float>, I'd prefer FloatList. For it's both simpler & faster than the former! :D
    processing.org/reference/FloatList.html

  • edited April 2014

    here is a little msgbox that pops up

    just hit return

    // the states
    // consts for states
    final int NORMAL = 0;  // normal state 
    final int ALERT  = 1;  // alert / shows the msgbox
    // current 
    int state =  NORMAL;
    
    boolean locked=false;
    
    // this is the object msgBox
    MsgBox msgBox = new MsgBox();
    boolean msgboxHasBeenCalled = false;
    
    // cam 
    PVector camPos;     // its vectors 
    PVector camLookAt;
    PVector camUp;
    
    // cam rotation 
    float camCurrentAngle;       // for cam rot around center
    float camRadius;             // same situation 
    
    // Font 
    PFont font1 ;
    
    // --------------------------------------------------------
    // main funcs: 
    
    void setup() {
      size(800, 800, OPENGL);
    
      // set cams vectors 
      camPos    = new PVector(width/2.0, height/2.0, 600);
      camLookAt = new PVector(width/2.0, height/2.0, -210);
      camUp     = new PVector( 0, 1, 0 );
    
      background(111);
      font1 = createFont("Arial", 32);
      textFont(font1); 
      //
    } // func 
    
    void draw() {
      background(111);
    
      lookAtAngle();
    
      camera (camPos.x, camPos.y, camPos.z, 
      camLookAt.x, camLookAt.y, camLookAt.z, 
      camUp.x, camUp.y, camUp.z);
    
      lights();
    
      fill(255);
      // noStroke();
      translate(width/2, height/2);
      box (61);
    
      // camera 
      if (state==NORMAL && !keyPressed)
        camCurrentAngle++;
      lookAtAngle();
    
      // upper left corner 
      HUD_text("Hit return for MsgBox.");
    
      // this is the msgbox 
      msgBox.msgBoxDisplay();
    
      //
    } // func draw()
    
    // ----------------------------------------------------
    // input funcs
    
    void mousePressed() {
    
      switch (state) {
    
      case NORMAL: 
        // do nothing
        break;
    
      case ALERT: 
        msgBox.mousePressedForMsgbox();
        break;
    
      default:
        // error 
        println ("Error 139");
        break;
      } // switch
    } // func 
    
    void keyPressed () {
    
      switch (state) {
    
      case NORMAL: 
        if (key=='X') { 
          //
        }
        else if (key>='0' && key <= '9') {
          //
        }
        else if (key == RETURN || key == ENTER) {
          // start msgbox 
          msgBox.msgBox("You submitted something.");
        } 
        else if (key==ESC) {
          // key=0;
        }
        else {
          //
        }
        break;
    
      case ALERT: 
        msgBox.keyPressedForMsgbox();
        break;
    
      default:
        // error 
        println ("Error 296");
        break;
      } // switch
    } // func 
    
    // ----------------------------------------------------
    // misc funcs
    
    void lookAtAngle() {
      // rotation in the plane : cam 
      camRadius = camLookAt.dist (camPos); 
      // camRadius = 100;
      camPos.x = camRadius * cos (radians(camCurrentAngle)) + camLookAt.x;
      camPos.z = camRadius * sin (radians(camCurrentAngle)) + camLookAt.z;
    } // func 
    
    void HUD_text (String a1) {
      // HUD text upper left corner 
    
      // this is a 2D HUD 
      camera();
      hint(DISABLE_DEPTH_TEST);
      noLights();
      // ------------------
      textSize(16);
      text (a1, 20, 20);
      // ------------------
      // reset all parameters to defaults
      textAlign(LEFT, BASELINE);
      rectMode(CORNER);
      textSize(32);
      hint(ENABLE_DEPTH_TEST); // no HUD anymore
      lights();
    }
    
    // =====================================================
    
    class MsgBox {
    
      // the string to display 
      String alertText = ""; 
    
      // position and size and innerboder  
      int posX, posY;
      final int msgboxW = 400;
      final int msgboxH = 200;
      final int innerBorder1=14; 
    
      // the ok box
      final int innerBorder2 = 8;
      final int okBoxAddY = 40;
      final int okBoxW = 60;
      final int okBoxH = 30;
    
      RectButton[] rectButtons = new RectButton[3];
      int btnLength = -1; 
    
      // colors
      color col1=color(111);
      color col2=color(222);
    
    
      // no constructor here 
    
      void msgBox ( String a1 ) {
        // this activates the message box 
        alertText = a1;
        state     = ALERT;
        msgboxHasBeenCalled = true;
      } // method 
    
      void msgBoxDisplay() {
    
        // Shows the msgbox (centered on the screen).
        // Call this from draw() always (and at the end). 
        // It's active only when the state is ALERT.
    
        if (state==ALERT && !alertText.equals("")) {
    
          posX=width/2;
          posY=height/2;
    
          // this is a 2D HUD 
          camera();
          hint(DISABLE_DEPTH_TEST);
          noLights();
    
          // the outer box / msgbox 
          noStroke();
          fill(90);
          rectMode(CENTER);  // Set rectMode to CENTER
          rect (posX, posY, msgboxW, msgboxH);
    
          // a frame
          strokeWeight(1); 
          noFill();
          stroke(211);
          rect (posX, posY, msgboxW-innerBorder1, msgboxH-innerBorder1);
    
          // the X top left
          textSize(16);
          fill(255, 0, 0); // red
          textAlign(CENTER, CENTER);
          text ("X", posX+msgboxW/2-innerBorder1-4, posY-msgboxH/2+innerBorder1+4);
    
          // the variable text
          fill(244);
          textAlign(LEFT, CENTER);
          text (alertText, posX-msgboxW/2+innerBorder1, posY-msgboxH/2+2*innerBorder1); 
    
          // the OK box 
          textAlign(LEFT, BASELINE);
          rectMode(CORNER);
          setupButtonOK();
          drawButtons();
    
          // reset all parameters to defaults
          textAlign(LEFT, BASELINE);
          rectMode(CORNER);
          textSize(32);
          hint(ENABLE_DEPTH_TEST); // no HUD anymore
          lights();
        } // if
      } // method  
    
      // inputs 
      //
      void keyPressedForMsgbox() {
        if (key==ESC||key==RETURN||key==ENTER||key==' ')
          state=NORMAL;
        // if (key==ESC)
        key=0;
      } // method
    
      void mousePressedForMsgbox() {
        if (rectButtons[0].Exists) {
          if (rectButtons[0].over) {
            state = NORMAL;
          } // if
        } // if
      } // method 
    
      void drawButtons () {
        // List of Buttons 
        // draw buttons
        for (int i=0; i<btnLength; i++) {
          if (rectButtons[i].Exists) {
            // set colors
            rectButtons[i].update();
            // display 
            rectButtons[i].display();
          }
        }
      } // function 
    
      // command buttons on the screen 
      // Init Buttons
    
      void setupButtons () {
    
        // for the command-buttons on the screen
        int CmdButtonsX        = width-140; 
        int CmdButtonsDistance = 40; 
        int j = 0;
    
        // Pre-Init: All Buttons OFF 
        for (int i=0; i<btnLength; i++) {
          rectButtons[i] = new RectButton( 1, 1, 20, 20, col1, col2, false);
        } 
    
        // Init Buttons 
        j=0; 
        rectButtons[j] = new RectButton( CmdButtonsX, CmdButtonsDistance *(j)+33, 90, 28, col1, col2, true);  
        rectButtons[j].Text ="OK"; 
    
        j=j+1; 
        rectButtons[j] = new RectButton( CmdButtonsX, CmdButtonsDistance *(j)+33, 90, 28, col1, col2, true);  
        rectButtons[j].Text ="Yes";  
    
        j=j+1; 
        rectButtons[j] = new RectButton( CmdButtonsX, CmdButtonsDistance *(j)+33, 90, 28, col1, col2, true);  
        rectButtons[j].Text ="No";  
    
        j=j+1;   
        rectButtons[j] = new RectButton( CmdButtonsX, CmdButtonsDistance *(j)+33, 90, 28, col1, col2, true);  
        rectButtons[j].Text ="Cancel";
      } // function 
    
      void setupButtonOK () {
    
        // for the command-buttons 
        int CmdButtonsX = width-140; 
        int CmdButtonsDistance = 40; 
        int j = 0;
    
        // Pre-Init: All Buttons OFF 
        for (int i=0; i<btnLength; i++) {
          rectButtons[i] = new RectButton( 1, 1, 20, 20, col1, col2, false);
        } 
    
        // Init Button
        j=0; 
        rectButtons[j] = new RectButton( posX-45, posY+okBoxAddY, 
        90, 28, 
        col1, col2, true);  
        rectButtons[j].Text ="OK"; 
    
        btnLength=1;
      } // function 
    
      //
    } // class
    
    // ====================================================================================
    // class Button and RectButton
    
    class RectButton extends Button {
    
      // constr 
      public RectButton(int ix, int iy, 
      int isizeX, int isizeY, 
      color icolor, color ihighlight, 
      boolean iExist) {
        x = ix;
        y = iy;
        sizeX = isizeX;
        sizeY = isizeY;    
        basecolor = icolor;
        highlightcolor = ihighlight;
        currentcolor = basecolor;
        Exists = iExist;
        Text = "";
      }
    
      boolean over() {
        if ( overRect(x, y, sizeX, sizeY) ) {
          over = true;
          return true;
        }
        else {
          over = false;
          return false;
        }
      }
    
      void display() {
        if (Exists) {
          if (Tag.equals("None")) {
            //
          }
          else {
            // command
            stroke (ButtonStrokeColor); 
            strokeWeight(1); 
            fill(currentcolor);
            rect(x, y, sizeX, sizeY);        
            if (Text != "") { 
              fill(0, 102, 153);
              textAlign(CENTER);
              textSize(16) ;
              text(Text, (x + (sizeX / 2.0)), (y + (sizeY / 2.0))+5);
            } // if (Text != "")
          } // else
        } // if exists
      } // method display
      //
    } // class
    
    // ===============================================================
    
    class Button {
      int x, y;
      int sizeX;
      int sizeY;  
      color basecolor, highlightcolor;
      color currentcolor;
      boolean over = false;
      boolean pressed = false;  
      boolean Exists = false;  
      String Text = "";
      String Tag = "";
      int Tag2 = 0;
      int TagMark = 0; 
      color ButtonStrokeColor = color (255, 255, 255);
    
      void update() {
        if (over()) {
          // Mouse over 
          currentcolor = highlightcolor;
        }
        else {
          // not Mouse over 
          currentcolor = basecolor;
        }
      } // update 
    
      boolean pressed() {
        if ( over()) {
          locked = true;
          return true;
        }
        else {
          locked = false;
          return false;
        }
      }  // pressed; 
    
      boolean over() {
        return true;
      } // over 
    
      boolean overRect(int x, int y, int width, int height) {
        if (mouseX >= x && mouseX <= x+width &&
          mouseY >= y && mouseY <= y+height) {
          return true;
        }
        else {
          return false;
        }
      } // overRect
    } // class
    
    // =========================================================
    
  • line 159 to 446 you can just copy and paste (without reading them)

    then you need line 108

    line 10 to 12

    mainly

  • holy cow! i think now its difficult for me

  • line 159 to 446 you can just copy and paste (without reading them)

  • this is not enough i think

  • line 159 to 446 you can just copy and paste (without reading them)

    then you need line 108

    line 10 to 12

    mainly


    again: you fail to describe what you want

  • do you know how to "exite" from program and "roll up" program??

  • for exit / end program use command exit();

    what means "roll up"? Restart?

  • edited April 2014

    first button-exit; second- i dont know (i dont need) AND THIRD BUTTON- ROLL UP (MAY BE =) )

  • what's roll up - return to program?

    close the extra window?

  • I am not proud on this code, but it works for your purpose....

    // the states
    // consts for states
    final int NORMAL = 0;  // normal state 
    final int ALERT  = 1;  // alert / shows the msgbox
    // current 
    int state =  NORMAL;
    
    boolean locked=false;
    
    // this is the object msgBox
    MsgBox msgBox = new MsgBox();
    boolean msgboxHasBeenCalled = false;
    
    // cam 
    PVector camPos;     // its vectors 
    PVector camLookAt;
    PVector camUp;
    
    // cam rotation 
    float camCurrentAngle;       // for cam rot around center
    float camRadius;             // same situation 
    
    // Font 
    PFont font1 ;
    
    // --------------------------------------------------------
    // main funcs: 
    
    void setup() {
      size(800, 800, OPENGL);
    
      // set cams vectors 
      camPos    = new PVector(width/2.0, height/2.0, 600);
      camLookAt = new PVector(width/2.0, height/2.0, -210);
      camUp     = new PVector( 0, 1, 0 );
    
      background(111);
      font1 = createFont("Arial", 32);
      textFont(font1); 
      //
    } // func 
    
    void draw() {
      background(111);
    
      lookAtAngle();
    
      camera (camPos.x, camPos.y, camPos.z, 
      camLookAt.x, camLookAt.y, camLookAt.z, 
      camUp.x, camUp.y, camUp.z);
    
      lights();
    
      fill(255);
      // noStroke();
      translate(width/2, height/2);
      box (61);
    
      // camera 
      if (state==NORMAL && !keyPressed)
        camCurrentAngle++;
      lookAtAngle();
    
      // upper left corner 
      HUD_text("Hit return for MsgBox.");
    
      // this is the msgbox 
      msgBox.msgBoxDisplay();
    
      //
    } // func draw()
    
    // ----------------------------------------------------
    // input funcs
    
    void mousePressed() {
    
      switch (state) {
    
      case NORMAL: 
        // do nothing
        break;
    
      case ALERT: 
        msgBox.mousePressedForMsgbox();
        break;
    
      default:
        // error 
        println ("Error 139");
        break;
      } // switch
    } // func 
    
    void keyPressed () {
    
      switch (state) {
    
      case NORMAL: 
        if (key=='X') { 
          //
        }
        else if (key>='0' && key <= '9') {
          //
        }
        else if (key == RETURN || key == ENTER) {
          // start msgbox 
          msgBox.msgBox("Do you want to exit the program?", msgBox.tOB_YesNo);
        } 
        else if (key==ESC) {
          // key=0;
        }
        else {
          //
        }
        break;
    
      case ALERT: 
        msgBox.keyPressedForMsgbox();
        break;
    
      default:
        // error 
        println ("Error 296");
        break;
      } // switch
    } // func 
    
    // ----------------------------------------------------
    // misc funcs
    
    void lookAtAngle() {
      // rotation in the plane : cam 
      camRadius = camLookAt.dist (camPos); 
      // camRadius = 100;
      camPos.x = camRadius * cos (radians(camCurrentAngle)) + camLookAt.x;
      camPos.z = camRadius * sin (radians(camCurrentAngle)) + camLookAt.z;
    } // func 
    
    void HUD_text (String a1) {
      // HUD text upper left corner 
    
      // this is a 2D HUD 
      camera();
      hint(DISABLE_DEPTH_TEST);
      noLights();
      // ------------------
      textSize(16);
      text (a1, 20, 20);
      // ------------------
      // reset all parameters to defaults
      textAlign(LEFT, BASELINE);
      rectMode(CORNER);
      textSize(32);
      hint(ENABLE_DEPTH_TEST); // no HUD anymore
      lights();
    }
    
    // =====================================================
    
    class MsgBox {
    
      // the string to display 
      String alertText = ""; 
    
      // position and size and innerboder  
      int posX, posY;
      final int msgboxW = 400;
      final int msgboxH = 200;
      final int innerBorder1=14; 
    
      // the ok box
      final int innerBorder2 = 8;
      final int okBoxAddY = 40;
      final int okBoxW = 60;
      final int okBoxH = 30;
    
      RectButton[] rectButtons = new RectButton[3];
      int btnLength = -1; 
    
      // colors
      color col1=color(222);
      color col2=color(255);
    
      // typeOfButtons
      final int tOB_OK = 0;  // consts 
      final int tOB_YesNo = 1;
      final int tOB_OKCancel = 2;  
      int typeOfButtons; 
    
      // type of return
      final int OK  = 0;
      final int YES = 1;
      final int NO  = 2; 
    
      // no constructor here 
    
      void msgBox ( String a1 ) {
        // this activates the message box 
        // simple OK, no return value
        alertText = a1;
        state     = ALERT;
        msgboxHasBeenCalled = true;
      } // method 
    
      void msgBox ( String a1, int typeOfButtonsTemp ) {
        // this activates the message box 
        alertText = a1;
        state     = ALERT;
        msgboxHasBeenCalled = true;
    
        typeOfButtons =  typeOfButtonsTemp;
        switch (typeOfButtons) {
        case tOB_OK:
          msgBox(a1);
          break; 
        case tOB_YesNo:
          //
          break;
        case tOB_OKCancel:
          //
          break;
        default:
          // error 
          break;
        }//switch
      } // method 
    
      void msgBoxDisplay() {
    
        // Shows the msgbox (centered on the screen).
        // Call this from draw() always (and at the end). 
        // It's active only when the state is ALERT.
    
        if (state==ALERT && !alertText.equals("")) {
    
          posX=width/2;
          posY=height/2;
    
          // this is a 2D HUD 
          camera();
          hint(DISABLE_DEPTH_TEST);
          noLights();
    
          // the outer box / msgbox 
          noStroke();
          fill(90);
          rectMode(CENTER);  // Set rectMode to CENTER
          rect (posX, posY, msgboxW, msgboxH);
    
          // a frame
          strokeWeight(1); 
          noFill();
          stroke(211);
          rect (posX, posY, msgboxW-innerBorder1, msgboxH-innerBorder1);
    
          // the X top left
    
          textSize(16);
          textAlign(CENTER, CENTER);
          /* 
           fill(255, 0, 0); // red
           text ("X", posX+msgboxW/2-innerBorder1-4, posY-msgboxH/2+innerBorder1+4);
           */
    
          // the variable text
          fill(244);
          textAlign(LEFT, CENTER);
          text (alertText, posX-msgboxW/2+innerBorder1, posY-msgboxH/2+2*innerBorder1); 
    
          // the OK box 
          textAlign(LEFT, BASELINE);
          rectMode(CORNER);
    
          switch (typeOfButtons) {
          case tOB_OK:
            setupButtonOK();
            break; 
          case tOB_YesNo:
            setupButtonsYesNo();
            break;
          case tOB_OKCancel:
            break;
          default:
            // error 
            break;
          }//switch
    
          drawButtons();
    
          // reset all parameters to defaults
          textAlign(LEFT, BASELINE);
          rectMode(CORNER);
          textSize(32);
          hint(ENABLE_DEPTH_TEST); // no HUD anymore
          lights();
        } // if
      } // method  
    
      // inputs 
      //
      void keyPressedForMsgbox() {
        if (key==ESC||key==RETURN||key==ENTER||key==' ')
          state=NORMAL;
        // if (key==ESC)
        key=0;
      } // method
    
      void mousePressedForMsgbox() {
        switch (typeOfButtons) {
        case tOB_OK:
          if (rectButtons[0].Exists) {
            if (rectButtons[0].over) {
              state = NORMAL;
            } // if
          } // if
          break; 
        case tOB_YesNo:
          if (rectButtons[0].Exists) {
            if (rectButtons[0].over) {
              exit();
            } // if
          } // if
          state = NORMAL;
          break;
        case tOB_OKCancel:
          break;
        default:
          // error 
          break;
        }//switch
      } // method 
    
      void drawButtons () {
        // List of Buttons 
        // draw buttons
        for (int i=0; i<btnLength; i++) {
          if (rectButtons[i].Exists) {
            // set colors
            rectButtons[i].update();
            // display 
            rectButtons[i].display();
          }
        }
      } // function 
    
      // command buttons on the screen 
      // Init Buttons
    
      void setupButtonsYesNo () {
    
        // for the command-buttons on the screen
        //  int CmdButtonsX        = width-140; 
        //  int CmdButtonsDistance = 40; 
        int j;
    
        // Pre-Init: All Buttons OFF 
        for (int i=0; i<btnLength; i++) {
          rectButtons[i] = new RectButton( 1, 1, 20, 20, col1, col2, false);
        } 
    
        // Init Button2
        j=0; 
        rectButtons[j] = new RectButton( posX-80-45, posY+okBoxAddY, 
        90, 28, 
        col1, col2, true);  
        rectButtons[j].Text ="Yes"; 
    
        // Init Button
        j++; 
        rectButtons[j] = new RectButton( posX+80-45, posY+okBoxAddY, 
        90, 28, 
        col1, col2, true);  
        rectButtons[j].Text ="No"; 
    
        j++;
        btnLength=j;
      } // function 
    
      void setupButtonOK () {
    
        // for the command-buttons 
        //int CmdButtonsX = width-140; 
        //int CmdButtonsDistance = 40; 
        int j;
    
        // Pre-Init: All Buttons OFF 
        for (int i=0; i<btnLength; i++) {
          rectButtons[i] = new RectButton( 1, 1, 20, 20, 
          col1, col2, false);
        } 
    
        // Init Button
        j=0; 
        rectButtons[j] = new RectButton( posX-45, posY+okBoxAddY, 
        90, 28, 
        col1, col2, true);  
        rectButtons[j].Text ="OK"; 
    
        j++;
        btnLength=j;
      } // function 
    
      //
    } // class
    
    // ====================================================================================
    // class Button and RectButton
    
    class RectButton extends Button {
    
      // constr 
      public RectButton(int ix, int iy, 
      int isizeX, int isizeY, 
      color icolor, color ihighlight, 
      boolean iExist) {
        x = ix;
        y = iy;
        sizeX = isizeX;
        sizeY = isizeY;    
        basecolor = icolor;
        highlightcolor = ihighlight;
        currentcolor = basecolor;
        Exists = iExist;
        Text = "";
      }
    
      boolean over() {
        if ( overRect(x, y, sizeX, sizeY) ) {
          over = true;
          return true;
        }
        else {
          over = false;
          return false;
        }
      }
    
      void display() {
        if (Exists) {
          if (Tag.equals("None")) {
            //
          }
          else {
            // command
            stroke (ButtonStrokeColor); 
            strokeWeight(1); 
            fill(currentcolor);
            rect(x, y, sizeX, sizeY);        
            if (Text != "") { 
              fill(0);
              textAlign(CENTER);
              textSize(16) ;
              text(Text, (x + (sizeX / 2.0)), (y + (sizeY / 2.0))+5);
            } // if (Text != "")
          } // else
        } // if exists
      } // method display
      //
    } // class
    
    // ===============================================================
    
    class Button {
      int x, y;
      int sizeX;
      int sizeY;  
      color basecolor, highlightcolor;
      color currentcolor;
      boolean over = false;
      boolean pressed = false;  
      boolean Exists = false;  
      String Text = "";
      String Tag = "";
      //  int Tag2 = 0;
      //  int TagMark = 0; 
      color ButtonStrokeColor = color (255, 255, 255);
    
      void update() {
        if (over()) {
          // Mouse over 
          currentcolor = highlightcolor;
        }
        else {
          // not Mouse over 
          currentcolor = basecolor;
        }
      } // update 
    
      boolean pressed() {
        if ( over()) {
          locked = true;
          return true;
        }
        else {
          locked = false;
          return false;
        }
      }  // pressed; 
    
      boolean over() {
        return true;
      } // over 
    
      boolean overRect(int x, int y, int width, int height) {
        if (mouseX >= x && mouseX <= x+width &&
          mouseY >= y && mouseY <= y+height) {
          return true;
        }
        else {
          return false;
        }
      } // overRect
    } // class
    
    // =========================================================
    
  • another one question, for example i drew some figure and want to delete it ( back up) but i have no idea how to do it

  • I posted this already

    when you hold q on the keyboard you delete canvas with the mouse (press mousebutton)

    int x, y, z, w ;
    void setup()
    {
      size(640, 360);
      background(111);
    }
    void draw()
    {
      //  background(111);
    
      stroke(0);
    
      x= mouseX;
      y= mouseY;
      if (mousePressed)
      {
        fill(255, 0, 0);
        rect(mouseX, mouseY, 5, 5);
        point(pmouseX, pmouseY);
    
        if (z>0 && w>0 && !keyPressed) {
          line(z, w, mouseX, mouseY );
        } // if
    
        // delete
        if (keyPressed && key=='q') {
          fill(111);
          noStroke();
          rect(mouseX-25, mouseY-25, 50, 50);
        } // if
        else { 
          z=mouseX;
          w=mouseY;
        } // else
      } // if
    } // func
    // 
    
  • a more professional way would be to store that what you have drawn as data in your sketch (lines and rects)

    then the sketch draws the data

    then you can delete last line or last rect (or any of the lines)

    but this is very advanced and we are not going to do it

  • PImage img1;
    PImage img2;
    PImage img3;
    PImage img4;
    PImage img5;
    PImage img6;
    PImage img7;
    PImage img8;
    PImage img9;
    PImage img10;
    PImage img11;
    PImage img12;
    PImage img13;
    PImage img14;
    boolean [] button1;
    boolean [] button2;
    boolean [] button3;
    boolean [] button4;
    boolean [] button5;
    boolean [] button6;
    boolean [] button7;
    boolean [] button8;
    boolean [] button9;
    boolean [] button10;
    boolean [] button11;
    boolean [] button12;
    boolean [] button13;
    boolean [] button14;
    boolean [] button15;
    int i, n,u,a,s,d,f,g,h,z,x,c,v,xx,cc,w,ww,zz,zzz,yy,yyy,cl1,cl2,ii;
    int j=70;
    int k=20;
    PFont verdana;
    int incomingByte;
    int Slider;
    float distTotal;
    float distTotal2;
    ArrayList<Float> distances = new ArrayList();
    float currArea=0;
      int zq,wq;
    
    void setup()
    {
      img1=loadImage ("pc.jpg");
        img2=loadImage ("server.jpg");
          img3=loadImage ("com.jpg");
            img4=loadImage ("marsh.jpg");
              img5=loadImage ("wifi.jpg");
                img6=loadImage ("fax.jpg");
                  img7=loadImage ("scan.jpg");
                    img8=loadImage ("print.jpg");
                     img9=loadImage ("line.jpg");
                      img10=loadImage ("wall.jpg");
                         img11=loadImage ("mark.jpg");
                         img12=loadImage ("save.jpg");
                         img13=loadImage ("new.jpg");
                         img14=loadImage ("exit.jpg");
                         verdana = loadFont("Verdana-48.vlw");
    
    background(250);
    
      size(displayWidth, displayHeight);
    
      button1 = new boolean[1];
        button2 = new boolean[1];
          button3 = new boolean[1];
            button4 = new boolean[1];
              button5 = new boolean[1];
                button6 = new boolean[1];
                  button7 = new boolean[1];
                    button8 = new boolean[1];
                      button9 = new boolean[1];
                        button10 = new boolean[1];
                          button11= new boolean[1];
                            button12 = new boolean[1];
                             button13 = new boolean[1];
                              button14= new boolean[1];
                              button15= new boolean[1];
    
      for (int k=20; k < displayWidth+100; k += 20) 
    {
    strokeWeight(0);
    line(0 + k , 100 , 0 + k,displayWidth);
    line(0 , 100 + k , displayWidth ,100 + k);
    }
    
    }
    
    void draw()
    {
      fill(230);
      strokeWeight(4);
      rect(0,0,displayWidth-1,100);
    
    textFont(verdana, 16);
    fill(0);
    text("Status connecting:",10,20);
    
    textFont(verdana, 16);
    fill(0);
    text("Area=            square meters",10,45); 
    
    textFont(verdana, 16);
    fill(0);
    text("Cable length=              meters",10,65);
    
    textFont(verdana, 16);
    fill(0);
    text("Coordinates (         ;       )",10,85);
    
          textFont(verdana, 16);
          fill(0);
          text(int(distTotal),140,65);
    
          textFont(verdana, 16);
          fill(0);
          text ( int (currArea), 75, 45);
    
          textFont(verdana, 16);
          fill(0);
          text( mouseX ,115,85);
    
          textFont(verdana, 16);
          fill(0);
          text( mouseY ,164,85);
    
      strokeWeight(4);
      line(0,100,displayWidth,100);
      line(displayWidth,100,displayWidth,displayHeight);
      line(0,displayHeight,displayWidth,displayHeight);
      line(0,100,0,displayHeight);
    
    
     image(img1, 330,26,56,48);
      image(img2, 400,26,56,48);
       image(img3, 470,26,56,48);
        image(img4, 540,26,56,48);
         image(img5, 610,26,56,48);
          image(img6, 680,26,56,48);
           image(img7, 750,26,56,48);
            image(img8, 820,26,56,48);
             image(img9, 890,26,56,48);
              image(img10, 960,26,56,48);
               image(img11, 1030,26,56,48);
               image(img12, 1100,26,56,48);
               image(img13, 1170,26,56,48);
               image(img14, 1240,26,56,48);
    
    
             for(int j=70; j <=displayHeight; j += 70)
    {
      strokeWeight(2);
      noFill();
      rect(260+j,26,56,48);
    }
    
    
    if(button1[i]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(330,26,56,48);
    if(button2[u]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(400,26,56,48);
    if(button3[a]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(470,26,56,48);
    if(button4[s]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(540,26,56,48);
    if(button5[d]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(610,26,56,48);
    if(button6[f]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(680,26,56,48);
    if(button7[g]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(750,26,56,48);
    if(button8[h]) 
       {  
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(820,26,56,48);
    if(button9[z]) 
       { 
    if (mouseY > 110)
    {
      if ( true)
               {
      if (mousePressed==true) 
      {
        fill(255, 0, 0);
        rect(mouseX, mouseY, 5, 5);
        point(pmouseX, pmouseY);
        strokeWeight(1);
        if (w>0&&ww>0&&!keyPressed)
        {
          line(w, ww, mouseX, mouseY );
          distTotal = distTotal + (dist( w, ww, mouseX, mouseY )/50);
        }
        w=mouseX;
        ww=mouseY;
      }
               }
    }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(890,26,56,48);
    if(button10[x]) 
       { 
    if ( true)
    {
             fill(0,255,0);
       }
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(960,26,56,48);
    if(button11[c]) 
       {  
         if ( true)
               {
    if (mousePressed == true) 
             {
              line(mouseX,mouseY,pmouseX,pmouseY);
             }
             fill(0,255,0);
       }
       }
     else 
          {
            noFill();
          }
    strokeWeight(3);
    rect(1030,26,56,48);
    if(button12[v]) 
       {  
              fill(0);
             textFont(verdana, 16);
             text ( " Online", 200,20);
              fill(0,255,0); 
       }
     else 
          {          
            textFont(verdana, 16);
             fill(0);
             text ( " Offline", 200,20);
             fill(255,0,0);
           }
    strokeWeight(2);
    ellipse(180,15,22,22);
    if(button13[cc]) 
       {  
    if ( true)
               {
    if ( keyPressed  ) {
    saveFrame("images/file-####.jpg");
    }
             fill(0,255,0);
       }
       }
     else 
          {
            noFill();
          }
    rect(1100,26,56,48);
    if(button14[xx]) 
       {  
         if ( true)
               {
    if ( keyPressed  ) {
    w=-1;
    ww=-1;
    zq=-1;
    wq=-1;
    distTotal=0;
    distTotal2=0;
    currArea=0;
    background(250);
      for (int k=20; k < displayWidth+20; k += 20) 
    {
    strokeWeight(0);
    line(0 + k , 100 , 0 + k,displayWidth);
    line(0 , 100 + k , displayWidth ,100 + k);
    }
    }
               }
             fill(0,255,0);
       }
     else 
    
          {
            noFill();
          }
    rect(1170,26,56,48);
    if(button15[ii]) 
       {  
             exit();
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(1240,26,56,48);
    }
    void mouseClicked(){
        if(dist(350,38,mouseX, mouseY)<=32)
        {
        button1[n] = !button1[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }    
            else if(dist(420,38,mouseX, mouseY)<=32){
        button2[n] = !button3[n];
        button1[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
         else   if(dist(490,38,mouseX, mouseY)<=32){
    button3[n] = !button3[n];
        button2[n] = false; 
        button1[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
         else   if(dist(560,38,mouseX, mouseY)<=32){
    button4[n] = !button4[n];
        button2[n] = false; 
        button3[n] = false; 
        button1[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
          else  if(dist(630,38,mouseX, mouseY)<=32){
    button5[n] = !button5[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button1[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
          else  if(dist(700,38,mouseX, mouseY)<=32){
    button6[n] = !button6[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button1[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
         else   if(dist(770,38,mouseX, mouseY)<=32){
    button7[n] = !button7[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button1[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
          else  if(dist(840,38,mouseX, mouseY)<=32){
    button8[n] = !button8[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button1[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
           else if(dist(910,38,mouseX, mouseY)<=32){
    button9[n] = !button9[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button1[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
          else  if(dist(980,38,mouseX, mouseY)<=32){
    button10[n] = !button10[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button1[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
           else if(dist(1050,38,mouseX, mouseY)<=32){
    button11[n] = !button11[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button1[n] = false; 
        button13[n] = false; 
        button14[n] = false; 
        }
          else  if(dist(200,18,mouseX, mouseY)<=32){
    button12[n] = !button12[n];
    Slider ^= int(pow(2,n));
    println(Slider);
        }
        else   if(dist(1120,38,mouseX, mouseY)<=32){
    button13[n] = !button13[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button1[n] = false; 
        button14[n] = false; 
        }  
         else  if(dist(1190,38,mouseX, mouseY)<=32){
    button14[n] = !button14[n];
        button2[n] = false; 
        button3[n] = false; 
        button4[n] = false; 
        button5[n] = false; 
        button6[n] = false; 
        button7[n] = false; 
        button8[n] = false; 
        button9[n] = false; 
        button10[n] = false; 
        button11[n] = false; 
        button13[n] = false; 
        button1[n] = false; 
        }
        else  if(dist(1260,38,mouseX, mouseY)<=32){
    button15[n] = !button15[n];
        }
        if(button1[i]) 
       {  
               if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img1, mouseX-18,mouseY-14,36,28); 
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(330,26,56,48);
    if(button2[u]) 
       {  
               if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img2, mouseX-18,mouseY-14,36,28);
             }
             }
    
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(400,26,56,48);
    if(button3[a]) 
       {  
    if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img3,mouseX-18,mouseY-14,36,28);
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(470,26,56,48);
    if(button4[s]) 
       {  
    if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img4, mouseX-18,mouseY-14,36,28);
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(540,26,56,48);
    if(button5[d]) 
       {  
    if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img5, mouseX-18,mouseY-14,36,28);
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(610,26,56,48);
    if(button6[f]) 
       {  
    if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img6, mouseX-18,mouseY-14,36,28);
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(680,26,56,48);
    if(button7[g]) 
       {  
    if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img7,mouseX-18,mouseY-14,36,28);
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(750,26,56,48);
    if(button8[h]) 
       {  
    if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img8, mouseX-18,mouseY-14,36,28);
             }
             }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(820,26,56,48);
      }
    void mousePressed() {
    if(button10[x]) 
       {  
    if (mouseY > 110)
    {if ( true)
               {
      if (mousePressed==true) 
      {
        fill(255, 0, 0);
        rect(mouseX, mouseY, 1, 1);
        point(pmouseX, pmouseY);
     strokeWeight(8);
    
        if (zq>0 && wq>0)
        {   
          line(zq, wq, mouseX, mouseY );
         distances.add ( dist( zq, wq, mouseX, mouseY ) );
          distTotal2=distTotal2 + (dist( zq, wq, mouseX, mouseY )/50) ;
        }
        if (distances.size() == 2) 
          {
            currArea=((distances.get(0)/50)*(distances.get(1)/50)); 
            text ( currArea, 95, 55);
          }
        zq=mouseX;
        wq=mouseY;
      }
               }
    }
             fill(0,255,0);
       }
     else 
          {
            noFill();
          }
          strokeWeight(3);
    rect(960,26,56,48);
    }
    

    please check this one, when i count area of figure i get i number, when i destroy this figure with

    if ( keyPressed  ) {
    w=-1;
    ww=-1;
    zq=-1;
    wq=-1;
    distTotal=0;
    distTotal2=0;
    currArea=0;
    background(250);
    

    i get currArea=0; ( was for example 180) and when i "clear window" and draw figure againe i still have 0 ( after delete with background(250);)

  • your code is very hard to read

    please use ctrl-t to format your code

    please read about arrays and use them for your images

    please read about arrays and use them for your buttons

    please do the tutorial on OOP and use it for your buttons

    your question

    currArea only works for the first two lines

    you need to reset it with distances.clear() every time

  • int x, y, z, w ;
    void setup()
    {
      size(640, 360);
      background(111);
    }
    void draw()
    {
      //  background(111);
    
      stroke(0);
    
      x= mouseX;
      y= mouseY;
      if (mousePressed)
      {
        fill(255, 0, 0);
        rect(mouseX, mouseY, 5, 5);
        point(pmouseX, pmouseY);
    
        if (z>0 && w>0 && !keyPressed) {
          line(z, w, mouseX, mouseY );
        } // if
    
        // delete
        if (keyPressed && key=='q') {
          fill(111);
          noStroke();
          rect(mouseX-25, mouseY-25, 50, 50);
        } // if
        else { 
          z=mouseX;
          w=mouseY;
        } // else
      } // if
    } // func
    

    sorry but this part dont work( i draw image but cannot delete it

  • it works

    press and hold q

    delete stuff with mouse while still holding q

  •      for(int m = 0, m > 5 , m ++)
         {
    

    i wrote this but it dont work because of error "expecting colon found =" what it can be

  • you need to use ; not the ,

  • edited April 2014
    if(button1[i]) 
       {  
        float sum;
        sum = currArea/6;
        println(sum);
        for(int m=1; m <= sum; m +=1)
        {
               if ( true)
               {
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img1, mouseX-18,mouseY-14,36,28); 
             }
             }
               }
             fill(0,255,0);
       }
    

    please look here, i want to dwar room and put in PC in this room, for example i have 120 m2 (room) i want to put in 20 pc ( 6 m2 for 1 PC) in this code i draw for(;;) but it dont count "m+=1" and because of this dont work

  • for (int m=1; m <= sum; m++)

    and please use ctrl-t to format your code

    and please don't write if (true), it is not necessary, since true is always true. You need to remove { and } as well when you remove this.

  • float sum;
        sum = currArea/6;
        println(sum);
        for(int m=1; m <= sum; m ++)
      {  
               if (mouseY > 120)
               {
              strokeWeight(4);
              rect(mouseX-18,mouseY-14,36,28);
              image(img1, mouseX-18,mouseY-14,36,28); 
             }
             }
             fill(0,255,0);
       }
    

    Sorry i cant formar code ( ctrl T open new windows in my browser) but i still draw more then 20 pc it dont count m +1 every time

  • you have to press ctrl-t in processing (in the IDE)

    not in the browser

    you want to draw 20 PCs at the mouse-position (-18,-14)? That makes no sense -

    maybe the for-loop gets called more often than 1 time?

  • look a draw a room with line, in this room 120 meters squared, for 1 computer you need 6 meters squared i 120 divide 6 and get 20, i put in my room (rect which i draw with lines) only 20 computers not more

Sign In or Register to comment.