xxxxxxxxxx
61
let spaceMono;
let img;
let grid = 50;
let letter = ['N','G','C']
function preload() {
spaceMono = loadFont('assets/SpaceMono-Regular.ttf');
img = loadImage('assets/DNA-test.jpeg');
}
function setImage(cols, rows) {
img.resize(cols, rows);
}
function setup() {
createCanvas(1000, 1000);
textFont(spaceMono);
textAlign(CENTER, CENTER);
colorMode(HSB,255);
setImage(grid, grid);
}
function draw() {
noLoop();
newGrid();
//image(img,0,0,width,height);
}
function newGrid() {
background(0);
fill(255);
let tx = grid;
let ty = grid;
let tw = width / tx;
let th = (height / ty);
translate(tw / 2, th / 2);
for (let x = 0; x < tx; x++) {
for (let y = 0; y < ty; y++) {
let c = img.get(x, y);
//let selector = int(map(brightness(c), 0, 255, 0,20));
let size = int(map(brightness(c), 0, 255, 20,0));
let randomLetter = int(random(letter.length));
textSize(floor(size*0.65));
text(letter[randomLetter], x * tw, y * th);
}
}
}
function keyPressed(DOWN_ARROW){
save("canvas.svg");
}