xxxxxxxxxx
31
let phrase = "I wish to wash my Irish wristwatch.";
let positions = [];
function setup() {
createCanvas(windowWidth, windowHeight);
textSize(32);
fill(0);
randomizePositions(); // set initial positions
}
function draw() {
fill(0)
background(255);
// draw chars at their stored positions
for (let i = 0; i < phrase.length; i++) {
text(phrase[i], positions[i].x, positions[i].y);
}
}
function mousePressed() {
randomizePositions(); // update positions when the screen is clicked
}
function randomizePositions() {
positions = [];
for (let i = 0; i < phrase.length; i++) {
positions.push({ x: random(width), y: random(height) });
}
}