xxxxxxxxxx
const density = '@ÑW#80$965432ba1?c7=!+;_-,:. ';
let vid;
function setup() {
createCanvas(1200, 675);
vid = createCapture(VIDEO);
vid.hide();
vid.size(16 * 5, 9 * 5);
}
function draw() {
background(0);
let w = width / vid.width;
let h = height / vid.height;
pixelDensity(1);
vid.loadPixels(1);
for (let j = 1; j < vid.height; j++) {
for (let i = 1; i < vid.width; i++) {
const pixelIndex = (i + j * vid.width) * 4;
const r = vid.pixels[pixelIndex + 0];
const g = vid.pixels[pixelIndex + 1];
const b = vid.pixels[pixelIndex + 2];
const avg = (r + b + g) / 3;
strokeWeight(2);
stroke(0, 255, 0);
// fill(0, 255, 0);
noFill();
// square(i * w, j * h, w);
const len = density.length;
const charIndex = floor(map(avg, 0, 255, len, 0));
// textStyle(BOLD);
textSize(w * 1.5);
textAlign(CENTER);
text(density.charAt(charIndex), i * w + w * 0.5, j * h + h * 0.5);
}
}
}