xxxxxxxxxx
36
// https://happycoding.io/examples/p5js/images/pixel-painter
let img;
function preload() {
img = loadImage('images/cat-3.jpg');
// Click the > menu to the left and look in
// the images directory for more images to try!
// Or upload your own image!
// URLs also work, like this:
// img = loadImage('https://upload.wikimedia.org/wikipedia/commons/6/69/June_odd-eyed-cat_cropped.jpg');
}
function setup() {
createCanvas(600, 600);
// Resize the image so it fits on the screen.
img.resize(width, height);
background(32);
noStroke();
}
function draw() {
// Get the color of a random pixel.
img.loadPixels();
const pixelX = random(width);
const pixelY = random(height);
const pixelColor = img.get(pixelX, pixelY);
// Paint that pixel with a circle.
fill(pixelColor);
circle(pixelX, pixelY, 20);
}