Eventually, I'd like to get to a place where I'm generating multiple fake "countries" on a fake "continent," but to start I boiled the problem down into something simple, and I'm already stuck at this first step:
Given an area (let's say 10 tiles x 10 tiles) and a number of polygons (let's say 6), I'm looking for a way to randomly give the polygons tile coordinates in a way that 6 polygons of approximately equal size (+/- 10% is fine, and honestly even planned) will fill up the entirety of the grid. Not the precise code per se, but even how I'd go about doing it on paper.
I've also thought about using a spiral. Starting from the approximate centre of the area (let's say [4, 4]), spiral around clockwise and cut off at 100 / 6 = ~16. While this seems like a really straight-forward approach, both on paper and in code, it certainly makes for weird-looking polygons:
And no matter how much I tweak some random variables (e.g., size of polygon, where I start, etc), it'll always look like that. In a variation, starting at the bottom left point and going up, then right, then down, then right, etc., yields the same:
To create something vaguely realistic, I'm thinking that I need to generate 6 centroids across my [10, 10] area, and then use the spiral method to create regions from that.
I find myself pretty quickly running into three problems:
- How do I "equally space" out the centroids?
- How do I handle the "overlap" areas, like shown with the ?s or ?!s (for the second pass-through)
- How do I handle the "gap" areas, like shown with the letter G above?
And finally... is this centroid approach even the best method? I've heard of (and used, via 'clicking a button') k-means clustering... would it work to theoretically set my 100 points as input points and try to generate 6 clusters?
Any help would of course be much appreciated!