Short answer: that's because speed is random(2) ie. a number between 0 (inclusive) and 2 (exclusive). Lines with speed 0 won't move...
Long answer: the fix, and some little improvements, to show some common idioms in Java (and C/C++/similar languages):
i=i+1 => i++
num => NUM (convention to spot constants) See
Static Final for a good explanation of constants
increment plus test above a value, then return at 0 => use of
% (modulo)using a boolean instead of an integer with only two values used only in tests
Resulting code:
Code:
void setup() {
size(200,200);
background(0);
smooth();
//noStroke();
frameRate(30);
//int[NUM]
for(int i=0;i<NUM;i++){
vh[i]=random(2) > 1;
speed[i]=int(random(1,3));
col[i]=color(random(256),random(256),random(256));
posx[i]=random(width);
posy[i]=random(height);
}
}
void draw() {
background(0);
for(int i=0;i<NUM;i++){
stroke(col[i]);
if(vh[i]) {
posx[i]=(posx[i]+speed[i]) % width;
line(posx[i],0,posx[i],height);
} else {
posy[i]=(posy[i]+speed[i]) % height;
line(0,posy[i],width,posy[i]);
}
}
}
// static final just indicate it is a constant
static final int NUM=100;
boolean[] vh =new boolean[NUM];
float[] posx=new float[NUM];
float[] posy=new float[NUM];
int[] col =new int[NUM];
int[] speed =new int[NUM];
Also note I incremented the values in random, since the upper bound is never reached.