Faster WordCrams? An Experiment

Simulated annealing is a programming trick for quickly packing a bunch of things together. It’s based on the idea of annealing, where (as I understand it) a metal is heated, which gives the molecules enough energy to wiggle, then cooled slowly, which lets the molecules settle into a denser arrangement.

I’ve been wondering for a while whether this could make WordCram faster. It seems well-suited to the problem – the heart of WordCram is packing non-overlapping shapes together.

So I made this Processing experiment sketch, which uses simulated annealing to arrange circles.

I think it works pretty well – it can arrange 200 circles of different sizes along a line in under a second. (My first experiment was a lot slower, which gives you an idea how powerful this trick can be – once you get it right.)

Posted in Uncategorized | Leave a comment

WordCram’s moving to GitHub

I started moving WordCram on to GitHub, and most things are in place, like the issues list and the wiki. I still need to copy over the downloads. Got the downloads, too! (Only 0.5.0 for now – the older ones are still at googlecode, but I’ll probably copy them too, eventually.)

Let me know if I missed anything!

Posted in Uncategorized | Leave a comment

WordCram Release 0.5.0

Today I learned that WordCram 0.4.1 doesn’t work with Processing 1.5, and the root of the problem is the way it renders word shapes. Then I found that the same change that enables PDF rendering enables Processing 1.5 support.

So I could bug-fix the Processing 1.5 support, or throw in PDF rendering and call it a release. Changing the way WordCram renders word shapes is pretty core, so I chose the release. And as a bonus, PDF support is official!

And that’s how WordCram 0.5.0 found its way out into the world this afternoon. The big news is PDFs, but you can also control the padding between your words. Download it now! You can thank me later. Send me a WordCrammed PDF.

Next up: replacing the text parsing code with cue.language.

Posted in release, wordcram | 6 Comments

New daily: WordCram to PDF

WordCram now outputs to PDF. It’ll be in the 0.5 release, but you can grab the new daily build right now (zip or tar) and try it out. The only new code you’ll need is normal Processing PDF stuff, all the WordCram code stays the same. Just import processing.pdf.*, and use size(width, height, PDF, "path/to/output.pdf").

Here’s an example, a PDF word cloud from the Wikipedia page on PDF. Here’s the code to produce it:

import processing.pdf.*;
import wordcram.*;

void setup() {
  size(700, 700, PDF, "wordcram.pdf");
  
  background(255);
  
  new WordCram(this)
    .fromWebPage("http://en.wikipedia.org/wiki/Portable_Document_Format")
    .withColors(#000000, #777777, #ff0000)
    .withFonts("LiberationSans")
    .sizedByWeight(1, 200)
    .withWordPadding(1)
    .angledAt(0)
    .withPlacer(new WordPlacer() {
      public PVector place(Word w, int r, int c, int ww, int wh, int fw, int fh) {
        float xScatter = (1-w.weight);
        float x = map(random(-xScatter, xScatter), -1, 1, 30, fw-ww-30);
        float y = (1-pow(w.weight, 0.25)) * (fh - wh) + 30;
        return new PVector(x, y);
      }
    })
    .drawAll();
}

I’m pretty excited about this. PDF output was one of the first features asked for, and it’s been a goal of mine to finish it. But more importantly, we can now print some really nice, high-res word clouds!

Posted in examples, wordcram | 6 Comments

BarCamp Boston 6 Slides Up

Here they are!

Posted in wordcram | Leave a comment

See You at Barcamp Boston 6

http://www.barcampboston.org/

import wordcram.*;

void setup() {
  size(900, 500);
  colorMode(HSB);
}

void draw() {
  background(68);
  color red = color(0, 255, 255);
  color mustard = color(30, 255, 255);
  
  new WordCram(this)
    .fromWebPage("http://en.wikipedia.org/wiki/Barcamp")
    .withColors(color(0, 0, 0), 
                color(0, 0, 255), 
                mustard) // red)
    .withFonts(PFont.list())
    .withAngler(moreRandomByWeight())
    .withPlacer(crazyPlacer())
    .sizedByWeight(8, 100)
    .maxNumberOfWordsToDraw(300)
    .drawAll();
}

WordAngler moreRandomByWeight() {
  return new WordAngler() {
    public float angleFor(Word w) {
      float range = (1-w.weight) * PI;
      return random(-range, range);
    }
  };
}

WordPlacer crazyPlacer() {
  return new WordPlacer() {
    public PVector place(Word w, int rank, int words, 
                        int ww, int wh, int fw, int fh) {
      float x = (fw-ww) * (1-w.weight);
      float y = random(fh-wh);
      return new PVector(x, y);
    }
  };
}

Posted in examples, wordcram | 1 Comment

WordCram Release 0.4.1

WordCram 0.4.1 is a minor bug-fix release, available in zip and tar.

Danilo Di Cuia wondered whether French accents worked in WordCram, which surprised me, because I’ve seen characters like that in WordCrams before. But as it turns out, it only worked if you pass your own array of Words: the word-counting part was removing all accented characters from the source text.

The bug’s fixed now, but for the 0.5 release, I’ll probably replace that whole part with cue.language instead. It’s a small library for natural-language tasks, written by Wordle creator Jonathan Feinberg, and it grew out of Wordle. It’s better-tested, and it handles a bunch of languages already. That part of WordCram was always pretty immature, so it’ll be nice to rely on something more battle-hardened.

 

Posted in release, wordcram | Leave a comment