Generative Text

For this week’s assignment, I decided to work with text instead of data visualization. I started off with creating photos out of text, but then I wasn’t sure if that was enough, so I made a project that took in words from Nick’s post about his snail story. With that, the program counted which words appeared the most in the text. The ones with the most occurrence would appear larger in size compared to the others.

Here are images created from text:

 

PImage timeImage; 
PFont f;
String[] chars = {"t", "i", "m", "e"};

int i = 0;
int incr = 10;
void setup() {
  size(560, 560);
  timeImage = loadImage("time.jpg");
  f = createFont("Monaco", 15);
  textFont(f);
}

void draw() {
  background(0);
  timeImage.loadPixels();
  for (int x = 0; x < timeImage.width; x += incr) {
    for (int y = 0; y < timeImage.height; y += incr) {
      int loc = x + y * timeImage.width;
      i++;
      float red = red(timeImage.pixels[loc]) ;
      float green = green(timeImage.pixels[loc]);
      float blue = blue(timeImage.pixels[loc]);
      fill(color(red, green, blue));
      text(chars[i % chars.length], x, y);
    }
  }
}

 

This is the one from the snail text: To distinguish the words, the bigger text ones shake a bit too. 

String[] textLines;
String[] words;
String fileText;
PFont font;
int len;
int ct = 0;

ArrayList<String> seenWords = new ArrayList<String>();
ArrayList<Integer> wordSize = new ArrayList<Integer>();
ArrayList<Float> xPos = new ArrayList<Float>();
ArrayList<Float> yPos = new ArrayList<Float>();

void setup() {
  fullScreen();
  font = createFont("ZapfDingbatsITC", 32);
  textFont(font);
  textLines = loadStrings("textlalal.txt");
  fileText = join(textLines, "");
  String files = fileText.toLowerCase();
  words = splitTokens(files, ",?!.:\" ");
  len = words.length;
  textAlign(CENTER);
  frameRate(30);
  for (int idx = 0; idx < len; idx++) {
    String word = words[idx];
    int loc = seenWords.indexOf(word);
    if (seenWords.contains(word)) {
        wordSize.set(loc, wordSize.get(loc) + 5);
        textSize(wordSize.get(loc)); 
    } else {
      int wordLen = word.length();
      seenWords.add(word);
      wordSize.add(wordLen + 5);
      xPos.add(width/2 + random(-500, 500));
      yPos.add(height/2 + random(-350, 350));
      textSize(wordLen);
    }
  }
}

void draw() {
  background(0);
  for (int i = 0; i < seenWords.size() - 1; i++) {
    textSize(wordSize.get(i));
    if (wordSize.get(i) > 20) {
      //xPos.set(i, lerp(xPos.get(i), 250, 0.01));
      text(seenWords.get(i), xPos.get(i) + random(-1, 1), yPos.get(i) + random(-1, 1) );
    } else {
      text(seenWords.get(i), xPos.get(i) , yPos.get(i));
    }
  }
}

 

 

Leave a Reply