Archive for February, 2008

libhex v0.2.0

I’ve just uploaded a new 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]

I’ve redesigned the SVG output interface. The crazy templates are gone. It’s now just a set of simple functions. SVG output is no longer flipped either, so it’s easier to add text.

I’ve also added routing algorithms: find best path, find movement horizon given a movement budget. Using the library for a game, you need to know where a piece can move. The hex::move namespace defines a “Topography” class which enables you to model movement costs within the grid. Then it will calculate the best path from one hex to another, or tell you how far a piece can get with a given movement budget.

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

Comments (4)

A hex map of England!

I’ve been using (and testing) my new hex-map library. Here’s a map of England.

Hex map of England

It was generated by a little program that uses NASA’s SRTM data as input. The light brown hills are just high ground, but the dark brown hexes are both high and hilly – my program samples the elevation, and calls a hex hilly when the elevation’s standard deviation rises above a set limit. The rivers are drawn by selecting sample locations and then finding an optimal route to the sea. The routing is done with something like Dijkstra’s algorithm – it mostly wants to go downhill, but will jump over small rises if necessary to get to the sea.

The rivers look plausible, but there are quite a few problems, if you look closely. For example the Welsh headwaters of the Severn flow North into the Mersey on this map, but in real life they turn South.

Anyway, the map looks pretty good. It’s certainly good enough to form the playing surface for my online game (don’t ask). Writing the program was way more interesting than generating maps by hand. I only found a single bug in libhex, which is heartening.

Comments (5)