xxxxxxxxxx
62
var rhymes, word, data;
function setup()
{
createCanvas(300, 300);
fill(255);
textFont("Georgia");
lexicon = new RiLexicon();
findRhymes();
data = loadStrings('readme_4.txt');
// words = data.split(' ');
setInterval(findRhymes, 2000);
}
function draw()
{
background(100,0,100);
textAlign(RIGHT);
textSize(36);
text(word, 280, 40);
textAlign(LEFT);
textSize(14);
textLeading(17);
text(rhymes, 30, 73);
}
function newWord(){
var w = data[floor(random(data.length))];//lexicon.randomWord();
w = w.split(' ');
w = w[floor(random(w.length))];
return w;
}
function isAlpha(w){
var letters = /^[A-Za-z]+$/; // some regex
var allLetters = w.match(letters);
return (w.length !=0 && allLetters);
}
function findRhymes() { // called by timer
if(data == undefined){
return;
}
var tmp = '';
do {
word = newWord();
while(!isAlpha(word) ){
word = newWord();
}
tmp = lexicon.rhymes(word);
} while ( word && tmp.length < 3)
var arr = subset(tmp, 0, min(tmp.length, 13)); // max of 13 words
rhymes = arr.join("\n");
}