xxxxxxxxxx
32
let pixel_size = 20; // Size for each pixel
let panda = [
[1, 1, 0, 0, 0, 0, 0, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 1, 1, 0, 1, 1, 1, 0],
[0, 1, 1, 0, 0, 0, 1, 1, 0],
[0, 1, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[1, 0, 0, 1, 1, 1, 0, 0, 1],
[1, 1, 0, 0, 0, 0, 0, 1, 1]
];
function paint_color(panda) {
for (let row = 0; row < panda.length; row++) {
for (let col = 0; col < panda[row].length; col++) {
if (panda[row][col] === 1) {
fill(0); // paint black for the panda
noStroke();
} else {
fill(255); // paint white for the panda's face
}
rect(col * pixel_size + 100, row * pixel_size + 100, pixel_size, pixel_size);
}
}
}
function setup() {
createCanvas(400, 400);
background('white');
paint_color(panda);
}