**fault algorithm**

v0.1; caminoix; 30.06.2006

v0.2; caminoix; 10.07.2006

v0.3; caminoix; 27.08.2006

download source | binary

the idea behind the fault algorithm is pretty simple. you divide the map with a random line in two parts. then you elevate one part, and lower the other. repeat a few hundred times, smooth it, and there you go with a very nice looking heightmap.

the one thing you could be more interested in are the implementation details. sure, line drawing algortihms are available in lots of places on the web but the thing is that you don't really need to mess with that. just take a look at how it's done here (this isn't exactly my implementation. i found it on the web a long time ago and only modified it a bit and translated to nemerle. i'm very sorry but i couldn't find it now again to credit the author.):

`repeat (sLines){`

def x1=r.Next(sizeX); def y1=r.Next(sizeY);

def x2=r.Next(sizeX); def y2=r.Next(sizeY);

for (mutable x=0; x<sizeX; x++) for (mutable y=0; y<sizeY; y++)

if ((x2-x1)*(y-y1)-(y2-y1)*(x-x1)>0)

map[x,y]+=sDispl

else map[x,y]-=sDispl;

}

where

`sLines`

is the number of lines, and `sDispl`

is the displacement factor.