libhex v0.1.0

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]

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.

Comment · Comments Feed · TrackBack

  1. Felix said,

    5 March, 2013 @ 09:49

    Hi, I am having difficulties using your Javascript hex.js library. Could you maybe point me into the right direction of how to use it? I didn’t find any code examples anywhere and I was up to now unable to figure my way out reading the source… I want to draw a hexgrid on a html5 canvas… but any other example using hex.js would be helpful for a start.

    I would really appreciate your help, because this is the only library for hexgrids in javascript I have found so far and I was really happy that someone managed to write one! :)

    Best regards, Felix

  2. Philipp Meier said,

    29 November, 2013 @ 01:17

    Is this project still alive? I want to port it to QT5.

Leave a Comment

Sponsors