Skip to content

Instantly share code, notes, and snippets.

@edsonsoares
Created November 4, 2014 06:16
Show Gist options
  • Save edsonsoares/6eea91ff176c09c445c9 to your computer and use it in GitHub Desktop.
Save edsonsoares/6eea91ff176c09c445c9 to your computer and use it in GitHub Desktop.
Text Visualization 2
String[] words;
IntDict concordance;
int counter = 0;
void setup () {
size (600, 400);
String [] lines = loadStrings ("statement.txt");
String allthetxt = join (lines, " ");
words = splitTokens (allthetxt, " ,.;!?()");
concordance = new IntDict();
for (int i=0; i < words.length; i++) {
concordance.increment(words[i].toLowerCase());
}
concordance.sortValuesReverse();
}
void draw() {
background(0);
// Look at words one at a time
if (counter < words.length) {
String s = words[counter];
counter++;
concordance.increment(s);
}
// x and y will be used to locate each word
float x = 0;
float y = 48;
concordance.sortValues();
String[] keys = concordance.keyArray();
//Look at each word
for (String word : keys) {
int count = concordance.get(word);
//Only display word sthat appear 2 times
if (count > 2) {
// The size is the count
int fsize = constrain (count, 0, 48);
textSize(fsize);
text(word, x, y);
//Move along the x-axis
x += textWidth (word + " ");
}
//if gets to the end, move y
if (x > width) {
x = 0;
y += 48;
//if y gets to the end, we're done
if (y> height){
break;
}
}
}
noLoop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment