Newbie Problem with Nested Loops
in
Programming Questions
•
1 year ago
Hi, I just started digging into processing today. I had done basic java programming years ago and am trying to build some simple programs to brush up on some fundamentals. I was working on a program which utilizes double arrays, and was trying to iterate through the double array using nested for loops. i was not getting the results expected, and i narrowed the problem down to something with my nested for loop.
here is some very simple code that should theoretically give me 108 columns, and 64 rows, of tiny white rectangles. Instead I get a single white rectangle somewhat off center from the middle. Someone please help me answer:
int i=0;
int j=0;
void setup(){
size(1080,640);
background(0);
}
void draw(){
for (i=0; i<108; i++){
for (j=0; j<64; j++){
fill(255);
rect(i,j,5,5);
}
}
}
Stranger still is if I create variables "widecount" and "highcount" (so that the for loops could be adjusted for any size screen), I don't get even a single white rectangle. Nada. What's going on here?
int i=0;
int j=0;
int widecount = width/10;
int highcount = height/10;
void setup(){
size(1080,640);
background(0);
}
void draw(){
for (i=0; i<widecount; i++){
for (j=0; j<highcount; j++){
fill(255);
rect(i,j,5,5);
}
}
}
Any help is much appreciated!
Much thanks.
1