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;
function preload() {
thetext = loadStrings('alice.txt'); // load in a text file
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
fill(0);
stroke(0);
//frameRate(15);
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() {
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;
}