xxxxxxxxxx
39
let img;
let harryPotterText = ["Hogwarts", "Magic", "Harry", "Hermione", "Dumbledore", "Gryffindor", "Slytherin"]; // Use an array of words instead
function preload() {
img = loadImage("https://i.pinimg.com/564x/5d/88/a7/5d88a760e86c3b35cff903fe82cb492d.jpg"); // Load your Harry Potter character image
}
function setup() {
createCanvas(img.width, img.height);
img.loadPixels();
textSize(10);
textAlign(CENTER, CENTER);
fill(0);
noLoop(); // Draw only once
}
function draw() {
background(255); // White background
let words = harryPotterText.split(" "); // Split words into an array
// Loop through each pixel of the image
for (let y = 0; y < img.height; y += 10) { // Adjust step size for spacing
for (let x = 0; x < img.width; x += 10) {
let index = (x + y * img.width) * 4;
let r = img.pixels[index]; // Red value for brightness
let brightness = map(r, 0, 255, 0, 1); // Map brightness to 0-1 scale
let word = random(words); // Pick a random word from the text
// Use brightness to affect size or other parameters
let fontSize = map(brightness, 0, 1, 8, 18); // Adjust size based on brightness
textSize(fontSize);
// Draw word at (x, y)
text(word, x, y);
}
}
}