ZX Spectrum Filter Revisited

Well, a day is a long time in Free Software. Since I posted yesterday about the ZX Spectrum filter for The GIMP, I’ve had a lovely exchange of e-mails with the original author nitrofurano, I’ve improved the filter further and I’ve found out why it was written.

Spectral Spectrum

First things first, improving the filter. I had become rather rusty at working on filters for The GIMP but eventually everything came flooding back to me.

The first thing that helps when writing a Python filter in The GIMP is to run The GIMP from the command line in a terminal window. That way you get to see all the error messages the plug-in produces and are not working “blind”. You can also see the output of any print statements you add to help you debug.

The second thing I remembered was that you should use a symbolic link to the filter in The GIMP’s plug-in folder, so you can work somewhere more convenient than a hidden folder that’s several levels down.

Sugary Spectrum – click to enlarge

Once I’d got myself working sensibly I could have a look at improving the filter. The first thing I did was to speed the filter using this technique described in Akkana‘s blog.  It cuts down on writing to the actual image, which is slow. Instead you copy the image to a byte array, work with that and then copy all the bytes back to the image when you have finished. Using Akkana’s technique had the added bonus of allowing the filter to be adapted easily work with either RGB or RGBA images.

However, the resulting changes didn’t seem to generate the desired increase in speed until I realised I had stupidly queried the image class’ size and width repeatedly instead of storing the values in variables. Once I did that the filter literally flew.

Nitrofurano (Paulo Silva) has been lovely and very encouraging as I’ve been hacking his lovely code to bits. He’s also as enthusiastic about free software as I am. I think it’s fantastic that people who have never met before can work on each other’s software, share ideas and get to know each other – the GPL really does work as advertised.

Sinclair TV – thanks to Nitrofurano

The reason the code was written originally was to be part of a very interesting project Paulo is working on to create “retro” vision web-cams. You can find out more about it here.

You can download the updated python-fu ZX Spectrum filter for The GIMP here.

ClapTraps v1.1

You might remember that in April I blogged about the computer game ClapTraps, which was written by my friend testpilotmonkey. ClapTraps is a fiendishly addictive puzzle game written in Python using the PyGame SDL library.

ClapTraps v1.1 –  reworked title screen

Back in May I also blogged about my Inkscape reworking of the graphics for the game.

ClapTraps v1.1 – reworked graphics

Since then testpilotmonkey has released a new, expanded version of the game – ClapTraps v1.1. It includes my reworked graphics and a number of new features.

For instance, you can now redefine the control keys. This is very useful if you, like me, have a Hungarian keyboard!

Even better, people who can code in Python can easily change the behaviour the game objects, just as you can in Repton Infinity. To demonstrate this, ClapTraps comes with a XOR-style came called Arrows which has the potential to be very interesting indeed.

Arrows – a real head scratcher

Despite my best efforts to recommend the game to everyone I know, ClapTraps has been largely ignored, even by fans of Repton. I think this is inexplicable and a crying shame. It’s an absolutely fantastic puzzle game and has given me and my daughters a lot of fun. It’s free as in beer and free as in freedom so there is no reason not to download it and have a go – and let testpilotmonkey know what you think too!

It is available to download for Windows, GNU/Linux and OS X here.

NB for GNU/Linux users: I found I couldn’t run the ClapTraps code by double clicking on the main ClapTraps.py icon from Nautilus, the GNOME file browsing program. After much experimentation I found the problem was simply that ClapTraps.py was corrupted in some way. If you copy and paste its contents into a new file it will work correctly. The copy and pasted file will be 2K shorter than the original, but work perfectly.

Dave Dunce Goes Gloss

At the end of April, I blogged about Claptraps – my friend testpilotmonkey‘s new computer game. Claptraps is a fiendishly addictive puzzle game written in Python using the PyGame SDL library.

I also noted at the time that Claptraps was a piece of free software – testpilotmonkey released it using Free Software Foundation’s General Public Licence or GPL. This means that anyone is free to study or modify the source code and send copies of the game to their friends.

I felt that releasing something as fantastic as Claptraps under the GPL was an act of generosity that should not go unrewarded. As I don’t have any money, I decided to donate some of my time instead.

The place I felt best able to help out was the graphics. Claptraps is a tile based game, with 40 x 40 pixel tiles which are stored as 32-bit Portable Network Graphics (PNG) files. testpilotmonkey had decided on a cartoon look for his graphics, with flat fills bounded by black outlines. Here is a screenshot of the game with the testpilotmonkey’s original graphics:

Original graphics – Click to enlarge

I love these graphics, as they have bags of character and the animation is very pleasantly squishy and organic. But I thought it might be nice to take these graphics and see if I could make them a bit three-dimensional. To do this I decided to use a piece of free software called Inkscape. The reason I decided to use Inkscape, as opposed to a raster graphics package like The GIMP, was I felt cartoon-ish nature of the graphics lent themselves to be created in vector format. It also meant I could create one set of graphics that could be used at any size.

I made my canvas 40 x 40 pixels in Inkscape, for convenience. As far as guides were concerned, I just used two, one half way vertically and one half way horizontally which marked out the centre of the canvas for me. I imported the original graphics into Inkscape and used the Pen tool to trace over them. For each graphic, I created a separate Inkscape SVG (Scalable Vector Graphics) file.

As I was creating vectors to export to (rather small) bitmaps, there were a couple things I needed to bear in mind when tracing the original graphics to ensure good results. The first thing was I wasn’t free to put black outlines anywhere I chose. The end result would be rather grey and muddy due to too much anti-aliasing being used on the exported bitmaps. To keep anti-aliasing to a minimum (and hence keep the graphics as clear and colourful as possible) I needed to ensure that the nodes for my lines and Bezier curves were on half pixel boundaries. The second was to ensure that all my outlines had a one pixel stroke width, and were completely black – sounds obvious, but easy to mess up.

One traced frog – click to enlarge

Once I had an outline for a graphic it was time to colour it in, and again it was Nancy Kominsky to the rescue. I used her technique of using three tones – light, medium and dark to fill each shape. Then, if necessary I’d add any highlights with light yellow and any lowlights with dark purple. The nice thing about Painting Along with Nancy in Inkscape is I don’t have to put my spare colours into the fridge and cover them with cling film.

Incidentally, in case you think I’m joking about following Nancy Kominsky’s advice, here’s the Claptraps apple filled using a radial fill made up of my three tones – light, medium and dark red:

Where’s the light coming from Alan?

And here are my three tones I used in the gradient fill editor :

Cadmium orange, vermilion and alizarin crimson

Here is my purple lowlight and my lemon yellow and white highlight:

That’s one teaspoon of purple, the colour…

And here is the finished apple – Nancy Style.

And no need to apply any varnish

And, just for you to compare, here are Nancy’s apples:

Picture courtesy Rory Clark

So, after much colouring in but, sadly, no Alan Taylor to chat to while I was working, I had a finished set of graphics:

As seen in Fedora 13 Nautilus

And here are the finished graphics in place in the game:

Click to Enlarge

I was determined when working on the graphics that my input be as invisible as possible – Claptraps has bags of testpilotmonkey’s character and I wanted to keep that. The graphics remain very much testpilotmonkey’s, just coloured in slightly differently.

After showing testpilotmonkey my graphics, he said he’d like to use them in future releases of the games – which was very kind of him and made all the effort worthwhile. I’m hoping to spend more time on Claptraps and to return to it on this blog soon. In the meantime, why don’t you download the game and have a play? You can get hold of it here.

From Claptrap to Claptraps

Normally I use this blog to drone on about my own claptrap. However, today I’d like to use it to have a look at a friend’s.

Level 1 – It’s all uphill from here…

To be more precise, a computer puzzle game called Claptraps, written by “testpilotmonkey“. It’s one of the most joyfully bonkers and imaginative games I’ve ever played – the sort of thing Oliver Postgate would have come up with if he’d have been given a book about scripting languages.

The game itself was written in the language Python with the help of the wonderful PyGame SDL library.  If you’ve ever want to write a computer game for GNU/Linux, Windows, or Mac OS this combination is the place to start and indeed Claptraps will work beautifully on all three of these platforms and doubtless several more besides.

I think this game is really rather special for lots of reasons:

  • it is released under the Free Software Foundation‘s General Public Licence or GPL. That in itself is a marvellous and selfless thing to do, particularly when you consider how much hard work has gone into the game.
  • the quality of the music testpilotmonkey has composed to include in the game – I really enjoy listening to it.
  • the graphics, which have a wonderful cut-out animation feel
  • and, most of all, the standard of the puzzles. The game design is incredibly clever and the puzzles are fiendish but solvable with thought. That makes it one of the most rewarding games I’ve ever played.

I could talk about the game at length here, but why not download it yourself from testpilotmonkey’s blog?

The game has come on in leaps and bounds since this video was made of an early demo version, but it’s worth a look:

The gameplay is loosely inspired by the games in the Repton Infinity suite with dashes of Bonecruncher and XOR. However it has a personality all of its own, something which you don’t get in modern games written by huge teams.

I’m hoping to do some work of my own on Claptraps if I get the chance over the coming weeks – in true GPL spirit I’ve been studying and modifying bits and bobs already which I hope to start sharing soon. The code is very, very clearly written and I’m looking forward to having a proper dabble with it enormously.

NB: As the game is still a work in progress, GNU/Linux users may find they need to append two lines to ClapTraps.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

Also, don’t forget to right click on the Claptraps.py in the file browser, and go to PropertiesPermissions and check the Execute check box to Allow Executing File as Program. You’ll also need to make sure you have the pygame package installed on your computer – but if you’ve installed GNU/Linux in the first place I’m sure you can manage this.

Windows users can just click on the .exe. I know nothing at all about Apples apart from the fact that Granny Smiths are my favourite and my mother’s bramley crumble with custard is delicious.