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

Blog Header by WordCram

Here is, more-or-less, the sketch I used to generate the new WordCram blog header. About half of the sketch is Processing setup and interaction, so I could keep running it until I found one I liked.

When I get around to it, I want to make it easier to load a directory of source code files, but for now, cat find -name *.java > src.txt is good enough.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import wordcram.*;
import wordcram.text.*;

WordCram wc;

void setup() {
  colorMode(HSB);
  size(940, 198);
  background(0);

  initWordCram();
}

void initWordCram() {
  String license = join(loadStrings("LICENSE"), " ").toLowerCase();

  wc = new WordCram(this)
      .fromTextFile("src.txt")
      .withStopWords(StopWords.ENGLISH + StopWords.JAVA + license)
      .withFont("Droid Sans Mono")
      .sizedByWeight(12, 60)
      .withPlacer(new WordPlacer() {
          public PVector place(Word w, int wordCount, int numWords,
                               int wordWidth, int wordHeight,
                               int fieldWidth, int fieldHeight) {

            // x = weight, heavies on the left
            float x = (fieldWidth - wordWidth) * (1 - (float)w.weight);
            x *= random(0.6, 1); // fade them back a bit -- don't clump on the right

            // y = random around center horiz. line. Heavier words are less random.
            float y = random(1) *
                      (1 - (float)w.weight) *
                      (fieldHeight - wordHeight) / 2;
            y += (fieldHeight - wordHeight) / 2;

            return new PVector(x, y);
          }
      })
      .withAngler(new WordAngler() {
          public float angleFor(Word w) {

            // swing between -30 and 30 degrees -- heavy words swing less
            return (1 - (float)w.weight) * random(radians(-30), radians(30));
          }
      });
}

void draw() {
  if (wc.hasMore()) {
    wc.drawNext();
  }
  else {
    save("wordcram.png");
    println("done");
    noLoop();
  }
}

void mouseClicked() {
  background(0);
  initWordCram();
  loop();
}

Update 2015-02-03: I moved the WordCram blog to github pages, and changed the layout. Here’s the original blog header I was talking about; it graced wordcram.org for a good 5 years.

<<

>>