xxxxxxxxxx
var thetext; // the words we are gonna work with
var fonts = []; // an array of fonts
var fadespeed = 100; // frames to fade in and out
var theline; // the current line of text
var tw, th; // the width and height of the text
function preload() {
// load the text and the fonts
thetext = loadStrings('stein.txt');
fonts[0] = loadFont('Eutemia.ttf');
fonts[1] = loadFont('dramaticstyle.otf');
fonts[2] = loadFont('breakfastDEMO.otf');
fonts[3] = loadFont('SanitariumBB.otf');
}
function setup() {
createCanvas(windowWidth, windowHeight);
rectMode(CENTER);
// pick a random line and font to start with:
theline = random(thetext);
textFont(random(fonts));
// strip out blank lines in the text file:
for(let i = thetext.length-1;i>=0;i--)
{
if(thetext[i]=='') thetext.splice(i, 1);
}
}
function draw() {
background(192, 192, 216);
textSize(30);
textAlign(CENTER, CENTER);
// use frameCount to switch lines and fade in new ones:
if(frameCount%fadespeed==0) // switch line:
{
textFont(random(fonts)); // new font!
theline = random(thetext); // new line!
tw = textWidth(theline); // how wide?
th = textAscent()+textDescent(); // how tall?
}
// fade in the box and get to full opacity halfway in:
let alpha = frameCount%fadespeed/fadespeed/2*255.
noFill();
stroke(70, 70, 32, alpha);
rect(width/2, height/2, tw, th); // draw a box!
noStroke();
fill(0, 0, 0, alpha);
text(theline, width/2, height/2); // draw the text!
}