xxxxxxxxxx
37
let capture;
let symbols = ["@", "#", "$", "%", "&", "*", "+", "-", ".", "/"]; // Customize symbols
let resolution = 15; // Adjust for coarser or finer details
function setup() {
createCanvas(640, 480);
capture = createCapture(VIDEO);
capture.size(width / resolution, height / resolution);
capture.hide(); // Hide the actual webcam feed
textFont('monospace');
textAlign(CENTER, CENTER);
textSize(resolution);
noStroke();
}
function draw() {
background(0);
capture.loadPixels();
for (let y = 0; y < capture.height; y++) {
for (let x = 0; x < capture.width; x++) {
let index = (x + y * capture.width) * 4; // Get pixel index
let r = capture.pixels[index + 0];
let g = capture.pixels[index + 1];
let b = capture.pixels[index + 2];
let brightness = (r + g + b) / 3; // Calculate brightness
let symbolIndex = floor(map(brightness, 0, 255, 0, symbols.length));
let symbol = symbols[symbolIndex];
fill(r, g, b); // Use the pixel color
text(symbol, x * resolution, y * resolution);
}
}
}