True's beaked whale.jpg

Western spotted skunk

Hooded skunk

Yellow-throated Marten

Wolverine

Archive for January, 2010

Book review: Ever Since Darwin

Thursday, January 28th, 2010

Ever Since Darwin cover
Ever Since Darwin is book of essays by Stephen Jay Gould, originally written as columns for Natural History magazine.

This is Gould’s first collection of essays, published in 1977. It’s a great introduction to Gould’s writing. The essays are shorter and the ideas are simpler than those in some of his later collections. There are great essays on the life and times Darwin worked in, and on how evolutionary and developmental biology got worked out through fits and starts. The last few essays on sociobiology are kind of weak. I guess 30 years on, it’s hard to really understand the ground that was being fought over.

Overall, a great book!

L-system Iterator

Monday, January 11th, 2010

I’ve put up a web site for exploring L-system images, L-system Iterator.

Well known L-systems

The snowflake shape is only one example of the pictures that can be drawn this way.

L-systems are simple iterated drawing rules. Simple rules for turning and drawing put together in this way make quite interesting and complicated patterns. The ones shown above are well known. From the the left, the Koch snowflake, the Sierpinski triangle, a kolam-like image, and a plant-like image. On the second row, the Heighway dragon, the Hilbert curve, and another plant.

The Heighway dragon has many interesting properties–for example, it can be tiled over the plane.

Some iterated objects are fractals–the Koch snowflake, Sierpinski triangle, and Hilbert curve are famous simple fractals.

L-systems can be quite complicated. The systems modeled on my web site use a single rotation angle and only one line width. More complicated models can make surprisingly realistic plants. Prusinkiewicz and Lindenmayer (the L in L-system) have developed detailed plant models.

The web site is based on the Perl code I wrote for my Biomorph evolution/selection web site. The images are generated using Postscript to draw the L-system, and then the ImageMagick convert program to change it to a PNG image. Images are given a file name that describes the L-system, effectively caching the image. The Prototype Javascript library is used to assist in making the popup boxes.

Each L-system variant has two changes from the current L-system. Some logic is used to keep the L-system in the same family–if there’s no Y equation, one isn’t added. Existing equations are grown or shrunk but not dropped. These images can take much longer to generate than the Biomorph images, so a number of limits are placed to keep the L-system from getting too complicated or taking too much CPU time.

The hardest part of the Postscript was getting the images scaled and centered appropriately. The images can extend in any direction and some are large, others small. The centering code generates the image twice, once to find out its dimensions and then a second time scaled and centered. Here’s the code to record the dimensions of each part of the image. It gets called before each stroke operation.

/max_path {
gsave initmatrix pathbbox grestore


ur_y false eq { /ur_y exch store } { dup ur_y gt { /ur_y exch store } { pop } ifelse } ifelse
ur_x false eq { /ur_x exch store } { dup ur_x gt { /ur_x exch store } { pop } ifelse } ifelse
ll_y false eq { /ll_y exch store } { dup ll_y lt { /ll_y exch store } { pop } ifelse } ifelse
ll_x false eq { /ll_x exch store } { dup ll_x lt { /ll_x exch store } { pop } ifelse } ifelse
} def

The ‘initmatrix’ command is required to reset things because of all the rotation operations.

The code for the site is linked on the L-system iterator home page.

Update: Added color variation as an option. And a reverse direction primitive.

Also, the code now runs under mod_perl.

Note for mod_perl users–mod_perl 2.0 has no way of handling alarms. select() doesn’t work either as a way of timing out pipes. The only usable method is prepending commands with ‘ulimit -t secs’ and letting the shell limit the system process.

To make the split color B&W images I used these ImageMagick commands:
convert -size 150x150 tile:color.png tile:bw.png ../temp/mask.png -composite split.png
using a half black, half white split image as the mask.

Then added the split line using:
convert -size 150x150 -fill white -stroke black -draw "line 0,0 150,150" split.png split_line.png