Hello,
I thought every time I ran the code, the black boxes would appear like this. (image 1 and 2) But they are doing it like this (image 3) or anything but this.
Does anyone know why?
function blacksquare1() {
fill(0)
square(204, 204, grid)
}
function blacksquare2() {
fill(0)
push()
square(102, 102, grid)
square(204, 102, grid)
square(306, 102, grid)
square(306, 204, grid)
square(306, 306, grid)
square(204, 306, grid)
square(102, 306, grid)
square(102, 204, grid)
pop()
}
var canvasWidth = 512;
var canvasHeight = 512;
var elementsNumber = 5;
var grid = canvasWidth / elementsNumber;
var posX;
var posY;
var formes = 0; //variable del if
function setup() {
createCanvas(canvasWidth, canvasHeight);
}
function draw() {
noLoop()
background(255)
for (i = 0; i < canvasHeight / grid; i++) {
for (j = 0; j < canvasWidth / grid; j++) {
coordenadaX = i * grid;
coordenadaY = j * grid;
noStroke()
fill(200);
triangle(coordenadaX, coordenadaY, coordenadaX, coordenadaY + grid, coordenadaX + grid, coordenadaY)
fill(100);
triangle(coordenadaX, coordenadaY + grid, coordenadaX + grid, coordenadaY, coordenadaX + grid, coordenadaY + grid)
}
formes = int(random(0, 2))
noStroke()
if (formes == 1) {
blacksquare1()
} else if (formes == 0) {
blacksquare2()
}
}
}