So,
i have filled an IntList with a bunch of values, and i’m comparing this values using a for loop. I’m painting a horizontal line whenever the result of the comparison is false.
I used the || operator to compare also the precedent and subsequent index that the for loop is pointing to.
And now i’m wondering how could i extend this comparison for an arbitrary number of precedent and subsequent index(from i-n to i+n), without having to write by hand all the || operator cases.
Most probably my overall approach is wrong,
and there might be something which i ignore and that would make my life easier?
final IntList il = new IntList(new int[] { 60, 72, 84, 96 });
void setup() {
size(120,120);
noLoop();
}
void draw(){
background(0);
stroke(255);
strokeWeight(1);
int weight=2;
for(int i=0;i<height;i++){
if (containsAnyOfRange(il, i-(weight/2), i+(weight/2))){
line(0,i,width,i);
}
}
}
static final boolean
containsAnyOfRange(final IntList il, int low, final int high) {
if (il != null) while (low <= high) if (il.hasValue(low++)) return true;
return false;
}