xxxxxxxxxx
44
const density = '520bois';
let shen;
function preload() {
shen = loadImage("jn2.png");
}
function setup() {
createCanvas(3000, 2020);
}
function draw() {
background(0,0,0,0);
let w = width / shen.width;
let h = height / shen.height;
shen.loadPixels();
for (let i = 0; i < shen.width; i++) {
for (let j = 0; j < shen.height; j++) {
const pixelIndex = (i + j * shen.width) * 4;
const r = shen.pixels[pixelIndex + 0];
const g = shen.pixels[pixelIndex + 1];
const b = shen .pixels[pixelIndex + 2];
const avg = (r + g + b) / 3;
noStroke();
fill(255);
//square(i * w, j * h, w);
const len = density.length;
const charIndex = floor(map(avg,0,255,len,0));
textSize(w);
textAlign(CENTER, CENTER);
if(avg > 0 && avg < 255) text(density.charAt(charIndex), i * w + w * 0.5, j * h + h * 0.5);
}
}
}