Need help with a loop for class
in
Programming Questions
•
25 days ago
For my class we are supposed to recreate a loop image that our teacher gave us:
I really have no idea what I'm doing, but i was trying to just make a red background and then have the blue boxes be a loop. I was trying to set the blue box as a function and then have a row of boxes be a function and then draw all of the rows. But when I try to do this it only draws one blue box in the corner and I have no idea why. Maybe I'm going about this a completely wrong way but I'm really bad at this so someone please help me!
void setup() {
size(400,400);
background(255,0,0);
rectMode(CENTER);
}
//Set Variables
int x = 4;
int y = 4;
int squareWidth = 8;
int endSquares = 400;
//Blue Square Loop
void drawBlueSquare(int x, int y) {
background(255,0,0);
stroke(0);
fill(0,0,255);
rect(x,y,8,8);
}
void drawRowofSquares(int y) {
while (x < width) {
drawBlueSquare(x,y);
x = x + 8;
}
}
void draw() {
while (y < height) {
drawRowofSquares(y);
y = y + 8;
}
}
1