IOCCC image by Matt Zucker

The International Obfuscated C Code Contest

2006/sloane - Homer's favorite

Animated donut

Author:

To build:

    make alt

We recommend the alt version so that you can see what this looked like back in 2006. If you wish to see the original faster version see Original code below.

To use:

    ./slone.alt

Try:

The alternate version, which we recommend that you use in order to see what is happening with modern systems, and to not flash too quickly, which can be problematic for some people, can be configured to different speeds by way of the value used in usleep(). The default is 75000 but you can easily change it. To do so try:

    make clobber SLEEP=70000 clobber alt
    ./sloane.alt

If you wish to make it like the original, as if the below original code was being used, you can do:

    make SLEEP=0 clobber alt
    ./sloane.alt

Original code:

Should you wish to see the original you may do so with the original code, sloane.c.

Original build:

    make clobber all

Original use:

    ./sloane

WARNING: if you are easily overstimulated with fast movement or have photosensitivity please be careful running this version and instead see the above!

NOTE: again as above, to see what is going on, we recommend that you instead use the alternate code which we described in the To build and Try sections above.

Judges’ Comments:

Looks almost good enough to eat, dunnit? I suppose you could argue that, at first blush, this looks like a self-reproducing program.

Author’s remarks:

This program doesn’t require any special build options, other than that it uses sin(3) and cos(3) and hence requires the math library.

You will almost certainly get a compiler warning because I declared a bunch of global ints without types. The code looks better this way, though, I think. There are also no #includes, so there may be warnings for undeclared references to printf(3), etc. There’s a chance that my failure to include math.h or declare sin(3) or cos(3) will make the donut not render properly – it’s worked on every system I’ve tried so far though.

You will need some kind of VT100-ish emulation; so while this compiles and runs OK in Windows, you will need PuTTYcyg or something like that.

The shape of the source gives a hint about its output: it’s a little animation of a shaded donut rotating over an infinite checkerboard. Like many IOCCC entries, it is thus self-documenting.

I wanted to create something as “pure” as I could - meaning that the entire source code is shaped into a work of art, without being prefixed by any #define hacks, or even #includes, and is portable enough to not require any special libraries to do the animating. I achieved this with two standard escape codes for clearing the screen and moving the cursor back to the top-left.

The donut isn’t raytraced. It’s much simpler than that.

How is it obfuscated?

There are three main pieces to this program: the donut, the checkerboard, and the ASCII logo. The first two are programmed in a straightforward way (with z-buffering even!), but the mathematics for drawing them is “optimized”. The ASCII logo has been shrunk into the smallest I could make it by any means necessary.

The logo can actually be compressed much better (ironically, by doing something simpler), but I didn’t discover this until well after submitting.

Puzzles

In increasing order of difficulty:

Inventory for 2006/sloane

Primary files

Secondary files


Jump to: top