xxxxxxxxxx
44
//javascript literal object
let word_count = {
//defining words
'hi': 1,
'bye': 2,
};
function preload(){
loadStrings('america.txt',process)
}
function setup() {
createCanvas(400, 400);
for (let word in word_count) {
let wc = word_count[word];
textSize(wc * 10);
text(word, random(width), random(height));
}
}
function draw() {
//background(220);
}
function process(lines){
for (let line of lines){
let tokens = splitTokens(line);
words.push(tokens);
}
for(let w in words){
word = word.trim();
word = word.toLowerCase();
word = word.replace(/[,.?!]/g,'');
words[w] = word;
}
for(let word of words){
if(word in word_count) word_count[word]++;
else word_count[word] = 1;
}
}