This is a neat little algorithm for generating
landscapes for video games, movies, screen savers
and the like.

Say we start with a line segment AB like
this:

A ***
***
***
***
***
***
*** B

This line should be going in the direction which
we eventually want the

landscape to be going in.

Now, we add point C and split this segment into
smaller segments AC and BC. C is located horizontally
midway between points A and B, like so:

Ax + Bx
Cx = -------
2

and Cy is given by this formula:

Ay + By
Cy = ------- + (Ay - By) rand(r)
2

where rand(a) is a

function returning a

random
number between -a and a

inclusive, and r is a

number
between 0 and .5 determining the "roughness" of the

landscape.

Now our landscape looks something like
this:

A *****
*****
***
C **
**
**
** B

Now, AC is split into AD and DC, while CB is split into
CE and EB, and the same calculations are performed. We
end up with something maybe like this:

A ***
***** C
D ***
**** E
***
*
** B

Trust me, this looks a lot better when it's not

ASCII art.

And so on and so forth this continues,
until your landscape is as pretty as you want it to be!

This same technique can be applied to
three-dimensional landscapes, too. I'm not sure of any
standard method, but a plausible one would be
to split one triangle into three by adding a point as
described above:

A
*
* *
* *
* *
* *
* *
* *
B *************** C

Now we add D.

A
*
***
* * *
* * *
* D *
* ** ** *
* ** ** *
B *************** C

It now becomes very difficult to exemplify this
method, seeing as 3D ASCII art is an as-of-yet unexplored
frontier. But you get the picture.

pfft informs me that a more standard method is to split each triangle into *four* small triangles, by adding three new points:

A
*
* *
* *
D ******* E
** **
* * * *
* * * *
B *************** C
F

This seems to make an

infinite amount more sense than my method, since now the

triangles don't get all squishy. Thanks,

pfft!