Mapping the terrain
About 5 years ago I came across a very interesting account on "The Cesspit formerly known as Twitter" which posted a random map every day. I was intrigued by how they were created, and discovered that it was all on GitHub.
As a former table-top roleplayer who has many friends who still game regularly (some of whom also who have kids who might like personalised treasure maps), that started me wondering if I could make my own maps, but with different visual themes...
I started picking the code apart and trying to get my head round the maths behind it, with varying degrees of success.
I did manage to create a slightly updated map generator that spat out a more "fantasy-looking" map style, replete with parchment effect background, but it never quite felt right (let alone "complete").
I tinkered with it a bit in 2021, came back to it in 2024 to customise the UI, add PNG export, as well as edit, delete, click and drag modes, new fonts, and SVG “wreck” markers, but never really got it to where I wanted it.
This week's experiment
Given that I have a bit of time on my hands at the minute, I decided to pick it up again, this time with some robotic arms to help me.
The basic idea was simple enough - make the UI a bit nicer and iron out some of the bugs, then maybe tweak the theming a bit... so obviously I went a bit bigger than that!
We can rebuild it...
I decided to fundamentally modernise and rebuild it, updating some of the dependencies and making some improvements that had been stalled since Martin O'Leary effectively mothballed it back in 2016.
I moved it from static HTML and JS to Vite with a core generation model that has no DOM dependencies and is fully seeded — the same seed gives the same map at any detail level, because each generation stage has its own random stream.
I upgraded to D3 v7 and d3-delaunay for the underlying maths, and improved performance by implementing typed arrays for the grid and heightmaps, a memory budget for undo, and redraws that only touch the layers that changed.
Make it pretty(ish)
Where the original was procedural and designed to show you how the maths behind it worked, I decided to focus more on the output, leaving the underlying grid, heightmap etc. as a secondary layer for exploration if the user is interested, but with the map as the primary focus.
I rebuilt it as a single editor with a top bar, tool strip, status bar and Build / Style / Advanced panels along with specific view modes for the map, heightmap, geological erosion, city positioning / scoring, and associated territories.
The tools were re-worked to be more friendly (and less buggy), with options to move any city, label, point of interest or embellishment, edit text in place, add new text and markers (X, Danger, Flag, Camp, Landmark), and delete, all with keyboard shortcuts and the ever-useful "undo" function and a history panel with replay and undo/redo that says what each step did.
Now make it bigger and better!
The original map was square, so I added A4 options in landscape and portrait orientation, figuring that people might want to print maps out (plus I have an embryonic plan to build a pen plotter from the guts of a couple of old all-in-one printer/scanners, and maybe have it draw out a randomly generated map each day - more on that if/when it happens!).
I thought it would be handy to be able to save and share maps, so I added autosave, share links and a “map of the day”.
Maps can be pretty basic, or they can be highly detailed and embellished, so I added some more features, each of which can be toggled on and off as desired:
- Grid lines (square or hex)
- A scale bar
- A compass rose that can be scaled up or down
- A title box that fits and wraps its text
- Wrecks and points of interest that can be placed by hand, plus a colour per marker
- Mountain, hill and forest symbols, with hills and forests as separate layers
- Roads and routes, with the option to re-draw the roads automatically if you move any of the towns and cities around
- A legend (map key, not me...)
- Label placement that avoids clashes and keeps region names on their own land
What's in a name?
One of the things that I liked most about Martin's original was the pseudo-language construction used for the labelling of the maps, but that was originally randomised, which I found a bit annoying.
I decided to expand those phoneme-based label generators with some additional choices, grouped into “Language-like” and “Name lists”, as well as town names generated from word lists that suit where the town sits geographically (e.g. no "Port" or "Quay" place names halfway up a mountain).
I added some distinct groupings for Pirate maps, Military codenames, Tolkien-inspired Shire names, and slightly GOT-ish Kingdom names.
Variations on a theme
Map themes are built as plain data - each one bundles and embeds its own fonts, and a change to one theme never affects another.
I steadily built out a number of different themes:
- Simple: the default, staying close to Martin's original work
- Fantasy: my original tweaks to look and feel
- Plotter: strokes only, single-stroke Hershey lettering
- Pirate: sea shading along the coast and blackletter fonts
- Military: stencil type and military styling
- Underhill: Tolkien-style mountains, smoothed coasts, rugged hills and forests
- Throne-ish: regions with watercolour-esque painted tints, castles, engraved mountains, hachures, and hand-drawn mixed woodlands
- Coloured relief: a more modern rendered map with land and sea filled and coloured by height
- Surveyor: contour lines and woodland areas inspired by UK OS maps
- Illuminated atlas: coloured like a Dutch or French atlas of around 1700, with a graticule on the frame
Each theme has configurable typography rules that set font, size, case and spacing for each kind of text.
Getting it done
So far it has taken around 80 commits and 24 PRs, plus a roadmap, a CLAUDE.md and a test suite, all using my AI-enhanced development framework and done in the background over 4 days on a Claude Pro subscription.
It's deployed statically here on my website, in my steadily expanding experiments section, so why not take a look and have a play around?
What's next?
Well, it's in a good enough state to share for now — hence this blog post — but I definitely have some ideas for improvements:
- Wreck and point-of-interest drawings, and iconography — the wreck and point-of-interest markers are currently a bit crappy across themes, so I would like to make the symbols as good as possible.
- Several peoples / cultures on one map - a naming feature that any theme can use which enables different names per region, with each region (or group of regions) named in its own made-up language, e.g. elvish-sounding, dwarvish-sounding and human. The languages already exist — this would assign them per region and name the region's towns to match.
- Replaying how a map is made (the algorithm-explorer side) — stepping through the stages inside "New random map" could be improved, and the UI / tools there need some polish.
- 3D view and sculpting tools — sculpting would record brush strokes as steps, allowing you to carve your own world. I think that would be pretty cool!
- Magical world theme: points of interest for wizards' towers, portals, crystal formations, enchanted forests and floating islands, with optional glowing ley lines between magical sites.
- Relief rendering improvements for Fantasy and Pirate themes - they could use relief symbols or hachures rather than the original contour ticks.
- Pen-plotter output — on hold until the physical plotter build starts. This will cover clearing rivers and borders from under labels, ordering strokes to cut pen travel, and a physical paper size constraints.
- Measuring — a tool to calculate / show a route's length in the map's units (miles, km, leagues), shown while drawing and optionally on the map.
Caveats
- Sadly I'm no artist or illustrator, so this is the hardest bit for me to do directly or to act as Creative Director for my AI assistant on.
- It only really works on tablet / desktop screen sizes - smaller screens will get a blocking message rather than a broken experience for now.
- I haven't done extensive cross-browser or cross-device testing — this is a quick experiment / side project, not a product.
- All technology choices are somewhat opportunistic and geared towards rapid experimentation rather than being deeply opinionated - again, this is an experiment being approached via a product engineering mindset, not an actual product.
What do you think?
Give it a whirl and let me know how you get on - feel free to share any cool maps you create!
If you're interested in how it works, the code is on GitHub - bugs, issues, feature requests, and PRs are welcome.
