The 5k

This years entries are up at the5k.org. Unfortunately it looks like the efforts to shave off those last few bytes have meant an end to any cross-platformification. The current leader of the pack is an awesome windows IE only version of Wolfenstein 3D. This tiny, jerky little bitmap miracle has to be seen to be believed.

I'm not even sure how it's done, it appears to be redrawing a single graphic on the fly and the code looks like javascript. Some of the comments mention xpm and xbm, but googling for those doesn't turn up much other than that they're graphics formats. Can anyone satisfy my curiosity?

Update: I've put a slightly de-obfuscated version of the code here for anyone who wants a look, and click comments below for a little bit more detail on how it seems to be done.

2 comments

  • So, most of the ray-tracing engine is standard javascript by the looks of things, the only bit that seems unusual is the part that actually generates the graphic:

    function X(cz) {
    for(i in p) b[i]=N[cz?0:255-p[i]];
    z = "#define t_";
    im = z+"width "+W+"\n"+z+"height "+(H+8);
    im += "\nstatic char t_bits[] = {"+b.join(",")+"}";
    d.images[0].src = cz==2?"r.gif":"javascript:"+($x++)+";im;"
    }

    ie. It loads a red graphic on being hit, but otherwise it loads something like "javascript:123;im;" as the img src, where "im" is an raw bitmap definition of some sort.

    Posted by Anonymous on 28 Jun 2002 at 09:49 AM

  • I know nobody's really interested in this except me, but I'll post this anyway in case someone googles here looking for info. I found out a little bit more detail:

    The image is in XBM format (bitmap for the X windowing system and an early suggestion for a supported IMG tag filetype). The javascripting of this is not the IE only part. It's just that windows IE is one of the only common browsers that supports XBMs (curses!).
    The format is compression-free and can be defined in raw ASCII text. A basic example would be:

    #define t_width 4
    #define t_height 4
    static char t_bits[] = { 0xA5, 0xA5 }

    Which would display as a 4px*4px "grey" block of alternating black and white pixels. Each hexadecimal element of the array accounts for 8 bits or pixels, where 0x01 is the first of the eight and 0x80 is the last. More info here if you need it.

    It's a shame this isn't more widely supported, scripted manipulation of images would be a really nice thing to have available.

    Posted by Anonymous on 30 Jun 2002 at 12:49 PM

Add a comment
You must have Javascript enabled to add a comment.
  (optional)

Metadata