const imgSrc = "https://i.loli.net/2018/10/19/5bc9db906f615.jpg";
let img;
function preload() {
img = loadImage(imgSrc)
}
function setup() {
createCanvas(img.width, img.height);
background(0);
}
function draw() {
for(let i= 0; i< 20; i++){
let x = random(width);
let y = random(height);
let col = img.get(x, y);// 获取x,y上的像素值[r,g,b,a]
let r = red(col);
let g = green(col);
let b = blue(col);
noStroke();
fill(r,g,b/2);
ellipse(x,y,6);
}
}