WordCram

open-source word clouds for Processing

Follow WordCram on Twitter @wordcram

Ask a Question in the Forum /wordcram

Pull Requests Welcome on GitHub danbernier/WordCram

Latest News

WordCram 1.0.0 Released, for Processing 3.0

WordCram 0.6.2 Released

WordCram 0.6.1 Released

All posts

Looking for some inspiration? Curious about WordCram, but don’t know where to start? Take a look around.

Letter Stair Case

import wordcram.*;

void setup() {
  size(400, 250);
}

void draw() {
  background(255);
  fill(0);

  new WordCram(this).
    fromWords(loadLetters()).
    angledAt(0).
    minShapeSize(0).  // Make sure "I" always shows up.
  drawAll();
}

Word[] loadLetters() {
  Word[] letters = new Word[26];
  for (int i = 0; i < 26; i++) {
    Word letter = new Word(str(char(65+i)), 1);
    float x = map(i, 0, 29, 0, width);
    float y = map(i, 0, 29, 0, height);
    letter.setPlace(new PVector(x, y));
    letter.setSize(35);
    letters[i] = letter;
  }
  return letters;
}

Us Constitution

/*
US Constitution text from http://www.usconstitution.net/const.txt
Liberation Serif font from RedHat: https://www.redhat.com/promo/fonts/
*/

import wordcram.*;

void setup() {
  size(800, 600);
  background(255);
  colorMode(HSB);
  
  new WordCram(this)
      .fromTextFile("../../usconst.txt")
      .withFont(createFont("../../LiberationSerif-Regular.ttf", 1))
      .sizedByWeight(10, 90)
      .withColors(color(0, 250, 200), color(30), color(170, 230, 200))
      .drawAll();
}

First Names

/*
firstnames is a WordCram of the most popular first names from 
the 1990 US Census.  Predictably, males are blue, and females
are pink.  It also shows one way you can use a custom WordColorer.
See firstnamesUsingSubclasses, in examples/OtherExamples, for another.

When you're parsing the names data, you know whether each word
is a male or female name.  To take advantage of this, the sketch
creates a Word object, and pre-sets its color to blue or pink,
via the setColor() method.

Names collected from http://www.census.gov/genealogy/names
Minya Nouvelle font from http://www.1001fonts.com/font_details.html?font_id=59
*/

import wordcram.*;

Word[] names;

void setup() {
  colorMode(HSB);
  size(800, 600);
  background(255);
  
  loadNames();
  
  new WordCram(this)
    .fromWords(names)
    .withFont(createFont("../../MINYN___.TTF", 1))
    .sizedByWeight(12, 60)
    .drawAll();
}

void loadNames() { 
  String[] nameData = loadStrings("../../names.txt");
  names = new Word[nameData.length];
  for (int i = 0; i < names.length; i++) {
    names[i] = parseName(nameData[i]);
  }
}

// Each row looks like:
// Mary\t1.0\tf
// ...or:
// {name} {tab} {frequency} {tab} {'f' for females, 'm' for males}
Word parseName(String data) {
  String[] parts = split(data, '\t');
  
  String name = parts[0];
  float frequency = float(parts[1]);
  boolean isFemale = "f".equals(parts[2]);
  
  Word word = new Word(name, frequency);
  
  if (isFemale) {
    word.setColor(#f36d91); // pink
  }
  else {
    word.setColor(#476dd5); // blue
  }
  
  return word;
}

Yin Yang Words

import wordcram.*;
import java.awt.*;

void setup() {
  size(600, 600);
  background(255);
  
  PImage image = loadImage("yinyang.png");
  image.resize(width, height);
  
  Shape imageShape = new ImageShaper().shape(image, #000000);
  ShapeBasedPlacer placer = new ShapeBasedPlacer(imageShape);

  new WordCram(this).
    fromWords(repeatWord("flexible", 500)).
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(4, 40).
    angledAt(0).
    withColor(#F5B502).
    drawAll();
    
  
  imageShape = new ImageShaper().shape(image, #ffffff);
  placer = new ShapeBasedPlacer(imageShape);
  
  new WordCram(this).
    fromWords(repeatWord("usable", 500)).
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(4, 40).
    angledAt(0).
    withColor(#782CAF).
    drawAll();
}

Word[] repeatWord(String word, int times) {
  Word[] words = new Word[times];
  for (int i = 0; i < words.length; i++) {
    // Give the words a random weight, so they're sized differently.
    words[i] = new Word(word, random(1));
  }
  return words;
}

More is coming soon.