xxxxxxxxxx
65
// Declare a variable to hold the video
let video;
function setup() {
createCanvas(500, 500);
// Initialize the video capture
video = createCapture(VIDEO);
// Set the size of the video capture to 50x50 pixels
video.size(50, 50);
video.hide();
}
function draw() {
// Set the background color to black
background(0);
// Declare variables for red, green, blue, and brightness values
let r, g, b, bright;
// Load the pixels of the video capture
video.loadPixels();
// Calculate the width and height of each pixel
let w = width / video.width;
let h = height / video.height;
// The character stringt that would be printed
let chr = "ME";
let k = 0;
// Loop through each pixel in the video capture
for (let i = 0; i < video.width; i++) {
for (let j = 0; j < video.height; j++) {
// Calculate the pixel index
let pixelI = (j + i * video.width) * 4;
// Get the red, green, blue, and alpha values of the pixel
r = video.pixels[pixelI + 0];
g = video.pixels[pixelI + 1];
b = video.pixels[pixelI + 2];
alp = video.pixels[pixelI + 3];
// Calculate the brightness value of the pixel - grayscale value
bright = (r + g + b + alp) / 4;
// Set the text color to the brightness value of the pixel
noStroke();
fill(bright);
// Set the font size to the size of the pixel
textSize(w);
// Set the text alignment to center
textAlign("CENTER", "CENTER");
// Display the text in the center of the pixel
text(chr[k], j * h + h * 0.5, i * w + w * 0.5);
// Increase the counter variable if it's not at the end of the string, otherwise reset it
if (k <= chr.length - 2) {
k++;
} else {
k = 0;
}
}
}
}