xxxxxxxxxx
var thetext; // this is gonna be the whole book, line by line
var thebigstring; // this is gonna be the whole book
var thewords = []; // this is gonna be an array of all the words
var fontsize = 30;
var x = 0;
var y = fontsize;
var whichword = 0;
var thefont = [];
function preload() {
thetext = loadStrings('alice.txt'); // load in a text file
thefont[0] = loadFont('Kirkjufell.ttf');
thefont[1] = loadFont('gabriele-bad.ttf');
thefont[2] = loadFont('Welcome Summer.ttf');
thefont[3] = loadFont('the unseen.ttf');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
fill(0);
stroke(0);
//frameRate(15);
textFont(random(thefont));
textSize(fontsize);
thebigstring = ''; // start with a blank nothing
for(let i = 0;i<thetext.length;i++)
{
thebigstring+=thetext[i]+' ';
}
thewords = thebigstring.split(' ');
console.log(thewords);
}
function draw() {
if(thewords[whichword]=='Alice')
{
textSize(fontsize*2);
}
else {
textSize(fontsize);
}
textFont(random(thefont)); // pick a random font
fill(random(0,255), 0, 0);
stroke(0, 0, random(0,255));
let wlen = textWidth(thewords[whichword]+' ');
if(x+wlen>width)
{
x = 0; // carriage return
y = y + fontsize*1.; // line feed
}
if(y>height) // page turn
{
x = 0;
y = fontsize;
background(255);
}
text(thewords[whichword], x, y);
x+=wlen;
whichword = (whichword+1)%thewords.length;
}