# Paint line question

**URL:** https://discourse.processing.org/t/paint-line-question/11312
**Category:** Coding Questions
**Created:** [May 16, 2019, 7:24pm UTC](https://discourse.processing.org/t/paint-line-question/11312 "2019-05-16T19:24:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.processing.org/u/Nick1)
#### Post date: [May 16, 2019, 7:24pm UTC](https://discourse.processing.org/t/paint-line-question/11312/1 "2019-05-16T19:24:42Z")

</div>

Hey,  
I want to draw a line with my “paint” program but is does not draw.  
Can anyone help me?  
Thanks

```auto
int akt_links, akt_breite, akt_oben, akt_hoehe;
boolean zeichnen_aktiv, zeichnen_aktiv_linie, loeschen, viereck, kreis, modus1, linie;
int [] oben;
int [] unten;
int [] breite;
int [] hoehe;
int [] form;
int counter, auswahl;
int r, g, b;
void setup()
{
  //fullScreen();
  size(1000, 800);
  background(0);
  rect(0, 0, 1000, 800);
  zeichnen_aktiv=false;
  loeschen=false;
  viereck=false;
  kreis=false;
  linie=false;
  counter=0;
  r=250;
  g=0;
  b=0;
  auswahl=3;
  ellipseMode(CORNER);
  oben = new int[100];
  unten = new int[100];
  breite = new int[100];
  hoehe = new int[100];
  form = new int[100];
  for (int i=0; i>100; i=i+1)
  {
    oben[i]=0;
    unten[i]=0;
    breite[i]=0;
    hoehe[i]=0;
    form[i]=0;
  }
}

void draw()
{
  background(0);
  if (zeichnen_aktiv==true)
  {
    akt_breite=mouseX-akt_links;
    akt_hoehe=mouseY-akt_oben;
  }

  for (int i=0; i<counter; i=i+1)
  {
    if (auswahl==1)
    {

      fill(r, g, b);
      rect(akt_links, akt_oben, akt_breite, akt_hoehe);
    }

    if (auswahl==0)
    {

      fill(r, g, b);
      ellipse(akt_links, akt_oben, akt_breite, akt_hoehe);
    }

    if (auswahl==2)
    {
      if (linie==true)
      {
        if (zeichnen_aktiv==true)
        {
          stroke(r, g, b);
          strokeWeight(10);
          line(mouseX,mouseY,pmouseX,pmouseY);
          noStroke();
        }
      }
    }
  }

  for (int i=0; i<counter; i=i+1)
  {
    ellipseMode(CORNER);
    if (form[i]==1) rect(unten[i], oben[i], breite[i], hoehe[i]);
    if (form[i]==0) ellipse(unten[i], oben[i], breite[i], hoehe[i]);
    if(form[i]==2) line(unten[i], oben[i], breite[i], hoehe[i]);
  }

  fill(250, 0, 0); //FARBEN RECTS
  rect(10, 10, 40, 40);
  fill(0, 250, 0);
  rect(60, 10, 40, 40);
  fill(0, 0, 250);
  rect(110, 10, 40, 40);
  fill(160, 032, 240);
  rect(160, 10, 40, 40);
  fill(250, 250, 0);
  rect(210, 10, 40, 40);
  fill(255, 69, 0);
  rect(260, 10, 40, 40);
  fill(250, 250, 250);
  rect(310, 10, 40, 40);

  fill(255, 255, 255); //MODES
  rect(950, 10, 40, 40);
  fill(0, 0, 250);
  ellipseMode(CENTER);
  ellipse(970, 30, 33, 33);
  fill(255, 255, 255);
  rect(900, 10, 40, 40);
  fill(0, 0, 250);
  fill(250, 250, 250);
  rect(850, 10, 40, 40);
  fill(0, 0, 250);

  rect(905, 15, 30, 30);
  textSize(30);
  text("Objekte:" + counter, 10, 1050);
  ellipseMode(CORNER);
}

void mousePressed()
{
  println(mouseX, mouseY);
  akt_links=mouseX;
  akt_oben=mouseY;
  zeichnen_aktiv=true;

  if (mouseX>10 && mouseX<50 && mouseY>10 && mouseY<50) //FARBEN viereck
  {
    r=250;
    g=0;
    b=0;
  }
  if (mouseX>60 && mouseX<100 && mouseY>10 && mouseY<50)
  {
    r=0;
    g=250;
    b=0;
  }
  if (mouseX>110 && mouseX<150 && mouseY>10 && mouseY<50)
  {
    r=0;
    g=0;
    b=250;
  }
  if (mouseX>160 && mouseX<200 && mouseY>10 && mouseY<50)
  {
    r=160;
    g=32;
    b=240;
  }
  if (mouseX>210 && mouseX<250 && mouseY>10 && mouseY<50)
  {
    r=250;
    g=250;
    b=0;
  }
  if (mouseX>260 && mouseX<300 && mouseY>10 && mouseY<50)
  {
    r=255;
    g=69;
    b=0;
  }
  if (mouseX>310 && mouseX<350 && mouseY>10 && mouseY<50)
  {

    r=250;
    g=250;
    b=250;
  }

  if (mouseX>900 && mouseX<940 && mouseY>10 && mouseY<50) //MODES KNÖPFE
  {
    auswahl=1;
    kreis=true;
    linie=false;
  }
  if (mouseX>950 && mouseX<990 && mouseY>10 && mouseY<50)
  {
    auswahl=0;
    viereck=true;
    linie=false;
  }
    if (mouseX>850 && mouseX<890 && mouseY>10 && mouseY<50)
    {
      auswahl=2;
      linie=true;
      viereck=false;
      kreis=false;
    }
  }

void mouseReleased()
{
  zeichnen_aktiv=false;
  oben[counter]=akt_oben;
  unten[counter]=akt_links;
  breite[counter]=akt_breite;
  hoehe[counter]=akt_hoehe;
  form[counter]=auswahl;
  counter=counter+1;
}

```

---

<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 16, 2019, 9:08pm UTC](https://discourse.processing.org/t/paint-line-question/11312/2 "2019-05-16T21:08:07Z")

</div>

you could kill background(0);

```auto

void draw()
{
  //background(0);

```

This stops deleting the canvas 60 times per second

Alternatively you could store the drawn objects in an ArrayList and show it every time (plus using background())

---

<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 16, 2019, 9:16pm UTC](https://discourse.processing.org/t/paint-line-question/11312/3 "2019-05-16T21:16:26Z")

</div>

ah, and in setup()

this

auswahl=3;

should better be auswahl=0;

---

<div class="post-metadata">

### Author: ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.processing.org/u/Nick1)
#### Post date: [May 17, 2019, 2:07pm UTC](https://discourse.processing.org/t/paint-line-question/11312/4 "2019-05-17T14:07:46Z")

</div>

thank you but now is may broblem ic ant draw rects and ellipse because they draw the whole time.  
and how can i fix it that the color not more changeable is?

thanks alot

---

<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 17, 2019, 3:26pm UTC](https://discourse.processing.org/t/paint-line-question/11312/5 "2019-05-17T15:26:55Z")

</div>

The colors work for me.

I think you need to think more about your code.

e.g. this:

```auto
  oben = new int[100];
  unten = new int[100];
  breite = new int[100];
  hoehe = new int[100];
  form = new int[100];

```

When this is your idea of storing the stuff you have previously drawn, you want to use `background()`.

You store everything neatly in `mouseReleased()` but you don’t display it properly.

You start ok with this:

```auto
  for (int i=0; i<counter; i=i+1)
  {

```

but then you fail to use `oben[i]`, `form[i]` etc.

Instead you only display the current form, which is ok and which you need to do additionally.

Chrisir
