Ex Nihilo

A Processing Sketch Blog

WallBlank prints now up

Just a quick update: I mentioned I was having some prints produced a few days ago; they’ve now been added to WallBank. I wrote up the process in Vector Output, so go have a read if you’re curious about how I did it. I have a print sitting on my desk, the paper is a thick high quality archival stock, and the ink is quite a bit richer than the on-site preview.

In an interesting case of things coming around full circle, apparently the whole idea behind WallBlank’s site was inspired by a post I wrote on the main blog last year. Seems only fitting that I’d contribute something sooner or later.

August 18th, 2009 | No Comments »

Bring on the Trig

2Π. Pythagorean. SOH CAH TOA. Conjures up terms of grade 10, doesn’t it? I had to go waaay back into the memory banks to even pull out a starting point for a recent trigonometry refresher.

It started like this: I had an idea to plot some points on a sphere. Now, I understand with some crafty use of the rotate() function I’d probably be able to get by without doing the math myself, but I guess I had the urge to dig a bit deeper in case I need to really know this (again) at some point.

So I started light and plotted some random points around a circle. By setting the X coordinate, I can reverse the Pythagorean equation enough to work out the math for the Y coordinate:

  X = random(0 - radius, radius);
  Y = sqrt(pow(radius, 2) - pow(X, 2));

That only gets me a positive value for Y though, which renders as a semicircle. So a bit more randomization was necessary to get the full circle:

  int rev = int(random(0, 2));
  if (rev == 1) {
    Y = sqrt(pow(radius, 2) - pow(X, 2));
  } else {
    Y = 0 - sqrt(pow(radius, 2) - pow(X, 2));

Which doesn’t strike me as terribly elegant, but that’s about the limit of my coding ability.

Random Point Circle

So that was the start. Now that I can plot individual points around a circle, why not use something other than points? With some fairly basic box() objects and various rotations and transformations, things get interesting quickly:


I still haven’t gotten the math for the sphere down yet, though. That was a “walk away for now, and come back to it in a few days” type of problem.

August 17th, 2009 | 2 Comments »

Reading a Google Docs Spreadsheet

There doesn’t seem to be much on the web specifically about tying together Processing and Google Docs, but it’s fairly simple when you realize the latter has a ton of export options that work pretty easily with Processing. I’m starting with CSV, though the option to work with XML will likely come in handy down the line.

Starting with a spreadsheet filled with a few dozen values, I can get at the CSV with a simple export:

Picture 2

The loadStrings function pulls in a local file or a remote URL as a String array:

String[] inputFileLines;
inputFileLines = loadStrings(
  "http://spreadsheets.google.com/pub? ->

It’s fairly trivial to walk through the array and do something useful with the numbers:

inputFileIndex = 0;

while (inputFileIndex < inputFileLines.length) {
  String pieces = inputFileLines[inputFileIndex];
  if (pieces.length() > 0) {

    // do stuff with the 'pieces' string here,


The data exists as strings though, so it’s probably more useful to convert each value to float() or int() before using it. With the simple CSV file I linked up earlier as a source, I used the basic loop to assign the data points as the radii values for each of a set of spheres plotted randomly along the Y axis, or the height of a set of bars slightly tilted along the X axis:


If we were to say the linear-increasing X value is time, that makes for a couple of fun 3D graphs that even Tufte can be proud of. (Or not.)

August 12th, 2009 | No Comments »

Vector Output

After some idle speculation about taking my last posted sketch further, I’ve been going back and forth with a boutique print site called Wall Blank about doing a run of prints. This may be as far as I take them, or it may just be the tip of the iceberg; but more on that later (whenever I figure it out).

The immediate challenge was outputting something usable in print. I saw two options; figure out a way to use a canvas thousands of pixels across for the sake of saving out a bitmapped screen grab as a file high-resolution enough to print, or, instead find a way to output as vector.

The latter is clearly the better option and it turns out Processing has a built in PDF library that does all the hard work for you. It’s not totally straightforward; you can’t just dump the screen contents to a file, instead you have to capture the entire draw loop from the start and save that out. But even that is fairly simple. My draw loop ended up something like this:

void draw() {

  // setup the PDF save
  if (writePDF) {
    beginRecord(PDF, "frame-####.pdf");

      // draw things here

  // now that the draw buffer is full,
  // dump the contents to a file
  if (writePDF) {
    writePDF = false;

The writePDF variable was an important check; without it I’d be writing PDFs on every frame. Instead I can toggle it on keypress and just capture a single frame:

void keyPressed() {
  // if 'p' is pressed, save out a PDF
  if (int(key) == 112) {
    writePDF = true;

The resulting PDFs are surprisingly svelte; 8000 ellipses saved out to about files around 110k. My PNG screen grabs are usually at least 4 times as large.

What was particularly fun about this project is that I dared to ask whether each print could be unique, or if we were stuck working with the same source PDF for each print. I was pleasantly surprised to discover the printer was totally cool with printing a unique file for each one of the 100-print series, and happy to take advantage of that. With a slight modification to my draw loop:

void draw() {
  if ((createStuff > 0) && (createStuff < 101)) {
    beginRecord(PDF, "print-####.pdf");

  if ((createStuff > 0) && (createStuff < 101)) {

...all I had to do was hit a key and wait about a minute, and voila, 100 totally unique prints, but united as a series with a common palette.


I'll make sure to mention it again on here when the prints are available for purchase, probably closer to the end of August.

August 10th, 2009 | 1 Comment »


I meant to move on from all-ellipses all-the-time already, but I wanted to try some interaction effects. While adapting one of my previous sketches, I stumbled on this neat marble effect that I’ve been playing with for a few days. Though it started as a happy accident, it’s good enough that I think I might actually take this one further and produce some sort of tangible item.

But that’s going to take some time and research. In the meantime, here are a few conveniently wallpaper-sized images I’ve saved out, feel free to nab one for your desktop:


Or, of course, for your iPhone:


August 6th, 2009 | 4 Comments »

Recursive Trees

I spent the better part of this past week trying my hand at creating a decent-looking recursive tree, in between all the sweating this heat wave is causing.


Maybe it’s the heat but I think I’m ready to throw in the towel. I got the recursion working reasonably well, but the branch curves look terrible, and most of the logical adjustments I wanted to make ended up in division by zero for some reason I couldn’t track down.

Like, a for loop starting from zero and incrementing i on each iteration; I get that for the first iteration i = 0 so you’d think this equation should work, right?

    variation = multiplier / (i + 1);

But no such luck. “Division by zero” error. My actual code is more complicated of course, but that’s the essence of it; the loop is just not behaving as I’d have expected.

So I think for now it’s time to put this sketch to bed and move on to something else. Shame, I had some interesting things I wanted to do with the trees eventually.

July 31st, 2009 | 4 Comments »

Dot Cube

I’m back to dots again. This time I’m stacking them in an orderly cube, and with the random palette some of them look pretty darn good.

I can’t get this one exported into anything usable in a browser for some reason; the applet that Processing creates just doesn’t want to run. I suspected the photos I’m using to generate the palette are to blame, but after hitting up the troubleshooting guide I appear to be doing everything right. The main symptom (aside from not running) is that the exported applet is only sized to 100×100 in the browser, which is a) wrong and b) strange.

Anyway, in lieu of something you can play with, here are some screen caps:


If for some reason you really really trust me, you can download the native applications Processing generates (Mac OS X, Windows, both around 2.5MB) and play with them on your own system. No guarantees they won’t hose your computer, but, they shouldn’t.

(Use the mouse to rotate the cube, press a or z to zoom in and out — or the mousewheel, but that’s buggy — and you can kind of drag it up and down to reposition, though that doesn’t work well either. Hit the spacebar for a fresh palette. Oh, and s will save out a PNG of the current frame if you’re so inclined.)

July 24th, 2009 | No Comments »

Bezier Stalks

So after yesterday’s Bezier celebration I thought I’d try a more structured approach and see if I couldn’t capture some interesting movement. Reducing the number of objects down to 3600 and plotting them along a grid as a start, I got the end points and curves moving along Perlin-assisted paths in kind of a wind-blown look.

Still all in 3D space of course, so I saved out a quick capture with some viewpoint shifts and generated palettes. (With the latter you can pretty clearly see that not everything that’s generated is usable since I have to cycle through a few different palettes before I get something decent).

July 24th, 2009 | No Comments »

Bezier Blossoms

Bezier curves are hard enough to get the hang of in a graphics program with visual handles, but plotting the handles in 3D space is a whole new ball of wax.

I played around a bit tonight with about 80,000 of them by rotating from the origin and randomizing both the endpoint and the end handle of each curve with Perlin noise. The results are neat:


By keeping track of the coordinates of each line I can manipulate the entire blossom in 3D space, though at 80,000 lines it’s a pretty slow refresh. I added an animation loop too, to get each line swaying a little; it works well with a few thousand, but not when the numbers get this high.

I’m also sticking with this photo-generated palette idea; it’s a great way to get a bunch of interesting colours in a hurry that don’t clash too badly. I’ve upped the photo pool to 10, and one is selected randomly each time the palette is generated. Each of the above examples only uses 5 colours, but I can change that number to whatever; the previous example used something like 25.

July 23rd, 2009 | 2 Comments »

Generated Palette

Okay, the generated palette idea was easier than I thought. Importing the photo into an off-screen buffer and grabbing some random pixel values makes for a fairly quick and easy way of generating an interesting palette. Here’s the photo:


And here are a few of the results:


July 23rd, 2009 | 1 Comment »

« Older Entries | Newer Entries »