A line always from the origin

Hi, i know that this could be a newbie question but i did not figure it out how to solve it.

Even if i create a simple sketch where there is a line that start from 100,100 and goes to mouseX mouseY... i always get a line from the origin to the first point.

How can i avoid the initial line?

void setup(){
 size(800,600); 

}


void draw(){


  line(100,100,mouseX,mouseY);


}
Tagged:

Answers

  • Not the most elegant way.

    void draw()
    {
       if(millis() > 100)
       {
          line(100,100, mouseX, mouseY);
       }
    }
    
  • Answer ✓

    You see the initial line because the mouse variables start off at (0, 0). If you don't want this, you can set the variables to (100, 100) manually:

    void setup() {
      size(800, 600);
    
      //Make the mouse start at (100, 100)
      mouseX = 100;
      mouseY = 100;
    }
    

    Now, if you want to get rid of the initial dot, as well, you can perform a simple check (which shouldn't effect the sketch's output):

    void draw() {
      //Only draw the line if we aren't in the default position (100, 100)
      if(mouseX != 100 || mouseY != 100) {
        line(100,100, mouseX, mouseY);
      }
    }
    
  • edited February 2014

    Ok! great!. But now moving to something more complicated.. how can i avoid this with a two dimensional array of points? i'm using the mesh library import megamu.mesh.*; and instead of list all the points, the sketch add the point when some criteria are met. But seems that at the origin even before starting to run the draw, it adds the first point at the origin.

  • Could you post the code? Maybe you can alter the criteria so that it doesn't draw the first point?

Sign In or Register to comment.