AllRGB - All the Colours of the 24-bit Rainbow

Posted by Tom on 2010-02-22 23:16

While surfing the intertubes recently I came across a link to allrgb (it was probably through proggit). The concept is simple and delicious, like good pasta. A 4096 by 4096 image with one pixel of each colour it is possible to represent in 24 bits - all 16,777,216 of them.

I like me a bit of eye-candy, and I'm enjoying the Python at the moment (after the brief false start), so I saw this as a good excuse to get my script on.

You can click on any of the below for a larger image. And when I say large I mean large. Only click on any of the below if you really, really mean it. The average image size is around 30MB.

If you've got an algorithmic eye you can probably infer what's being done in each of the examples above. To be honest all of this is pretty underwhelming compared to some of the submitted images. There's some frankly amazing stuff over there, and they've been getting progressively more awesome. Back before it became popular it was all nested loops, and I can follow it pretty easily. The best-fit image matching stuff I could have a stab at some algorithms. I even know what a Hilbert Curve is. But now? Now it just makes me feel uneducated. I have no idea what simulated annealing is, but it sure makes pretty pictures.

Anyhoo, here's the source used to generate my paltry efforts above. PNG functionality is provided by the sultry PyPNG, and apart from that there's nothing particularly special going on. I am still very much starting out, so this was a good way of cutting my teeth.

ZIP containing all the relevant bits

Caveat: The memory usage can get a little crazy. With 4GB in Windows 7 I have no problems. With 2GB in Windows XP there was some slight wackiness (where 'slight wackiness' can mean anything from heavy slowdown to so-boned-you-need-to-hard-reset). I got better results using arrays (which I understand are wrappers around C arrays, so pack a lot smaller) but left the code on another machine. Whoops. Also, I don't know what I'm doing in Python - so don't use this as an example of how to do it. As usual, The Disclaimer applies.

Increasingly traditional random link: Egads. If this isn't a harbinger of the eschaton then I don't know what is.