xxxxxxxxxx
64
// Mimi Yin
// NYU ITP
// Array of words
let words = [];
// Current word
let current_word = 0;
// Variable to hold the random string being built
let str = '';
// Paragraph element to hold the text
let p;
function preload() {
loadStrings('turkey.txt', process);
}
function setup() {
createCanvas(windowWidth, windowHeight);
p = createP();
}
function draw() {
// Draw next word every half second
if (frameCount % 30 == 0) {
str += words[current_word] + ' ';
// Update paragraph element
p.html(str);
// Go to next word
current_word++;
// Wrap around to beginning
current_word %= words.length;
}
}
function process(lines) {
// Go line by line by value
for (let line of lines) {
// Turn each line into an array of words
let tokens = splitTokens(line);
// Add it to 1 big array
words = words.concat(tokens);
}
// Go word by word, by index
// Clean up each word
for (let w in words) {
let word = words[w];
// Remove punctuation
word = word.replace(/[-_:;.,!?\(\)]/g, "");
// Make it all lowercase
word = word.toLowerCase();
// Get rid of whitespace around the word
word = word.trim();
// If nothing is left, get rid of it
if (word.length < 1) words.splice(w, 1);
// Otherwise put cleaned up word back in array
else words[w] = word;
}
// Shuffle words
words = shuffle(words);
}