Golan Levin and Collaborators

Flong Blog + News

Tag Clouds in Processing with OpenCloud

28 January 2011 / code, infovis, pedagogy, reference

I created a demo of tag clouds in Processing using MCavallo‘s excellent Java-based OpenCloud library. The development was extremely straightforward. Below is the Processing applet (hosted at OpenProcessing), visualizing a tag cloud of Dr. Suess’ Green Eggs and Ham, and its code. (The entire project can be downloaded here.) Clicking the applet alternates between alphabetic and frequency-based tag sorting.

In a related demonstration, I combined this tag cloud generator with a SubRip (subtitle text file) parser to produce a tag cloud visualization of the subtitles in Star Wars.

Processing Tag Cloud Demo, using MCavallo's OpenCloud Library
>> http://opencloud.mcavallo.org/
>> http://sourceforge.net/users/mcavallo

Developed using Processing 1.2.1, http://processing.org/
Using the text from Dr. Suess's "Green Eggs and Ham".
Press the mouse to see the words reorganized. 

To recompile this Processing sketch: 
(1) In your sketch folder, create a folder called "code".
Inside the code folder, place the "opencloud.jar" file which comes in:
(2) In your sketch folder, create a folder called "data". 
Put the "green_eggs_and_ham.txt" file there.

import org.mcavallo.opencloud.*;

Cloud  cloud;
String greenEggsAndHam[];
float  maxWordDisplaySize = 60.0;

void setup() {
  size (400,300); 

  // create a tagCloud object
  cloud = new Cloud(); // create cloud 
  cloud.setMaxWeight(maxWordDisplaySize); // max font size 
  cloud.setMaxTagsToDisplay (50);

  // Load the text file
  greenEggsAndHam = loadStrings("green_eggs_and_ham.txt"); 
  int nLines = greenEggsAndHam.length;
  for (int i=0; i 0) {
      String lineWords[] = split(greenEggsAndHam[i], " ");
      int nLineWords = lineWords.length;
      for (int j=0; j (width - (xMargin*2))) {
      xPos  = xMargin;
      yPos += ySpacing;

Comments are closed.

« Prev post:
» Next post: