Thanks lenny, it helped alot. I'm able to save the mouseXY in the array and using these values to draw lines (basic drawing app). Still having some minor problems/questions though.
I'm only saving my mouseXY values when the mouse is pressed and calling those values to draw the lines. The problem is, when I release the mousepress and want to start a new line it automatically connects the point of release and the new click point with a line as the line-drawing code just takes the previous array index spot (i-1), being the point of release, and connects it with the new click point (i).
Same problem happens at the very beginning, as I start drawing it automatically takes the first value being 0,0 and connects it with the first click point x,y.
As a last thing, right now I've set my array to 1000 (to get a reasonable drawing time), what would be better is to get an array without a max size, which would be cleared every time a drawing get's cleared.
Thanks.
Code:
import processing.opengl.*;
import processing.video.*;
Capture camera;
int cameraWidth = 1024;
int cameraHeight = (cameraWidth/4)*3;
float x,y;
float[] xpos=new float[1000];
float[] ypos=new float[1000];
void setup(){
size(cameraWidth*2,cameraHeight);
smooth();
for(int i=0;i<1000;i++){
xpos[i]=x;
ypos[i]=y;
}
background(0,0,255);
stroke(255);
strokeWeight(10);
strokeJoin(ROUND);
strokeCap(ROUND);
camera = new Capture(this,cameraWidth,cameraHeight,30);
}
void captureEvent(Capture camera)
{
camera.read();
}
void draw(){
background(0,0,255);
image(camera,0,0);
//motion
if (mousePressed == true){
x=mouseX;
y=mouseY;
}
for(int i=1;i<1000;i++){
xpos[i-1]=xpos[i];
ypos[i-1]=ypos[i];
}
xpos[999]=x;
ypos[999]=y;
noFill();
beginShape();
for(int i=999;i>0;i--){
vertex(xpos[i],ypos[i]);
vertex(xpos[i-1],ypos[i-1]);
}
endShape();
noFill();
beginShape();
for(int i=999;i>0;i--){
vertex(xpos[i]+cameraWidth,ypos[i]);
vertex(xpos[i-1]+cameraWidth,ypos[i-1]);
}
endShape();
}