title: Processing - Animation between two points
body: <p>I am developing the below code. To give you a brief description, it is allowing the user to click on different points on the screen, then these mouse coordinates and positions are stored in an array and also seen on the screen. When the user clicks <code>enter</code> there is a movement from the first point to the last point, using the linear interpolation technique. I am having difficulty in the <code>for</code> loop as the <code>PVector v</code> is storing the coordinates. Could anyone please guide me accordingly?.</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>ArrayList vectors;
  PVector v = new PVector();
  boolean animate = false; //declare a boolean variable you can use to switch from building points to animating the movement
  int FirstMouseClick; //declare an int variable to store the frameCount of the first mouseclick
  int AnimationStart; //declare an int variable to store the frameCount of the animation start
  
  void setup()  
  {
    size(500, 500);
    frameRate(60);
    vectors = new ArrayList();
  }
  
  void draw()  
  {
    if(!animate)//if the boolean variable animate is true
    {
      float output = frameCount - AnimationStart; // subract the animation start frameCount from the current frameCount so you know which framecount from the vectors array you should be showing
      for(int i=0; i&lt;vectors.size(); i++) //loop through the vectors array
       //until you find the (next PVector's frameCount - frameCount of first mouseClick) &gt; above subtraction result
      {
        v = (PVector)vectors.get(frameCount); //until you find the (next PVector's frameCount)
  
      }
     ellipse(v.x,v.y,10,10);// use the current pvector's xpos and ypos to draw the ellipse
    }
  }
  
  void mouseClicked()
  {
    frameCount = 0; //if not yet set, set the first frameCount value
    vectors.add(new PVector(mouseX, mouseY,frameCount));// &lt;--- store the framecount in the z axis
    ellipse(mouseX,mouseY,10,10);
    println("Mouse Coordinates are: " + vectors);
  }
  
  void keyPressed()
  {
    if(keyCode == ENTER)
    {
      animate = true; //set the boolean variable animate to true
      AnimationStart = 3; //set the framecount of the animation start
    }
  }
  </code></pre>