I have this assignment that I have to make a word cloud of the most common words used in an external text file which all words will start from the center and expand/animate to a word cloud... I already made a word counter to determine which words are most often used in the text file, now that I know which words are most often used, how can I select at least 15 random words from the top 50 most used words in the text file?
if that question can be easily answered how can I overlap all the selected words on the canvas?
note: I am very noob at java and processing so a code would help...
here is my code:
String [] words;
IntDict concordance;
int index = 0;
void setup () {
size (500,500);
background (0);
String [] lines = loadStrings ("alice_just_text.txt");
String entireplay = join(lines, " ");
words = splitTokens (entireplay, ",.?!:-;:()03 ");
concordance = new IntDict () ;
frameRate (5);
for (int i = 0; i < words.length;i++) {
concordance.increment(words[i].toLowerCase());
}
concordance.sortValuesReverse();
String [] keys = concordance.keyArray();
for (int i = 0; i < keys.length; i++) {
int count = concordance.get(keys[i]); //word counts
println(keys[i], count);
}
}
void draw () {
background (0);
textSize (64);
textAlign (CENTER);
text (words [index], width/2, height/2);
index++;
}
Aucun commentaire:
Enregistrer un commentaire