xxxxxxxxxx
29
let rectStart = {
x: -1,
y: -1,
};
function setup() {
createCanvas(windowWidth, windowHeight);
background(220, 20, 120);
noLoop();
}
function draw() {}
function mouseClicked() {
if (rectStart.x == -1 || rectStart.y == -1) {
rectStart.x = mouseX;
rectStart.y = mouseY;
} else {
let rectEndX = mouseX;
let rectEndY = mouseY;
let rW = rectEndX - rectStart.x;
let rH = rectEndY - rectStart.y;
rect(rectStart.x, rectStart.y, rW, rH);
rectStart.x = -1;
rectStart.y = -1;
}
}