Paint line question

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

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;
}

1 Like

you could kill background(0);



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())

1 Like

ah, and in setup()

this

auswahl=3;

should better be auswahl=0;

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

The colors work for me.

I think you need to think more about your code.

e.g. this:

  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:

  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

1 Like