xxxxxxxxxx
var thetext;
var thebigstring;
var thewords = [];
var fontsize = 50;
var x = 0;
var y = fontsize;
var whichword = 0;
var thefont = [];
function preload() {
thetext = loadStrings('sofia.txt'); // load in a text file
thefont[0] = loadFont('anattalia-personal-use-only.regular.otf');
thefont[1] = loadFont('teen.light-regular.ttf');
thefont[2] = loadFont('grinched.regular.otf');
thefont[3] = loadFont('the unseen.ttf');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background("black");
fill(0);
stroke(0);
frameRate(10);
textFont(random(thefont));
textSize(fontsize);
y= random(fontsize, windowHeight-fontsize);
thebigstring = ''; // start with a blank nothing
for(let i = 0;i<thetext.length;i++)
{
thebigstring+=thetext[i]+' ';
}
thebigstring = thebigstring.replace(/[^a-zA-Z0-9’ ]/g, ' ');
thebigstring = thebigstring.replace(/ ’/g, ' '); // kill apostrophes at beginning of words
thebigstring = thebigstring.replace(/’ /g, ' '); // kill apostrophes at end of words
thebigstring = thebigstring.toLowerCase();
thebigstring = thebigstring.replace(/ +/g, ' ');
thebigstring = thebigstring.trim(); // kill any dangling crud
console.log(thebigstring);
thewords = thebigstring.split(' ');
}
function draw() {
textFont(random(thefont)); // pick a random font
fill(random(255), 100, 100);
stroke(255, 0, random(255));
let wlen = textWidth(thewords[whichword]+' ');
if(x+wlen>width)
{
x = 0;
y = random(fontsize, windowHeight-fontsize);
background("black");
}
text(thewords[whichword], x, y);
x+=wlen;
whichword = (whichword+1)%thewords.length;
}