xxxxxxxxxx
35
let board = [];
let cols; let rows; let size = 10;
let img;
function preload(){
img = loadImage("images/autumn2.png");
}
function setup() {
createCanvas(600, 400);
rectMode(CENTER);
cols = width/size;
rows = height/size;
img.resize(width, 0);
for (let i=0; i<cols; i++) {
board[i] = [];
for (let j=0; j<rows; j++) {
let c = img.get(i*size, j*size);
// Mapping brightness from 0 - 100 (dark to light) to 0 to 3 to pick shapes
let s = map(brightness(c), 80, 100, 0, 3);
board[i][j] = new Shape(size/2+i*size, size/2+j*size, floor(s), c);
}
}
}
function draw() {
background('#28c4c7');
for (let i=0; i<cols; i++) {
for (let j=0; j<rows; j++) {
board[i][j].display();
}
}
}