int numRows;
int rowColumns;
int rowLength;
int startX;
int startY;
int rectWidth;
int rectHeight;
boolean isColour;
void setup () {
size (900, 400);
stroke (0);
numRows = 1;
rowColumns = 1;
rowLength = 10;
startX = 50;
startY = 350;
rectWidth = 75;
rectHeight = 30;
isColour = false;
}
void draw() {
background (155);
while (numRows < rowLength) {
rect (startX, startY, rectWidth, rectHeight);
startX = startX + rectWidth;
numRows = numRows + 1; //adding this line breaks the code thus no rectangle is drawn??!)
print(numRows + ", ");
}
}
I want the rectangles to keep producing while numRows is less than rowLength. For some reason, after adding the numRows + 1; (i.e. the count), no rectangle is produced. What am I doing wrong here?
Thanks!
Before I add the numRows = numRows + 1 command
Your program is executing exactly the way you coded it. After the the first draw() loop (which has rectangles) the next loop falls through the while loop (10 is not < 10) and the canvas is cleared for each draw() cycle that follows.
I added a noLoop() to end of setup() so draw() only loops once and you can see output.
I also added some println() statements.