3-D fractals; a new graphics technique for Apple II, Macintosh and TRS-80 computers. Michiel Van De Panne.
If you have no idea of what a fractal is, you are not alone. Fractals are, however, being used increasingly in a variety of modelling applications were it is desirable to obtain realistic simulations of such natural phenomena such as crystal growth, coastlines, and clouds. In this article, I will focus primarily on how to build realistic three-dimensional landscapes that are constructed with the aid of many random numbers.
Fractals: An Explanation
A fractal is an object that is put together by beginning with some basic shape such as a sphere and then adding or removing fractions of it. First, large fractions, or chunks, are removed or added in a random fashion. Then, in the next step of the procedure, smaller sized fractions are similarly removed or added. This process is repeated until the desired effect has been achieved.
It can easily be seen how this process can be used to construct landscapes when examining the structure of a mountain or other such natural phenomena in detail. A mountain can be thought of as a very large chunk of rock in the shape of a pyramid with parts taken out in some spots and added on in others. These parts serve to create the ridges, crests, bowls, etc. seen on real mountains. When smaller parts are added and removed from our model of a mountain, the resulting object becomes even more realistic. This basic concept of the addition and removal of parts of gradually decreasing size is the underlying concept of fractals.
In all of the accompanying illustrations, a triangle was used as a base figure. In theory, other types of figures can be used as starting configurations, but triangles make the construction of three dimensional fractals particularly easy, as you will soon see. The basic starting triangle is depicted in Figure 1a. To proceed to Figure 1b, each side on Figure 1a is divided at the midpoint. Each new midpoint is then displaced up or down by a random factor, and lines are drawn connecting these midpoints to the other midpoints created.
To create Figure 1c from Figure 1b, the same procedure is followed. The midpoint of each side is moved up or down by random amount and is then connected with straight lines to the surrounding points. Each time this procedure is repeated the number of triangles quadruples. We began in Figure 1a with one triangle, produced Figure 1b with four triangles and Figure 1c with 16 triangles, and end up in Figure 1g with a total of 4096 individual triangles.
When running the program, you have the option of choosing the number of times you wish to repeat the quadrupling process for the triangles. This is done by replying appropriately to the question Number of Levels?. Replying with 1 to indicate one level with result in a figure with four triangles. In other words, the dividing process will have been repeated once. Replying 2 will result in 16 triangles as a result of the dividing process having been repeated twice. Level 3 results in 64 triangles; Level 4, in 256 triangles, etc.
The Sea Level
You will have noticed at this point that all the illustrations in the article except for those in Figure 1 have a sea or water level, making the landscapes look like land with lakes, or islands, depending on how much of the land is above the water level. All these figures are constructed with the same process used to obtain Figure 1g, only they have a sea or water level inserted.
Running the Program
The programs as they are shown in the listings will produce only landscapes with sea levels. In the version for the Radio Shack Model I/III/4 with CGP-115 plotter and the Apple II version, the sea is colored blue while the land is colored black and white. Because the Apple Macintosh lacks color, the sea or water is indicated by dots. If you desire to produce a plot without a sca level inserted, simply change line 470 to read:
This applies to the versions for all three computers.
The only input the program requires is the number of levels you wish. This changes the number of triangles of which the resulting figure is made and hence, how realistic the resulting image is. A level 3 figure takes only about five minutes to plot, but does not produce a very realistic looking landscape. On the other hand, a level 6 figure might take an hour, but will produce a landscape that is very realistic. Generally, a good compromise is level 5. As listed, the programs create levels from 1 to 6.
If you have enough memory in your computer, you may wish to modify the program so that you can do up to seven levels. The enlarged illustration on page 82 is a figure with seven levels (16384 triangles). The only change required to do this is to change the dimension statement in line 20 from DIM D(64,32) to DIM D(128,64). On the Apple II/IIe there is not much point in doing this because the triangles are already approaching the pixel size in level 6. On the TRS-80 Model I/III/4 with CGP-115 plotter and the Apple Macintosh, the resolution is sufficient. You should plan on letting the computer plot for a long time, however.
It should not be difficult to modify the program to run on a different type of computer, providing it supports a sufficiently complex version of Basic and has a graphics resolution of at least 150 X 200 or so. All the program lines that are computer dependent are located at the end of the program from line 1030 on.
The technique used in the program for generating the landscapes is not my own. It is based on a technique described in the September 1984 issue of Scientific American. They in turn credit the original idea of fractal geometry to Benoit Mandlebrot, "the father of fractals', and the further development of the idea to Lucasfilm Ltd.
Table: Listing 1. TRS-80 Model I/III/4 version with CGP-115 plotter.
Table: Listing 2. Apple Macintosh version.
Table: Listing 3. Apple II version.
Photo: Figure 1a. Level 6.
Photo: Figure 1b.
Photo: Figure 1c.
Photo: Figure 1d.
Photo: Figure 1e.
Photo: Figure 1f.
Photo: Figure 1g.