Fractal Landscapes

Steve Criddle - February 2000

Click here to play with the program
(you need a Java-enabled browser, or you'll just get a blank page)

This is my first stab at writing a Java applet.  I have written this program in several different languages over the years, so it seemed like a good project with which to learn Java.  I'm quite pleased with the results.

Using the program

The controls probably don't need to be explained.  Simply type a number in the box and click Go!.  The program will generate a landscape based on that number.  Alternatively, click the Random button and the program will choose a number for you.

How it works

The landscape is on a 33x33 grid.  The program starts by setting the height of all four corners to zero.  Then it takes points halfway between the existing points, calculates the average of the points either side and adds a random amount to that.  Once it has done all four sides, it then calculates the centre point.

Having done that, it does the same thing at half the resolution (4 times), then again at half that resolution (16 times) and so on until every cell in the 33x33 grid has a number in it.

To draw the landscape, the program starts at the back and works forward (so the program doesn't have to worry about hidden lines).  For each sqaure the program calculates the average height of the four points and uses this as a fifth central point.  The program then draws each of the four resulting triangles and colours them according to some simple rules.

Javascript/HTML 5 version (2011)

If your browser supports HTML5, I have now written a variation of Frax that runs in a canvas object. Click on the link above to see it.