Date

I've just uploaded the first draft version of libhex, my library for manipulating and drawing hexagonal grids. It's available in C++, Python and JavaScript.

[docs, source, examples: C++, Python, SVG]

image0

The library comes in two parts. First, there's a geometry section, which describes abstract models of Hexes, Areas, Paths and Boundaries. This is complete and ready to use. Secondly there's an SVG section, that contains utilities for rendering the geometry objects into SVG. I'm a little less-sure about the interface to this section. Nevertheless, it's still perfectly functional.

Hopefully this will enable me to write that web-game, the next time the urge strikes me. What web-game? Well, I keep getting ideas for little online games that would use a hex grid. I've started writing more than one, but always given up really quickly. The mechanics of the hex-grid aren't as simple as they look, and when I'm all fired up about writing a game I don't have the patience to fiddle with sixfold geometry. But sadly, a bit of fiddling is required.

This time when I got the urge to write a little web-game, I stopped myself. I realised that I wouldn't get anywhere because I needed a library of hex-routines. Google turned up nothing, so I decided to put all that energy into writing the library. The next time I get the urge, this library will be ready and waiting.

Still to do

I've translated all of the geometry code into JavaScript. That will be needed by even the simplest web frontend, just to convert click-coordinates into a hex ID, for example. The SVG-imaging code is a different matter though. It would be nice to use client-side JavaScript to manipulate an SVG image directly. However, browser support for SVG is poor, so would that be worthwhile? I've got a little proof-of-concept application, but nothing complete.

I've used SWIG to translate the C++ interface into Python. I'm not sure that's such a good idea, because it makes deployment a real pain. It would be great if someone who knows about deploying Python packages could help me out here. Failing that, I suppose that I could implement the whole lot in pure-Python. Once the algorithms are correct, it's just legwork to translate it into a different language. I'm reluctant though, because it will be difficult to keep all those versions in synch.

So, please, please try out libhex. Let me know how you get on.