Hello,
I’m trying to get a pyramid with a for loop. It has to start at the middle with a rect like in my code (but there are 2 rects actually idk why) and then go down on both sides step by step but i’m really confused right now. Could someone help me out please? Is there a similar example maybe?
int n; // number of pyramid rows
int w, h; // width and height of each block
int pyramidX, pyramidY;
int bx, by;
void setup() {
size(400, 400);
surface.setTitle("Pyramide");
n = 38; // number of rows in pyramid
w = 10; // make it even so divible exactly by 2
h = 390;
pyramidY = height - h - 400;
pyramidX = width / 2;
}
void draw() {
background(0);
stroke(255, 255, 255);
line(10, 0, 10, 400);
line(0, 390, 400, 390);
stroke(0);
for (int row = 0; row < n; row++) {
by = pyramidY + row * h;
bx = pyramidX + (row + 1)*w/2;
for (int block =0; block < row + 1; block++) {
rect(bx, by, w, h);
bx += w;
}
}
}