title: Translate object, stopping, and continuing- Processing
body: <p>I'm trying to move an object (rectangle for our purposes), from point A to D.  However, along the way I want to stop the motion at different segments and wait some time.</p>
  
  <p>For example, I want to move from A to B, wait 5 seconds, then move from B to C, wait 2 seconds.  Finally, move from C to D.</p>
  
  <p>I've tried a couple of things.  First I moved my object by giving it a "speed" (xspeed) and increasing its position (xpos) by xspeed.  Then using an if statement I stopped the position when it reaches 100.  I then count 5 seconds and begin motion again.  However, since the motion starts past the x-position 100, the if-statement does not allow me to move forward.  I don't know if I can override this if statement.  Below is the code of what I did:</p>
  
  <pre><code>  class Pipe {
    color c;
    float xpos;
    float ypos;
    float xspeed;
    int time;
  
    Pipe(color c_, float xpos_, float ypos_, float xspeed_) {
      c = c_;
      xpos = xpos_;
      ypos = ypos_;
      xspeed = xspeed_;
    }
  
    void display() {
      noStroke();
      fill(c);
      rectMode(CENTER);
      rect(xpos,ypos,10,200);
    }
  
  
    void pipeMove() {
      xpos = xpos + xspeed;
      if (xpos &gt; 100) {
        xpos = 100;
        if (millis() &gt; time) {
          time = millis()+5000;
          xpos = xpos + xspeed;
        }
      }
    }
  }
  
  Pipe myPipe1;
  Pipe myPipe2;
  
  void setup() {
    size(1500,500);
    myPipe1 = new Pipe(color(85,85,85),0,height/2,2);
  //  myPipe2 = new Pipe(color(85,85,85),-100,height/2,2);
  }
  
  void draw() {
    background(255);
    myPipe1.display();
    myPipe1.pipeMove();
  //  myPipe2.display();
  //  myPipe2.pipeMove();
  }
  </code></pre>
  
  <p>The other option I tried was stopping the automatic looping in Processing by using noLoop(), and looping the position within my class.  However, this does not move my object.  See code below of my for-loop.</p>
  
  <pre><code>class Pipe {
    color c;
    float xpos;
    float ypos;
    float xspeed;
    int time;
  
    Pipe(color c_, float xpos_, float ypos_, float xspeed_) {
      c = c_;
      xpos = xpos_;
      ypos = ypos_;
      xspeed = xspeed_;
    }
  
    void display() {
      noStroke();
      fill(c);
      rectMode(CENTER);
      rect(xpos,ypos,10,200);
    }
  
  
    void pipeMove() {
      for (int i = 0; i&lt;100; i = i+1) {
      xpos = xpos + i;
      }
    }
  }
  </code></pre>