xxxxxxxxxx
66
let w = 383;
let h = 575;
let textLayer;
let imageBuffer = [];
function setup() {
createCanvas(w, h);
textLayer = createGraphics(w, h); // Offscreen buffer for text mask
storeTextInBuffer();
drawDiagonalLines();
}
function drawDiagonalLines() {
stroke(0);
strokeWeight(1);
strokeCap(ROUND);
let size = 10; // Line spacing
for (let x = size / 2; x < w; x += size) {
for (let y = size / 2; y < h; y += size) {
let index = Math.round(y) * w + Math.round(x);
let isInside = index < imageBuffer.length && imageBuffer[index];
if (isInside) {
// Lines inside text: opposite direction "\"
let x1 = x - size / 2;
let y1 = y + size / 2;
let x2 = x + size / 2;
let y2 = y - size / 2;
line(x1, y1, x2, y2);
} else {
// Background lines: standard direction "/"
let x1 = x - size / 2;
let y1 = y - size / 2;
let x2 = x + size / 2;
let y2 = y + size / 2;
line(x1, y1, x2, y2);
}
}
}
}
function storeTextInBuffer() {
textLayer.background(255);
textLayer.fill(0);
textLayer.noStroke();
textLayer.textAlign(CENTER, CENTER);
textLayer.textSize(250);
textLayer.textFont("serif");
//textLayer.textStyle(BOLD);
textLayer.text("M", w / 2, h / 3);
textLayer.text("K", w / 2, (h / 3) * 2);
textLayer.loadPixels();
imageBuffer = new Array(w * h).fill(false);
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
let index = (y * w + x) * 4;
let brightness = textLayer.pixels[index]; // Get red channel (assuming grayscale)
imageBuffer[y * w + x] = brightness < 128; // True if part of text
}
}
}