Nested loop problem
in
Programming Questions
•
1 year ago
he folks, I am struggeling with a nested loop problem, or at least thats what i think i am struggeling with^^....
I try to display (on screen) only every 5th value of a loop - I solved it with an if statement but this is very bad coding i think^^
any help would be greatly appreciated
thx
I try to display (on screen) only every 5th value of a loop - I solved it with an if statement but this is very bad coding i think^^
any help would be greatly appreciated
thx
- PFont font;
float[] numbersPed;
float[] numbersCar;
int m1, m2; // number of steps
float t2; // angle
float x, y, z;
float xm;
float ym;
float r;
float c1, c2;
boolean button = false; /// fuers umschalten zwischen ped und cars
void setup() {
frameRate(27);
font = loadFont("CordiaNew-bob.vlw");
size(600, 600);
smooth();
xm = width/2;
ym = height/2;
String[] lines= loadStrings("08082012__a.txt");
numbersPed = new float[lines.length];
numbersCar = new float[lines.length];
for (int i =0; i< lines.length; i = i+2) {
numbersPed[i] = float(lines[i]);
}
for (int i =1; i< lines.length; i = i+2) {
numbersCar[i] = float(lines[i]);
}
}
void draw() {
m2 = numbersPed.length;
t2 = 2*PI/m2;
if (button) {
c1 = 255;
c2 = 50;
}
else {
c1 = 50;
c2 = 255;
}
background(255);
strokeWeight(1);
noFill();
for (int i=0; i<=numbersPed.length-1; i+=2) {
x=xm+r*sin(t2*i);
y=ym+r*cos(t2*i);
//println(numbersPed[i]);
stroke(numbersPed[i]*15, 0, 0, c1);
r=numbersPed[i]*22;
line(x, y, width/2, height/2);
fill(0);
float intervall = i;
float time = 8+ 0.1*intervall;
textAlign(LEFT);
if(time>24){
time=time-24;
}
////////////// for ( int j =0; j<numbersPed.length; j=j+5){/////////////////////////////
if (i==0||i==5||i==10||i==15||i==20||i==25||i==30||i==35||i==40||i==45||i==50||i==55
||i==60||i==65||i==70||i==75||i==80||i==85||i==90||i==95||i==100||i==105||i==110||i==115
||i==120||i==125||i==130||i==135||i==140||i==145||i==150||i==155||i==160||i==165||i==170
||i==175||i==180||i==185||i==190||i==195||i==200||i==205||i==210||i==215||i==220||i==225
||i==230||i==235||i==240||i==245) {
text(int(time)+ ":" + "00", x, y);
}
}
for (int i=1; i<=numbersCar.length-1; i+=2) {
x=xm+r*sin(t2*i);
y=ym+r*cos(t2*i);
// println(numbersCar[i]);
stroke(numbersCar[i]*15, 0, 0, c2);
r=numbersCar[i]*22;
line(x, y, width/2, height/2);
}
// noLoop();
}
void mousePressed() {
button = !button;
}
1