xxxxxxxxxx
40
let words = [];
let str = '';
//paragraph element
let p;
function preload() {
loadStrings('1.txt', process);
}
function setup() {
createCanvas(windowWidth, windowHeight);
p = createP();
}
function draw() {
if (frameCount % 20 == 1) {
str += random(words) + ' ';
// update paragraph element
p.html(str);
}
}
function process(lines) {
for (let line of lines) {
let tokens = splitTokens(line);
words = words.concat(tokens);
}
// cleanup process
for (let w = words.length-1; w >= 0; w--) {
let word = words[w];
word = word.replace(/[-_:;.,!?()]/g,"");
word = word.toLowerCase();
word = word.trim();
if (word.length < 1) words.splice(w,1);
else words[w] = word;
}
}