xxxxxxxxxx
// what i'm trying to do is to let all the words appear on screen (it creates a sense of actually reading a book) but I haven't figured it out yet.
var thetext;
var thestring;
var thewords = [];
var fontsize = 50;
var x = 0;
var y = fontsize;
var whichword = 0;
function preload() {
thetext = loadStrings('book.txt');
img = loadImage("image.jpeg");
song = loadSound("Not Today.mp3");
font = loadFont("Creattion Demo.otf");
}
function setup() {
song.play()
createCanvas(windowWidth, windowHeight);
textFont(font);
stroke(0);
frameRate(3);
textSize(fontsize);
thestring = '';
for(let i = 0;i<thetext.length;i++)
{
thestring+=thetext[i]+' ';
}
thewords = thestring.split(' ');
console.log(thewords);
}
function draw() {
background(img);
let a = textWidth(thewords[whichword]+' ');
if(x+a>width)
{
x = 0;
y = y + fontsize*1 ;
}
text(thewords[whichword], x, y);
x+=a;
whichword = (whichword+1)%thewords.length;
}