import treemap.*; Treemap map; void setup( ) { size(1024, 768); smooth( ); strokeWeight(0.25f); PFont font = createFont("Serif", 13); textFont(font); WordMap mapData = new WordMap( ); String[] lines = loadStrings("script.txt"); String line = join(lines, " "); // Replace -- with an actual em dash. line = line.replaceAll("--", "\u2014"); String[] phrases = splitTokens(line, ".,;:?!\u2014\""); for (int i = 0; i < phrases.length; i++) { // Make this phrase lowercase. String phrase = phrases[i].toLowerCase( ); // Split each phrase into individual words at one or more spaces. String[] words = splitTokens(phrase, " "); for (int w = 0; w < words.length-1; w++) { if (!ignoreWord(words[w])) mapData.addWord(words[w]); } } // for (int i = 0; i < lines.length; i++) { // mapData.addWord(wolines[i]); // mapData.finishAdd( ); map = new Treemap(mapData, 0, 0, width, height); // Run draw( ) only once. noLoop( ); } String[] ignore = { "a", "of", "the", "i", "it", "you", "and", "to" }; boolean ignoreWord(String what) { for (int i = 0; i < ignore.length; i++) { if (what.equals(ignore[i])) { return true; } } return false; } void draw( ) { background(255); map.draw( ); }