xxxxxxxxxx
42
let video;
var pixel_density = ['$', '@', 'B', '%', '8', '&', 'W', 'M', '#', '*', 'o', 'a', 'h', 'k',
'b', 'd', 'p', 'q', 'w', 'm', 'Z', 'O', '0', 'Q', 'L', 'C', 'J', 'U', 'Y', 'X', 'z',
'c', 'v', 'u', 'n', 'x', 'r', 'j', 'f', 't', '/', '|', '(', ')', '1', '{', '}', '[', ']',
'?', '-', '_', '+', '~', '<', '>', 'i', '!', 'l', 'I', ';', ':', ',', '<', '^', '`', '.', ' '
];
function setup() {
createCanvas(640, 360);
video = createVideo(['sample2.mp4']);
video.loop();
//video.hide();
//noStroke();
noStroke();
fill(0, 255, 0);
}
function draw() {
background(0);
video.loadPixels();
const stepSize = 10;
for (let y = 0; y < height; y += stepSize) {
for (let x = 0; x < width; x += stepSize) {
const index = 4 * (y * width + x);
let c = color(video.pixels[index],
video.pixels[index + 1],
video.pixels[index + 2]);
let gray = brightness(c);
gray = parseInt(map(gray, 0, 255, 0, pixel_density.length));
text(pixel_density[gray], x, y);
}
}
}
function keyPressed()
{
if( key == 's' ){
save("output.png");
}
}