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
help (Read 512 times)
help
Nov 18th, 2009, 7:14am
 
Hi! I have a problem. I would like to know how the code to get this thing:
When I click somewhere on the window with the mouse and then when I click in another point of the window I always get a continous line ...
Can you help me?
Thanks for all  Smiley
Re: help
Reply #1 - Nov 18th, 2009, 7:25am
 
Hi, I will help you but first what thing? and can you post some code?

rS
Re: help
Reply #2 - Nov 18th, 2009, 7:33am
 
This is my code:
void setup() {
size (360,443);
PImage gino = loadImage("gino.jpg");
background(gino);
}



void draw() {
 stroke(0);
 strokeWeight(2);
 if(mousePressed) {
   line(mouseX, mouseY, pmouseX, pmouseY);
 }
}


In this case, to draw the line I have to hold down the mouse button, but I need that I click the mouse in one point of the window and then in another so the program draw a continuos line.
This the problem  Sad
I hope I have been clear:)
Re: help
Reply #3 - Nov 18th, 2009, 7:43am
 
try this out

Code:
ArrayList lines = new ArrayList();
PVector node;

void setup() {
 size (360, 443);
 
 strokeWeight(2);
}


void draw() {
 background(250);
 
 if(mousePressed) {
   PVector node = new PVector(mouseX, mouseY);
   lines.add(node);
 }
 
 stroke(0);
 for (int i = 0; i < lines.size(); i++) {
   if (i > 0) {
PVector prevNode = (PVector)lines.get(i - 1);
PVector node = (PVector)lines.get(i);
line(prevNode.x, prevNode.y, node.x, node.y);
   }
 }
}


In your case you need to draw your image in the draw method

Hope that helps
rS
Re: help
Reply #4 - Nov 18th, 2009, 7:54am
 
Wonderful!
You were really nice. Thanks for the help
Page Index Toggle Pages: 1