xxxxxxxxxx
34
//Topic: Create a grid of 10 columns and 5 rows. (EXTRA-CHALLENGE: When you mouseover a cell, fill that cell with a shade of gray that is related in some way to its column and row.
let columns = 10;
let rows = 5;
let wColumns;
let hRows;
let add;
function setup() {
createCanvas(400, 200);
wColumns = width / columns;
hRows= height / rows;
stroke(255);
}
function draw() {
background(225);
//for(r = 0; r<=columns; r++ && d = 0; d<=rows; d++
for(r = 0; r<=columns; r++) {
for (d = 0; d<=rows; d++) {
let x = r*wColumns;
let y = d*hRows;
//the color part learned from other people's code, still trying to understand why
let spotColor = dist(mouseX, mouseY, x, y);
spotColor = map(spotColor, 0, dist(0, 0, width, height), 255, 0);
fill(spotColor);
rect(x,y,wColumns,hRows);
}
}
}