# Store the coordinates of the mouse clicks

**URL:** <https://discourse.processing.org/t/store-the-coordinates-of-the-mouse-clicks/11745>\
**Category:** Coding Questions\
**Created:** [May 31, 2019, 7:13pm UTC](https://discourse.processing.org/t/store-the-coordinates-of-the-mouse-clicks/11745 "2019-05-31T19:13:58Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 31, 2019, 7:41pm UTC](https://discourse.processing.org/t/store-the-coordinates-of-the-mouse-clicks/11745/4 "2019-05-31T19:41:48Z")

</div>

```auto

// the coordinates of the lines: each line goes "from" a point "to" a point (PVector).

// The lists are parallel in that sense that the elements of both lists together make a line: 
// the 0th element of both lists make one line, the 1st element of both lists make one line, the 2nd etc. 
ArrayList<PVector> from = new ArrayList(); 
ArrayList<PVector> to = new ArrayList();

// necessary to know if the mouse enters a "from" or a "to" point of a line
int situation=0;

// -------------------------------------------------------------------------
// processing core functions  

void setup() {
  size(600, 1000);
  stroke(255);
}

void draw() {
  background (0); 

  stroke(255);

  // show all stored lines 
  for (int i = 0; i < to.size(); i++) {
    PVector currentFrom = from.get(i);
    PVector currentTo = to.get(i);
    // the line 
    linePV ( currentFrom, 
      currentTo );
  }//for

  if (situation==1) {
    stroke(0, 255, 0); 
    linePV(from.get(from.size()-1), 
      new PVector(mouseX, mouseY));
  }
}//func 

// -------------------------------------------------------------------------
// Inputs 

void mousePressed() {
  // depending on situation we store mouse-position as from or as to 
  if (situation==0) 
    from.add (new PVector (mouseX, mouseY));
  else if (situation==1)
    to.add (new PVector (mouseX, mouseY));

  // manage situation variable  
  situation++;
  if (situation>1)
    situation=0;
}

// -------------------------------------------------------------------------
// Tools 

void linePV ( PVector pv1, PVector pv2) {
  line(pv1.x, pv1.y, 
    pv2.x, pv2.y);
}//func 
//

```

---

_[View the full topic](https://discourse.processing.org/t/store-the-coordinates-of-the-mouse-clicks/11745)._
