Holycrapbooks, Batman!

This week we had to use data. Most of my code is lifted from the example provided in class. I changed it around and tried to make it a bit creepier/more interesting.

    

I compared Isaac Asimov’s Foundation series and J.D. Salinger’s Catcher in the Rye. Both books are cited for inspiring violent behavior and murder in certain individuals (Timothy McVeigh and Mark David Chapman, respectively).  I wanted to compare the words both authors use most often to see if there are any similarities.

I had some trouble removing certain words, so  the way it is in the code is a little slap/dash, because I got overwhelmed with doing something more intricate. I’d like to remove some more of the small words, maybe by taking out every 3-letter word and below.

 

Screen Shot 2014-04-14 at 2.42.07 PM

//asimov and salinger comparison
PImage photo;
String[] catcher; 
String delimiters = " - ,.?!;:[]";
IntDict words;

String[] foundation; 
IntDict panda;

//setup
void setup() {
  size(800, 640);
  photo = loadImage ("owl.jpg");
  String url = "http://www-958.ibm.com/software/analytics/manyeyes/datasets/the-catcher-in-the-rye-full-text/versions/1.txt";
  String[] rawtext = loadStrings(url);
  String everything = join(rawtext, "" );
  catcher = splitTokens(everything, delimiters);
  words = new IntDict();

  for (int i = 0; i < catcher.length; i++) {
    String s = catcher[i].toLowerCase();
//if statement with remove words
    words.increment(s);
  }
  words.sortValuesReverse();
  words.remove("the");
  words.remove("i");
  words.remove("and");
  words.remove("to");
  words.remove("a");
  words.remove("was");
  words.remove("it");
  words.remove("you");
//asimov
  String[] rawfile = loadStrings("asimov.txt");
  String everything2 = join(rawfile, "" );
  foundation = splitTokens(everything2, delimiters);
  panda = new IntDict();

  for (int j = 0; j < foundation.length; j++) {
    String d = foundation[j].toLowerCase();
    panda.increment(d);
  }
  panda.sortValuesReverse();
  panda.remove("the");
  panda.remove("of");
  panda.remove("and");
  panda.remove("a");
  panda.remove("to");
  panda.remove("that");
  panda.remove("you");
  panda.remove("'");

}

//draw
void draw() {
  image(photo, 0, 0);
 // background(255);//no need twice

  int h = 20;
  String[] keys = words.keyArray();

  for (int i = 0; i < height/h; i++) {
    String theword = keys[i];
    int count = words.get(theword);

fill(random (255), random (255), random (255));
    noStroke();
    ellipse(width/4, i*20, count/8, count/8);
    fill(255);
    text(theword, 0, i*h+h/2);
    stroke(0);
  }

//asimov
// Display the text and total times the word appears
  int g = 20;
  String[] keys2 = panda.keyArray();

  for (int j = 0; j < height/g; j++) {
    String theword = keys2[j];
    int count = panda.get(theword);

fill(random (255), random (255), random (255));
    noStroke();
    ellipse(width/4*3, j*20, count/20, count/20);
    fill(255);
    text(theword, width - 70, j*g+g/2);
    stroke(0);
  }

}

 

Leave a Reply