xxxxxxxxxx
45
let cam;
let circleSize = 20;
let density = "❃❄❅❆❇❈✿✸✬";
function setup() {
createCanvas(640, 480);
cam = createCapture(VIDEO, { flipped: true });
cam.hide();
}
function draw() {
background(220);
let w = width / cam.width;
let h = height / cam.height;
cam.loadPixels();
for (let y = 0; y <= cam.height; y += circleSize) {
for (let x = 0; x <= cam.width; x += circleSize) {
let index = (x + y * cam.width) * 4;
let r = cam.pixels[index + 0];
let g = cam.pixels[index + 1];
let b = cam.pixels[index + 2];
let averageCol = (r + g + b) / 3;
let len = density.length;
let charIndex = floor(map(averageCol, 0, 255, 0, len));
noStroke();
fill(r, g, b);
textSize(circleSize);
text(density.charAt(charIndex),
x * w + w * 0.3,
y * h + h * 0.3);
}
}
cam.updatePixels();
}