The Sinclair Spectrum font simulator

This one goes out on a whole new axis of pointlessness, but here it is:

I wrote a PHP version of this a long time ago, but it was kind of limited (and PHP sucks). So I've now rewritten it in python to be much more flexible. So what can it do?

Console version

./console_spectrum.py 1982 will generate this:

              OOOO          OOOOOOOO        OOOOOOOO        OOOOOOOO
            OO  OO        OO        OO    OO        OO    OO        OO
                OO        OO        OO      OOOOOOOO                OO
                OO          OOOOOOOOOO    OO        OO      OOOOOOOO
                OO                  OO    OO        OO    OO
            OOOOOOOOOO      OOOOOOOO        OOOOOOOO      OOOOOOOOOOOO

There's an option to use a different character to draw the thing, and that's about. It could really do with an option to specify a colour, too...

HTML table version

OK, so this is the good stuff. ./html_spectrum.py Sinclair will generate the HTML for this:

The -s (size) option lets us make a

or a

and the -c (colour) option lets us make a

So how does it work?

I managed to grub up the Spectrum character set as a list of bytes a long time ago from some kind soul on comp.sys.sinclair. The lines look like this:

a: [0, 0, 56, 4, 60, 68, 60, 0]

So we take the input string, then convert each of those numbers for each character into a byte that looks like this 00111000, and join them altogether so we end up with 8 long strings of 0s and 1s. Then we compress each of these strings using run length encoding, and the compressed strings lend themselves very well to rendering as HTML table cells via the colspan property. We need to add a row of single-span cells along the top or the spacing gets knackered. And that's about it. It generates a phenomenal amount of HTML, but never mind...

I will put together a demo page similar to the PHP one when I can work out the vagaries of mod_python importing.

The code is available on Github, although I've now reimplemented this as a Service.

Published under a Creative Commons Attribution-NonCommercial licence