Tickd.ai
← The Tickd Guide

Inspiration

How to Generate Procedural Fantasy Maps as Raw SVGs Using Claude and Python

Ditch static, low-res image generators. Learn how to coax Claude into writing raw, beautifully styled vector code to render infinitely scalable fantasy maps.

Updated 9/23/2026

Most AI-generated fantasy maps are disappointing. If you ask a standard text-to-image model for a 'fantasy map of an island kingdom,' you will get a pretty but utterly useless JPEG. The labels will be gibberish, the coastlines will be blurry, and you cannot edit, scale, or parse the geography for an actual game or worldbuilding project.

But there is a better way. Instead of generating pixels, you can instruct LLMs to generate code. Specifically, raw, styled SVG (Scalable Vector Graphics).

Claude 3.5 Sonnet is shockingly good at understanding spatial geometry and writing clean XML. By wrapping Claude’s capabilities in a lightweight Python script, you can build a procedural generator that spits out infinitely scalable, crisp, and fully editable vector maps, complete with custom kingdoms, coastlines, mountain ranges, and legible text labels.

Here is how to build your own vector cartographer.

Why SVGs Beat Raster Images Every Time

SVG is not just an image format; it is a document. It contains structured code: <path> elements for coastlines, <circle> tags for cities, and <text> tags for place names.

Generating maps as SVGs ticks all the boxes for creative builders: Infinite Scalability:* You can zoom into a tiny port town without seeing a single pixel. Total Editability:* Want to move a mountain range or rename a city? Open the SVG file in Illustrator, Inkscape, or Figma and drag the element. Semantic Data:* Because the map is written in code, you can parse the SVG file to extract a list of all your city names, river coordinates, and regional boundaries.

While OpenAI's models are competent at code generation, Claude’s visual-spatial reasoning makes it the undisputed king of rendering complex vector shapes on a coordinate grid.

Step 1: The Prompt Architecture

If you simply ask Claude to "write an SVG of a fantasy map," it will panic, write fifty lines of code, and give up. You need to provide a strict grid structure, constraint parameters, and design guidelines.

We need to teach Claude to think like a cartographer laying down layers: 1. Background/Ocean: A warm, parchment-toned rectangular base. 2. Landmass: A complex, organic closed path with irregular bumps. 3. Topography: Grouped symbols representing mountains (triangles with shading) and forests (clusters of small humps). 4. Markers: Styled circles or towers representing castles and ruins. 5. Typography: Legible text elements placed carefully so they do not overlap icons.

Here is a prompt template to feed Claude via your Python script:

`text You are an expert cartographer and SVG developer. Generate a raw, valid, standalone SVG map of a fictional fantasy island.

Use a viewBox of "0 0 800 600".

Apply a vintage fantasy aesthetic: - Ocean background: #f2ebd9 - Landmass fill: #e6dfcb with a dark brown stroke (#4a3b32), stroke-width 2, and a rough, organic path representing a realistic coastline. - Include at least 3 distinct mountain ranges (drawn as overlapping open paths forming triangles with simple hatch shading). - Include 4 major cities marked with small red shield icons or castle shapes, labeled with fictional Norse-sounding names using a serif font style. - Include a compass rose in the top-right corner. - Include a scale bar in the bottom-left corner.

Return ONLY raw SVG code inside an xml code block. No explanations, no markdown wrapper around the SVG itself other than the xml block, and no HTML formatting. `

You can play with different visual styles and prompts in our Tickd prompt library to refine your thematic instructions.

Step 2: The Python Wrapper

To automate this process and generate a folder full of unique maps, you can use a simple Python script to call the Claude API, extract the SVG code, and write it to disk.

Make sure you have the official Anthropic SDK installed (pip install anthropic).

`python import os import re from anthropic import Anthropic

Initialize the client. Make sure your ANTHROPIC_API_KEY environment variable is set. client = Anthropic()

def generate_fantasy_map(prompt, output_filename="fantasy_map.svg"): print("Plotting coordinates with Claude...") response = client.messages.create( model="claude-3-5-sonnet-20241022", max_tokens=4000, temperature=0.7, system="You are an elite cartographic drafting machine that outputs only raw, valid SVG code.", messages=[ {"role": "user", "content": prompt} ] ) raw_text = response.content[0].text # Extract the SVG content from the code blocks svg_match = re.search(r'<svg.*?</svg>', raw_text, re.DOTALL) if svg_match: svg_code = svg_match.group(0) with open(output_filename, "w", encoding="utf-8") as f: f.write(svg_code) print(f"Success! Map written to {output_filename}") else: print("Failed to extract clean SVG. Printing raw response:") print(raw_text)

Run the generator user_prompt = "Generate a raw SVG map of 'The Broken Reach', an archipelago of 5 volcanic islands with sea monsters, winding shipping lanes, and ancient watchtowers." generate_fantasy_map(user_prompt, "archipelago.svg") ```

Step 3: Polish and Aesthetic Tricks

Once you have the basics down, you can push the visual fidelity of the generated SVGs much further. Here are some tricks to add to your system instructions: The SVG Filter Trick:* Instruct Claude to include a <filter id="paper-grain"> at the top of the SVG. By using <feTurbulence> and <feColorMatrix>, you can generate a realistic, organic paper texture overlay entirely in code—no external image assets required. Wavy Coastlines:* Tell Claude to use multiple nested layers for the landmass, each with a progressively larger, lighter stroke and a lower opacity. This mimics the hand-drawn 'shore wave' lines common in Renaissance-era cartography.

Handling Parser Meltdowns

Every now and then, Claude might lose track of a closed path or leave a dangling tag, causing your web browser or design tool to throw an XML parsing error. This usually happens when the model runs out of output tokens mid-generation.

To prevent this, make sure your prompt explicitly restricts the complexity to fit well within Claude’s token limits. Avoid asking for "one hundred individual islands" on a single canvas. If you do run into persistent rendering issues, refer to our Claude troubleshooting articles to learn how to structure your parser checks and output validation pipelines.

claudepythonsvgprocedural-generationcreative-code

Keep going

Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.