xxxxxxxxxx
38
let str = "I dunk a skunk in a trunk full of gunk";
let x = 0;
let y = 0;
let c = 0;
function setup() {
createCanvas(400, 400);
textSize(36);
textAlign(LEFT, TOP);
background(220);
}
function draw() {
// Display a single character from the string every 10 frames
if (frameCount % 10 === 1) {
let ch = str.charAt(c); // Get the current character
text(ch, x, y); // Draw the character at the current position
x += textWidth(ch); // Move the x position by the width of the character
// Check if the x position exceeds the canvas width
if (x > width) {
x = 0; // Reset x to the beginning of the line
y += textAscent() + textDescent(); // Move to the next line
// Check if the y position exceeds the canvas height
if (y > height) {
y = 0; // Reset y to the top
//background(220); // Clear the canvas
}
}
c++; // Move to the next character
c %= str.length; // Wrap around to the beginning of the string
}
}