xxxxxxxxxx
88
//IML 300
// Ming Leng
// Concrete Poetry - Making a wish, seeing the fireworks.
let keywords = ["make", "a", "wish", "here", "make", "a", "wish", "here", "make", "a", "wish", "here", "make", "a", "wish", "here", "make", "a", "wish", "here", "make", "a", "wish", "here"];
let words = [];
let input;
let customFontSize = 20;
let fireworksImg; // Variable to hold the fireworks image
let isCustomInput = false; // Flag to track if there's a custom input
function preload() {
fireworksImg = loadImage("fireworks.gif");
}
function setup() {
createCanvas(windowWidth, windowHeight);
input = createInput();
input.position(windowWidth / 2, windowHeight / 2);
input.input(handleInput);
textSize(customFontSize);
textAlign(CENTER);
for (let i = 0; i < keywords.length; i++) {
words.push({
text: keywords[i],
x: random(width),
y: random(-500, 0),
speed: random(1, 2),
fontSize: customFontSize
});
}
}
function draw() {
// Use the fireworks image as the background if there's a custom input
if (isCustomInput) {
background(fireworksImg);
} else {
background(0);
}
for (let i = 0; i < words.length; i++) {
let word = words[i];
textSize(word.fontSize);
if (word.speed < 0) {
let redValue = random(0, 255);
fill(255, redValue, 0);
} else {
fill(255);
}
text(word.text, word.x, word.y);
word.y += word.speed;
if (word.y > height || word.y < 0) {
word.y = word.speed > 0 ? random(-500, 0) : height + random(0, 500);
word.x = random(width);
word.speed = word.speed > 0 ? random(1, 3) : -random(1, 3);
}
}
}
function handleInput() {
let userText = this.value().trim(); // Trim whitespace from the input
if (userText === '') {
isCustomInput = false; // Reset the flag if the input is empty
for (let i = 0; i < words.length; i++) {
words[i].text = keywords[i % keywords.length]; // Reset to original keyword
words[i].y = random(-500, 0); // Start above the canvas
words[i].speed = abs(words[i].speed); // Ensure the speed is positive for downward movement
words[i].fontSize = customFontSize; // Reset to default font size (24)
}
} else {
isCustomInput = true; // Set the flag for custom input
for (let i = 0; i < words.length; i++) {
words[i].text = userText;
words[i].y = height - words[i].y;
words[i].speed = -abs(words[i].speed);
words[i].fontSize = 50;
}
}
}