LJ Archive

Art Is but Engineered Reality

Marcel Gagné

Issue #99, July 2002

Generating your own landscapes, moonscapes and sheepscapes right on your desktop.

Cooking with Linux

Art Is but Engineered Reality

Generating your own landscapes, moonscapes and sheepscapes right on your desktop.

by Marcel Gagné

Dare I say, François, that this 1999 Côte-Rôtie is transcendent? Sipping a fine wine like this, I am transported to new planes of existence. Of course not really, François, it is only an expression. It is a compliment that I pay the vintner for such a fine wine. Am I not still here with you in this very restaurant, looking at the menu for this month's engineering focus issue?

Reality and perception are uniquely personal experiences, mon ami, experiences all Linux users may explore if they wish. One of the great joys of the Linux environment is the freedom it provides to talented programmers the world over to create alternative ways of working and playing. Those of us who merely use, prepare and serve their creations can then share in those visions as well.

François, where are you, mon ami? Your attention seems drawn elsewhere. Ah, mes amis! Welcome to Chez Marcel. I did not realize you were already here. François, Vite! Fetch more of this wonderful wine for our guests immédiatement. Please sit, everyone. Be comfortable. François will return momentarily with more of the 1999 Côte-Rôtie I was just sampling, er, I mean, subjecting to quality control, of course. It may seem strange, mes amis, but François and I were just discussing the nature of reality and perception.

I have never truly gotten over my first view of a great fractal landscape. The breathtakingly real mountainous panorama, with its snowcapped mountains and nestled lakes, made me understand the sheer beauty of mathematics. If something as complex as a landscape or a fern or a galaxy could be reduced to a series of mathematical symbols replayed over and over again, there is definitely something starkly beautiful at the heart of the universe.

Using a little program called xmountains, you can recreate those dreamlike landscapes for yourself. Go to author Stephen Booth's web site (www.epcc.ed.ac.uk/~spb/xmountains) and get yourself the latest version of his program. Engineer a little reality, manipulate it and dress up your desktop.

With that, it is time to extract and build the source. Notice that I have created a temporary directory into which the source can be extracted. The files are, unfortunately, not saved within their own directory. Building xmountains consists of these simple steps:

mkdir temp_dir
cd temp_dir
tar -xzvf xmountains_2.6.tar.gz
xmkmf
make

Then you can copy the resulting binary (called xmountains) to wherever you see fit (perhaps /usr/local/bin). There are many ways to tweak the program's output with command-line switches, but in its simplest form you can just type xmountains & and watch the show. A full-screen window will open up with a randomly generated landscape. Every ten seconds the landscape will scroll a little bit to the left with newly generated terrain. To see the available options, use the -h option. Have a look at Figure 1 for a sample of xmountains' output.

Figure 1. A Mountainous Virtual Reality

Depending on the window manager you are using, it is possible to modify xmountains to write directly to the root window, thus providing a constantly changing fractal landscape. By default, the code does not allow for this, and the effect doesn't work well on all window managers. Consequently, the author did not make this option a default for the program. I decided to go ahead and make the changes. Perhaps, mes amis, you will try it as well. The change is an easy one. Modify your Makefile and look for the line that reads PROJECT_DEFINES =, and change it to look like this:

PROJECT_DEFINES = -DVROOT

Now do a make clean followed by a make and rerun the program with the -b switch. The resulting pixmap will be written to your desktop's root window. The results under KDE weren't great, but everything worked beautifully under Window Maker. As they say, mes amis, the mileage, it varies, non?

Creating virtual landscapes is just one of the many applications of creating art with fractals. If you would rather just get in there and start generating a little eye candy, you may not need to install any software whatsoever. Most Linux distributions come with a package called xscreensaver that includes a collection of, well, screensavers. What you may not know is that each screensaver is a program unto itself with its own capabilities. For instance, drift is a program for drawing recursive fractal flames. It can be called from the xscreensaver program or directly, like this:

/usr/X11R6/lib/xscreensaver/drift -background "Wheat"

This will open a window with drift endlessly generating fractal flames on a wheat-colored background. The default is black but you can play with the colors. If you would like a larger window, (for instance, 800 × 600) try adding the -geometry 800x600 flag. Remember that talk about the root window when we discussed xmountains? As far as window managers go, the same rule applies here, but you certainly can launch the program to generate dynamic art on your desktop with the -root flag:

/usr/X11R6/lib/xscreensaver/drift -root
Do you long for the call of nature? A little joke, mes amis. Perhaps mountains are not your thing but, rather, the untamed beauty of the forest. Maybe a little window in the corner of your desktop is in order—try forest from the same package. The path to the executable will vary depending on your installation. On my test system, these all live under /usr/X11R6/lib/xscreensaver.
forest -geometry 300x200
When you are tired of this, try hopalong and experiment with fractal planes. You might also call up julia for some animated julia set fractals. What is that, you ask? Well, according to the documentation, the program “uses ifs {w0 = sqrt(x-c), w1 = -sqrt(x-c)} with random iteration to plot the julia set, and sinusoidally varied parameters for the set, and plots parameters with a circle.” (Aren't you glad you asked?) To round out the xscreensaver offerings for today, consider one of my personal favorites, imsmap. Figure 2 offers a view of my rather busy desktop with many of these programs running simultaneously.

Figure 2. Fractals, as far as the eye candy can see.

Your Linux system is a treasure trove of programs when it comes to creating virtual landscapes of surrealistic art. Another package that was likely installed as part of your distribution is netpbm or netpbm-progs. As part of that package, you'll find a program called pgmcrater that will create a cratered terrain using fractals, so that you end up with a virtual lunar landscape (as in Figure 3). Try this:

pgmcrater -x 800 -y 600 > crater.out
convert crater.out crater.jpg

The second command is part of the ImageMagick toolset. The pgmcrater program generates images in a raw portable graphics format that gets dumped to a temporary file. I then convert the raw image into a JPEG, a format I can use to set a background image for my desktop. Incidentally, we could make those two commands into one with the following:

pgmcrater -x 800 -y 600 | convert - crater.jpg
<center>

Figure 3. Is it the moon or pgmcrater

Before we move away from netpbm-progs, let's look at one more program, and one I am particularly fond of, ppmforge. This program generates “fractal forgeries” (a term coined by Richard F. Voss) of planets, starry skies and clouds. The images are incredibly realistic (as real as a computer-generated planet can be) and make for beautiful artwork. The program allows you to specify the amount of glacial formation (based on terrain altitude), the angle of tilt for your planet (in relation to the planet's star), the amount of polar ice and the time of day (which changes the position of the day/night meridian). Here's a sample:
ppmforge -hour 10.5 -glaciers .5 -tilt 23.5 -ice .5
-width 800 -height 600 -stars 70 | display -
<center>

Figure 4. Strange, new worlds are yours to create!

Figure 4 is a snapshot of one of my generated worlds. The resulting image is being piped through to ImageMagick's display program rather than converting it to a fixed image each time. I can then right click on the image and choose to save it in whatever format I desire.

For those of you who are fans of backgrounds comprised of blue sky dotted with clouds, ppmforge does the trick as well. Try this version of the command:

ppmforge -clouds -width 800 -height 600 | display -

As you can see, inspiration is as close as your desktop. François, our guests are thirsty. Please, more wine.

One of your humble chef's favorite movies is Bladerunner, based on Philip K. Dick's novel Do Androids Dream of Electric Sheep?, a fascinating picture of reality if ever there was one. Dick's novel is the inspiration for our next encounter with alternative reality, Scott Drave's electric sheep. When you are lost for inspiration, pull your hands away from the keyboard, wait for this fascinating screensaver to kick in and prepare for a little electronic dreaming.

Here is the premise: when the screensaver starts, your screen will blank for a moment as the program connects to the server. Then, an animated “sheep” will appear. This sheep is actually an animated fractal frame created by the collaborative processing efforts of networked clients. New sheep (the resulting animation) are created every 15 minutes, 24 hours a day. It's hard to say that this is as useful as the Seti@HOME Project (another part of electric sheep's inspiration), but it is certainly very cool, non?

The nature of the high-resolution animations generated pretty much demands some kind of high-speed internet connection; a 56K modem may not be sufficient. If you are hungry to try it, may I recommend that you begin with a visit to electricsheep.org for your copy. Then, extract and build it like this:

tar -xzvf electricsheep-2.1.tar.gz.html
cd electricsheep-2.1
./configure
make
su -c "make install"

You can start the program and test it without going into screensaver mode by simply typing electricsheep. In this mode, it will occupy the root window background, so you may have to minimize your active windows. You can also pass the --help flag for a list of options. To use it as a screensaver with the xscreensaver package, modify (or create) your .xscreensaver file with electric sheep listed as one of the programs. In the following example, I have also set my screensaver timeout to two minutes:

timeout:           0:02:00
lock:                True
lockTimeout:    0:02:00
programs: \
   electricsheep --nick "ChefMarcel"   \n
Then, start up xscreensaver with the command xscreensaver -nosplah & and wait. Figure 5 shows off one of the many sheep that appeared on your humble chef's screen.

Figure 5. Does your Linux system dream of electric sheep?

Speaking of dreams, mes amis, the hour grows late and we must soon close the restaurant. In order to help you sleep more comfortably tonight, François will refill your glasses a final time. François, s'il vous plaît. As usual, your visit to Chez Marcel has been a real pleasure. Dare I say dreamy? Non.

Finish your wine. Enjoy. Until next month. A votre santé! Bon appétit!

Resources

Marcel Gagné (mggagne@salmar.com) is president of Salmar Consulting Inc., a systems integration and network consulting firm and the author of Linux System Administration: A User's Guide, published by Addison-Wesley.

LJ Archive