xxxxxxxxxx
78
// assigned characters with space attributed to darker areas and <3 for brighter areas
// const density = " <33";
const density = " \u2661";
const density1 = " ?";
let video;
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
video = createCapture(VIDEO);
video.size(64, 48);
video.hide();
}
function draw() {
background(0);
// let emoji1 = "🤳🧍❔";
// let emoji = "🤳🧑🤝🧑❤️"
// push();
// text(emoji1, width / 6, height / 4);
// text(emoji, width / 6, height / 2);
// textSize(32);
// textAlign(CENTER, CENTER);
// pop();
// function singleAscii(){
// video.loadPixels();
// fill(255, 180, 180);
// stroke(255, 180, 180);
// strokeWeight(1);
// let asciiImage1 = "";
// for (let j = 0; j < video.height; j++) {
// for (let i = 0; i < video.width; i++) {
// const pixelIndex = (i + j * video.width) * 4;
// const r = video.pixels[pixelIndex + 0];
// const g = video.pixels[pixelIndex + 1];
// const b = video.pixels[pixelIndex + 2];
// const avg = (r + g + b) / 3;
// const len = density1.length;
// const charIndex = floor(map(avg, 0, 255, 0, len));
// const c = density1.charAt(charIndex);
// text(
// c,
// map(i, 0, video.width, 0, width),
// map(j, 0, video.height, 0, height)
// );
// }
// }
// }
video.loadPixels();
fill(255, 180, 180);
stroke(255, 180, 180);
strokeWeight(1);
let asciiImage = "";
for (let j = 0; j < video.height; j++) {
for (let i = 0; i < video.width; i++) {
const pixelIndex = (i + j * video.width) * 4;
const r = video.pixels[pixelIndex + 0];
const g = video.pixels[pixelIndex + 1];
const b = video.pixels[pixelIndex + 2];
const avg = (r + g + b) / 3;
const len = density1.length;
const charIndex = floor(map(avg, 0, 255, 0, len));
const c = density1.charAt(charIndex);
text(
c,
map(i, 0, video.width, 0, width),
map(j, 0, video.height, 0, height)
);
}
}
}