# How can I save lines?

**URL:** <https://discourse.processing.org/t/how-can-i-save-lines/33634>\
**Category:** Beginners\
**Created:** [November 20, 2021, 3:58pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634 "2021-11-20T15:58:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blah](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Blah](https://discourse.processing.org/u/Blah)\
**Post date:** [November 20, 2021, 3:58pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/1 "2021-11-20T15:58:46Z")

</div>

I need the lines drawn to be saved and match up to form an overall route. Really confused as to what’s missing.  
float cx; // x coordinate of point 1  
float cy; // x coordinate of point 1  
int lastClickX = -1;  
int lastClickY = -1;  
float x = 0;

void setup() {  
size(700, 700);

}

void mousePressed() {  
cx = mouseX;  
cy = mouseY;

redraw();

}  
void mouseReleased() {  
if(lastClickX\>=0 && lastClickY\>=0) line(mouseX,mouseY,lastClickX,lastClickY);  
lastClickX = mouseX;  
lastClickY = mouseY;

}

void draw() {  
background(0, 0, 100);  
ellipse(cx, cy, 20, 20);  
stroke(255);  
line(cx, cy, mouseX, mouseY);  
line(mouseX,mouseY,lastClickX,lastClickY);

line (pmouseX, pmouseY, mouseX, mouseY);  
println ();  
float distance = dist(cx, cy, mouseX, mouseY);  
textSize(60);  
text(""+distance, 40, 500);  
}

---

<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:** [November 20, 2021, 5:26pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/2 "2021-11-20T17:26:18Z")

</div>

Do you want to save the lines (as data, eg start and end point) on the hard drive?

---

<div class="post-metadata">

**Author:** ![Blah](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Blah](https://discourse.processing.org/u/Blah)\
**Post date:** [November 20, 2021, 5:28pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/3 "2021-11-20T17:28:17Z")

</div>

Hi! Thank you for your reply 🙂

I’d just like the lines to appear on the screen. As in, I would like to draw a point, have that stay on screen and then be able to draw the next line. i.e. Point A – Point B – Point C

Does that make sense?

---

<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:** [November 20, 2021, 5:48pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/4 "2021-11-20T17:48:00Z")

</div>

> [@Blah](#):
>
> background(0, 0, 100);

you can delete that

😉

---

<div class="post-metadata">

**Author:** ![Blah](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Blah](https://discourse.processing.org/u/Blah)\
**Post date:** [November 20, 2021, 5:56pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/5 "2021-11-20T17:56:35Z")

</div>

Woah, I really am a beginner 😄

The points work! But it seems that the background was hiding some kind of wild lines being drawn. I assume it has something to do with the framerate? Or something in that direction?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b135aa3bc02ec05b20cd9dc67750b078f2bdd1eb.png)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 20, 2021, 6:04pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/6 "2021-11-20T18:04:43Z")

</div>

Hello,

There are resources here:

> **[Welcome to Processing!](https://processing.org)**
>
> Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts…

As a beginner you should be take a look the tutorials and look up the references for all the elements of your code.

`:)`

---

<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:** [November 20, 2021, 6:14pm UTC](https://discourse.processing.org/t/how-can-i-save-lines/33634/7 "2021-11-20T18:14:16Z")

</div>

instead of getting rid of background you can really store the lines (start points) in an ArrayList

**example**

```auto

float cx; // x coordinate of point 1
float cy; // x coordinate of point 1
int lastClickX = -1;
int lastClickY = -1;
float x = 0;

ArrayList<PVector> list = new ArrayList(); 

void setup() {
  size(700, 700);
}

void mousePressed() {
  cx = mouseX;
  cy = mouseY;

  list.add(new PVector(mouseX, mouseY));

  // redraw();
}
void mouseReleased() {
  if (lastClickX>=0 && lastClickY>=0) 
  {
    //line(mouseX, mouseY, lastClickX, lastClickY);
    // list.add(new PVector(mouseX, mouseY));
  }
  lastClickX = mouseX;
  lastClickY = mouseY;
}

void draw() {
  background(0, 0, 100);
  ellipse(cx, cy, 20, 20);
  stroke(255);
  line(cx, cy, mouseX, mouseY);
  line(mouseX, mouseY, lastClickX, lastClickY);

  line (pmouseX, pmouseY, mouseX, mouseY);
  println ();
  float distance = dist(cx, cy, mouseX, mouseY);
  textSize(60);
  text(""+distance, 40, 500);

  for (PVector pv : list) {
    ellipse(pv.x, pv.y, 
      8, 8);
    //line(pv.x, pv.y,.....);
  }
}

```
