xxxxxxxxxx
63
/**************************************************
#1 is https://editor.p5js.org/Anne-Laure/sketches/btgqrh9jA
#3 is https://editor.p5js.org/Anne-Laure/sketches/QICjyjN8f
https://www.youtube.com/watch?v=55iwMYv8tGI
translat the pixels of an image into text
finish with rendering video as text ASCII characters
starting from 10'
Image source
https://pixabay.com/fr/photos/chien-jack-russel-terrier-terrier-7417233/
**************************************************/
const density = "Ñ@#W$9876543210?!abc;:+=-,._ ";
let img;
function preload() {
img = loadImage("dog48.jpg");
}
function setup() {
createCanvas(500, 500);
}
function draw() {
background(0);
image( img, 0, 0 ) ;
let w = width / img.width ;
let h = height / img.height ;
img.loadPixels() ;
for( let i = 0; i < img.width; i++ ) {
for( let j = 0; j < img.height; j++ ) {
const pixelIndex = ( i + j * img.width ) * 4 ;
const r = img.pixels[ pixelIndex + 0 ] ;
const g = img.pixels[ pixelIndex + 1 ] ;
const b = img.pixels[ pixelIndex + 2 ] ;
noStroke() ;
let greyVal = (r+g+b) / 3 ;
// fill( r, g, b ) ;
fill( greyVal ) ;
textSize(w) ;
textAlign( CENTER, CENTER ) ;
text( 'G', i*w + 10, j*h + 10 ) ;
}
noLoop() ;
}
}