Late Christmas Gift: A Wallpaper Generator
This post and the software described in it were originally planned to be released before or on December 24th, but I didn’t manage to finish either. So consider my random wallpaper generator as a late christmas gift.
The idea for this program was born rather quickly: I wanted to have some nice and fancy desktop background images (»wallpapers«), and I wanted them to change every day. This is nothing new, I already did that in the past by writing scripts that choose one random image from a certain directory, scale them to fit on the screen and use them as wallpaper. This approach is simple and common; it’s supported by all major desktop enviroments now, if I remember correctly. However, it has two drawbacks: First, you need to update the pool of available images every now and then so it doesn’t get boring. Second, everyone who’s looking at your desktop (maybe because you do a presentation, or you want to show something, or you requested some help) will be distracted by the wallpaper. You’ll likely end up talking about the things that can be seen on the wallpaper rather than the real subject.
A proper solution for this is having a generator that procedurally creates random images that are suitable as background images – that is, nice, soothing images that don’t distract too much. Basically the kind of background images that shipped as default in Ubuntu up to 7.10 and Mac OS X up to 10.4. My program is trying to do exactly that.
Here are some example images from the generator (click on them to get a full 2048×1536 preview):
As you can see, there are only few basic elements: Gradients and large circles that partly cover the screen. All this is driven by a random number generator and rendered in not-too-bright colors into an image file. On current computers, this takes approximately one second of time per megapixel.
The implementation is done in a single ~350-line C file in platform-independent floating-point code. Output is written to BMP files using Floyd-Steinberg error diffusion dithering. (Dithering is necessary because for the very smooth gradients generated by the algorithm, banding becomes obvious even on 8-bit displays.) The program can be compiled into two different versions: The first one is a generic command-line program that takes the output file name, the desired image size and optionally a random seed as parameters. The second one is specific to Win32: It automatically detects the image size (using the resolution of the largest attached monitor) and immediately sets the generated file as desktop wallpaper. This version can simply be put into Windows’ Autostart folder to generate a new wallpaper every time the computer boots up. Or it can be triggered periodically using Windows’ Task Scheduler.
The download archive contains the source code as well as compiled versions for 32-bit Linux and the Win32 special version. Both of these require a SSE-capable CPU. A small example script of how to use the command-line version for KDE desktops is also included:
- makeback-1.01.tgz (59k)
I’m afraid the Win32 version is quite large – it’s 49k. This is because I was forced to include Microsoft’s huge C runtime library (CRT) in the build: Without the CRT, the
pow() function can’t be used. If anybody knows how to include the math library of the CRT only (without all the I/O and heap management stuff) or knows of a nice assembler implementation of
pow() (for 0 <=
base <= 1 and
exponent > 0), I’d be very interested.
Also, if someone has any questions or suggestions about the program, I’d like to hear them. I might also post a detailed algorithm description if someone is interested in it.