Basic white triangle grid homework pls help

could anyone sort me out with this
I’m trying to make a grid of upside down white triangles exactly like

with nested loops
but so far I’ve only gotten

that has misaligned non grid triangles
I’ve no idea what to change in the variables now, any help would be seriously appreciated

my current code

void setup() {
size(420, 420);
background(0, 255, 0);
noStroke();
}

void draw() {
for (int x = 0; x <= 420; x += width/6) {
for (int y = 0; y <= 420; y += height/6)

triangle(x, y, x + 70, y, x += 35, y + 70 );

}
}

thank you

Hello,

There are resources (tutorials, references, examples) here:

:)

it is unnecessary (and evil) to add something to the x variable.

x += 35

You change the variable of the for-loop. Or was it a typo?
Don’t do this.

Example

Example which is not correct but should get you started



void setup() {
  size(420, 420);
  background(0, 255, 0);
  noStroke();
}

void draw() {
  for (int x = 0; x <= 420; x += width/6) {
    for (int y = 0; y <= 420; y += height/6) {
      triangle(x, y, 
        x - 35, y+70, 
        x+35, y+70);
    }
  }
}

THANK YOU SO MUCH finally got it to work

1 Like