The program is, at least on some level, an example of a quine1. A quine is a program that generates its own code as output. Consider this perl program I wrote (there are many more ways to do this in perl, but this is the one I came up with):
#! /usr/bin/perl $s='$c = chr(39);$t = q^#! /usr/bin/perl $s=^.$c.$s.$c.q^;eval $s;^."\n";print $t;';eval $s;This works by quoting the meat of the program in
$s
, and
then printing this string along with all the cruft at the
beginning and end, including the eval
used to execute the
print
. The only tricky bit is to avoid terminating
the single quotes, which I do using the chr
function.
The image above was generated with a similar script, except that the body of the program generated the gradient. The other twist is that a simple form of steganography is used to store the source code: each byte from the source is embedded in the least significant bits of the pixels. Running the script with the image file (in ppm format) as an argument will then display the source.
Here's the perl source.
To improve on this script, I'd like to use evolutionary procedural image generation (ala Karl Sims) to make the image actually look interesting.
[1] Named after philosopher Willard Van Orman Quine who championed reflective sentences like this one: "Is a phrase" is a phrase.