Archive for December, 2012

As I continue to translate Amit’s actionscript to javascript, it is becoming increasingly obvious that I’m missing a crucial part of this codebase- the actual voronoi diagram. Since this is a level of math that is beyond my ability, I’m going to cheat and find another implementation. Raymond Hill has a demo and a nice MIT-licensed library that may be exactly what I need.

After I examine the API, perhaps I can figure out how much the map.js will need to change to use that, if they’re even compatible. I also need to figure out which conceptual primitives I will need. In the meantime I’ve gone through most of the map.js and translated the skeleton of it to javascript. It’s not very useful, but it’s something.

So I have two ways to go about implementing this- read through Amit’s actionscript and try to implement it in java, or read though his article and randomly mishmash internet code together to get a working prototype. While it’s tempting to just swipe other people’s code, that won’t help me understand how it works.

There we go. So pretty. The next step (I think) is to come up with an object to represent the map; While the canvas is pretty, it’s just output. Amit seems to have done exactly this with Map.as. Do I try a full blown reimplementation of his code without understanding it, or do I aim for a skeleton that can output to the canvas, and the build up from there? For now, I think I’ll get more out of the latter. I’ll start with a simple map.js and try to port over the basic functionality. I’m not sure how successful this will actually be seeing as how he uses external libraries, which I will either need to emulate (no chance) or find a similar js version (slim chance).

Adding to the complexity is my lack of js-fu; I feel like someone who kind of knows Spanish trying to translate a Portuguese document to find out where Vasco De Gama hid his gold.

I’m currently in the process of stepping through the actionscript and replacing individual methods with javascript, while at the same time comprehending how they work. It’s a lot of effort; I’ve been at it for well over an hour and I’m only 9% complete. I need to take a break.

I’ve been working on my CityGenerator off and on for years; it’s finally reached a point where I’m content with it’s output and I want to move to the next level. I’d like to start generating an entire continent, then populating it with my CityGenerator. So, step 1- figure out how to generate an awesome map. I’ve tried a couple of things, including my last couple of posts on using gimp, but that won’t work for the city generator- I need something that can scale reasonably well.

So there are two parts to this problem; figuring out how to do it, and how to implement it. Fortunately, someone named Amit has already figured out and documented it magnificently. While I think his method isn’t perfect, I completely understand the design decisions he makes and would probably take the same shortcuts he has taken (specifically ensuring that there are no local minima to ease the creation of lakes and rivers).

Amit is a smart guy that makes me feel very dumb. Reading through his full article makes my head spin. The main problem with his awesome code is that it’s written in flash/actionscript, which makes it semi-useless to me (I have no flash development tools nor an inclination to get tied up in a now-dying proprietary pile of poo). This leads directly into my next problem- How do I implement it?

Like Amit’s code, my best bet on this is to refrain from doing this on the server side- the perlin noise algorithm can be fairly hefty, and under load would crush my dinky server- it would be better to have the clients do the heavy lifting if possible. That leaves me with one viable option- javascript. A combination of javascript and html5 canvas should do the trick nicely (this is also what I use to generate my city flags).

So, with the proper tools and directions written in another language, all that’s left is to interpret Amit’s code and method, then implement it. Hopefully this will be the first article of many on my progress, and I won’t just give up in frustration.

If you want nice, boring land, you can color this with the technique below and be done. Otherwise we should spice it up a bit.

With your landmasses selected

Create a new layer

Click on the land layer and color select the land

Use Filter->render->cloud->solid noise with the following settings:

random seed 2925538520 (note that this is different)

detail 15

turbulent

x,y= 6.0,6.0 (note that this is different)

Select colors->levels and click auto, then OK

Set this new layer’s mode to hard light

Merge down

Perfect! Now your land still roughly matches the patterns of the original solid noise, but has a flavor of something new as well. Now lets colorize this badboy Here’s a simple gradient that I made called Terrain.ggr. It can be dropped into your gimp-2.8/gradient directory.