April 03, 2004

My First Applet

Attention conservation notice: This post is about my learning Java so as to write a simple cellular automaton as an applet. If CAs interest you at all, your time will be much better spent at the Primordial Soup Kitchen than reading the rest of this post.

Judy Leemann, an old friend of Kris's, now finishing her MFA in Chicago, wanted images of a particular cellular automaton growth rule for an installation. I volunteered to write her an applet to make some pictures of it, since I'd been wanting to learn Java for a while, and had even taken stabs in that direction last summer and the summer before. After a week of coffee, head-scratching and gentle advice from Kris, here we are: red-fringed cellular moss. The rule, in case you're wondering, is a stochastic contract growth process, working as follows. Cells are binary, with a four-cell (von Neumann) neighborhood. If exactly one or exactly four of a cell's neighbors are occupied, it is eligible for growth. At each point in time, exactly one eligible cell is selected, completely at random, and grown into. Cells marked in red are eligible; cells marked in green were once eligible, but aren't any more. While I like the colored pictures, the version I made for Judy's installation just shows the basic process, in the classic simplicity of black and white.

I did worry a bit, when I volunteered, that I'd run into problems because I'd never done any serious graphics programming, but that wasn't really an issue; this wasn't serious graphics programming either. Much more trouble arose from the facts that (1) the good people at Sun decided, effectively, that before you write applets you should understand threads and (2) none of the teach-yourself-Java books I have explained this adequately. Hard-to-find bugs were mostly my own damn fault, e.g., for not writing an equals method for a new class, and then comparing instances of that class. There would've been many more of these if I'd had to deal with pointers. Overall I'm pleased with the language, and with having learned it; if I'd done so circa 1996 it might even have been a useful skill.

While I'm on the subject of teach-yourself-Java-books, I looked at quite a few, and found a lot of them less than helpful, and some even insultingly bad. Two were worthwhile. Budd's Understanding Object-Oriented Programming with Java is well-written, reasonably compact and seems quite sound; I liked the fact that it tries to explain the general ideology of object-orientation, and its roots in simulation. Aside from more on applets, the main deficiency I could detect is that it doesn't cover Swing at all. Niemeyer and Knudsen's Learning Java is four times as long as Budd, but I think most of the extra bulk is from covering lots of the language features in detail, things which Budd leaves to the documentation as such. Also, it has a really cute cover.


Posted at April 03, 2004 21:21 | permanent link

Three-Toed Sloth