 # Help needed simplifying graphing consecutive lines w/Processing 2.0.2

Hello. I am graphing consecutive lines with Procesing 2.0.2 using gyro's coordinates (x,y) and encoder's distances (d), both via Xbee from an Arduino Fio. i.e:

line 1: x1,y1 ----d1---- x2,y2 line 2: x2,y2 ----d2---- x3,y3 line 3: x3,y3 ----d3---- x4,y4 etc...

So far my application works OK but as the amount of lines (coordinates and distances) increase, my code is getting bigger and bigger. I need help trying to simplify the code (may be using 'for' or 'while' iterations). x and y are proportional to the distance and they become xn and yn after the distance and the second point are fixed. Here my draw() function for the first four lines.Thank you.

``````void draw() {
background(255);
translate(width/2, height/2);;

// First concatenated line (not yet fixed)
if(fixed_lines==0){
line(0,0,x,y);
}
// concatenated lines 1 and 2 (line 1 fixed)
if(fixed_lines==1){
line(0,0,x1,y1);
line(x1,y1,x1+x,y1+y);
}
// concatenated lines 1, 2 and 3 (lines 1 and 2 fixed)
if(fixed_lines==2){
line(0,0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x2+x,y2+x);
}
// concatenated lines 1, 2, 3 and 4 (lines 1, 2 and 3 fixed)
if(fixed_lines==3){
line(0,0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x3+x,y3+y);
}
}
``````