xxxxxxxxxx
39
let img;
let lines = [];
function preload() {
// Load the image
img = loadImage('rsz_3me.png');
}
function setup() {
createCanvas(img.width, img.height);
noLoop();
}
function draw() {
// Display the image on the canvas
image(img, 0, 0);
// Load the pixels of the image
loadPixels();
// Iterate through each pixel
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
// Get the color of the current pixel
const index = (x + y * width) * 4;
const r = pixels[index];
const g = pixels[index + 1];
const b = pixels[index + 2];
const a = pixels[index + 3];
// Print the color values to the console
lines.push("r: " + r + " g: " + g + " b: " + b);
}
}
saveStrings(lines, "cols.txt");
noLoop();
}