Skip to content

Language Settings

Embedded Iteration

Embedding "for" structures allows repetition in two dimensions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function setup() {
  createCanvas(720, 360);
  background(0);
  noStroke();
  let gridSize = 35;
  for (let x = gridSize; x <= width - gridSize; x += gridSize) {
    for (let y = gridSize; y <= height - gridSize; y += gridSize) {
      noStroke();
      fill(255);
      rect(x - 1, y - 1, 3, 3);
      stroke(255, 50);
      line(x, y, width / 2, height / 2);
    }
  }
}
X

creative commons license