xxxxxxxxxx
21
let numRectangles = 10;
let rectWidth;
function setup() {
createCanvas(400, 400);
noStroke();
}
function draw() {
//numRectangles = map(mouseX, 0, width, 4, 20);
rectWidth = width / numRectangles;
background(150, 120, 182);
for (let i = 0; i < numRectangles; i++) {
let posX = rectWidth*i;
let posY = height - rectWidth*(i+ 1);
let rectHeight = rectWidth*(i+1);
let fillColor = map(i, 0, numRectangles - 1, 0, 255);
fill(fillColor);
rect(posX, posY, rectWidth, rectHeight);
}
}