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.
Page Index Toggle Pages: 1
mouseDragged() (Read 631 times)
mouseDragged()
Apr 19th, 2010, 12:25am
 
Hi, i would like to know how i can introduce the mouseDragged method in a program involving the construction of a polygon. As such I have managed to construct the polygon but i need to drag the mouse say 5 pixels near a point and then drag the point and the lines joining it to  a new postion. This is my code so far:
String [] lines;
int index = 0;
int dragX, dragY;

void setup(){
 size(650,560);
 lines = loadStrings("coordinates.txt");
 frameRate(12);
 strokeWeight(5);
}
 
 void draw(){
   if(index < lines.length){
     String [] pieces = split(lines[index], '\t');
     if(pieces.length == 2){
       int x = int(pieces[0]);
       int y = int(pieces[1]);
       point(x,y);
       line(12,30,124,345);
       line(124,345,267,89);
       line(267,89,56,78);
       line(56,78,12,30);
       
       
     }
     
     index = index + 1;
   }
 }
 void mouseDragged(){
   
   
   
 }
   
 
 
  thanks for your help.
Re: mouseDragged()
Reply #1 - Apr 19th, 2010, 2:18am
 
This is fairly straightforward and no doubt homework?

You have dragX and dragY variables declared; so set these to appropriate defaults in setup(), use them to draw a point of your polygon (which will involve using them in two of your line() calls) and then set them to mouseX/Y in mouseDragged()...

That would be a first step to test the principle.  In theory you could extend it so that each point of you polygon has associated variables; could test the distance of the mouse from the points on mouseDragged and only move a specific point if the mouse is dragged near enough to it.

Don't even try that second step till you've figured out the first Wink
Re: mouseDragged()
Reply #2 - Apr 19th, 2010, 11:49pm
 
thanks a lot i will figure it out!
Page Index Toggle Pages: 1