We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Draw vertex-shape with mouse
Page Index Toggle Pages: 1
Draw vertex-shape with mouse (Read 970 times)
Draw vertex-shape with mouse
Oct 5th, 2009, 5:16am
 
Hi,

I started building this little tool for myself. The idea is that the draggable vertexes help me to draw shapes quickly. I would also like to see the coordinates of each vertex and the cursor. How can I display them near the actual vertex-points with "hovering" numbers? Also, how can I create new vertices with double-click?

Quote:
float x = 250;
float y = 250;
float x2;
float y2;
float x3 = 100;
float y3 = 150;

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

void draw() {
  background(150);
  rectMode(CENTER);
  fill(255);
  line(x,y,x2,y2);
  line(x,y,x3,y3);
  ellipse(x, y, 15, 15);
  ellipse(x2,y2,15,15);
  ellipse(x3,y3,15,15);
  float d = dist(x,y,mouseX,mouseY);
  float d2 = dist(x2,y2,mouseX, mouseY);
  float d3 = dist(x3,y3,mouseX,mouseY);
  noFill();
  beginShape();
  vertex(x,y);
  vertex(x2,y2);
  vertex(x3,y3);
  endShape();
  if(d<20 && mousePressed) {
    x = mouseX;
    y = mouseY;
  }
  if(d2<20 && mousePressed) {
    x2 = mouseX;
    y2 = mouseY;
  }
  if(d3<20 && mousePressed) {
    x3 = mouseX;
    y3 = mouseY;
  }
  smooth();
}



Re: Draw vertex-shape with mouse
Reply #1 - Oct 5th, 2009, 5:49am
 
You need to put the coordinates in an array (of PVector for example) or, better, an ArrayList.
On double-click, create a new coordinate and add it to the list.
See also Bézier Editor for some inspiration (and code...).
Re: Draw vertex-shape with mouse
Reply #2 - Oct 5th, 2009, 8:50am
 
I'll look into this, thanx!!!
Page Index Toggle Pages: 1