xxxxxxxxxx
37
let x, y, w, h;
let lx, rx, ty, by;
function setup() {
createCanvas(800, 600);
background(20);
// 1st argument: x-coordinate of the rectangle
// 2nd argument: y-coordinate of the rectangle
// 3rd argument: width of the rectangle
// 4th argument: height of the rectangle
x = width / 2;
y = height / 2;
w = width / 2;
h = height / 2;
lx = x - w / 2;
rx = x + w / 2;
ty = y - h / 2;
by = y + h / 2;
rectMode(CENTER);
}
function draw() {
//draw with rect()
// noStroke();
// rect(x, y, w, h);
//draw with vertex()
beginShape(QUADS);
vertex(lx, ty);
vertex(rx, ty);
vertex(rx, by);
vertex(lx, by);
endShape();
}