Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 10, NO. 1 / JANUARY 1984 / PAGE 210

Random landscapes; plotter tutorial - part 2. Michiel Van de Panne.

Random Landscapes

Plotter Tutorial--Part 2

Today I have written the most useless program ever invented. Nevertheless, I am certain you will find it interesting. What is the program you ask? Well, think of it as your introduction to the field of computer art. This program draws the random landscapes that illustrate this article. Perhaps it will spark your interest in the latest field to be invaded by computers, that age old phenomenon called art.

First of all, I should state that all the figures shown were drawn by the same program. All the variations are due to random numbers. Naturally, the ones I chose are the most appealing pictures that were generated. For every good landscape that is generated, there is frequently one that is not as attractive. This does nature justice, however, as the same holds true in nature.

To use the program, simply type it in and add the lines given for your computer. The remarks do not have to be typed in. The program will run as listed on the TRS-80 Model I/III with CGP-115 plotter. The figures were done with the CGP-115 plotter.

If there is no routine given for your computer, make one yourself. Line 20 should contain a clear screen, choose color, or whatever start up is necessary for your screen or plotter. Lines 920 and 930 should contain program lines to move to a point if A "MOVE' and to draw to a point if A "DRAW'.

Depending on your screen size or plotting surface, you might have to scale down the drawing by multiplying the X and Y coordinates by a fraction. The origin should be located halfway across the screen and one quarter of the way up. For a screen of 200 by 140, this would mean adding 100 to X and 35 to Y when plotting. Lastly, line 940 should contain a program line for generating a random number between one and the number given by the variable R1.

Creating The Landscape

Each landscape is made up of five parts: the ground level, the mountain backdrop, the tree or trees, the rocks, and possibly a park bench with or without a back. The trick in creating a reasonable landscape lies in controlling the randomness of all these different parts without overdoing it. Too much control of the random factors results in a similar picture each time the program is run. A balance must be reached to allow for variety but to eliminate anything wholly unnatural.

The ground level is the first part to be drawn in the scene. The first thought on drawing this simple slope at the bottom is simply to have a random height chosen along a regular interval of steps. Unfortunately, this results in a jagged and unrealistic surface. Instead, the program chooses a random constant that is added to the previous level at each step. This random constant is changed four times across the scene to allow for gradual changes. On top of this, more random numbers allow for minor variations of the levels dictated by first constant.

The mountains are much simpler to depict. The jagged surface that was unacceptable for the ground surface is perfectly acceptable for the mountains. The height of the mountains is changed to a different random number at random intervals. There is also a check included to ensure that they don't pass below the level of the ground that has been drawn.

The trees prove to be the most interesting feature of the landscape. Surprisingly, they are not as difficult to draw as it might seem. The first thing to notice is that each tree starts with one trunk that splits into two branches. Each of these branches further divides into two branches. This repeats until there are eight different levels of branches, with the trunk being the first level and all the twigs being the last level.

To make the tree random is fairly involved. First, the length of the trunk is specified by a random number. From the trunk onward, the length of each branch is about six tenths of the length of the previous level plus or minus a small random factor. The angles of the branches are also determined randomly. For each branch on a previous level, one branch goes to the left at a random angle (with respect to the branch to which it is attached), and another goes to the right.

I have not fully explored the possibilities of the random tree. Leaves would be one possible addition. Another interesting possibility would be to depict the tree as if being bent by the wind. I have tried this, but have not yet been successful at it. At any rate, there is an infinite number of things that can be randomly controlled or randomly added.

From the tree, the program proceeds to draw a random number of randomly shaped rocks. These rocks are basically circles that have been randomly deformed. As the angle of the circle increases in random steps, the radius is controlled by random numbers. In addition to this, the X axis of the circle is stretched randomly by a factor of between one and two. If this isn't random enough for you, the program also decides randomly how many rocks to draw and where to place them.

The last thing put in to complete the landscape is the park bench. First, there is a 50% chance that there will be a bench drawn. Second, if there is to be a bench, the computer will search for a flat spot to place the bench. If there is no such flat spot, the bench will not be drawn. Once a flat spot has been found, a bench without a back will be drawn. Another 50/50 chance determines whether a back is added to the bench.

Indentical Pictures?

For those interested in the chances of getting two identical pictures, the possibility of this happening is very small. The average drawing uses about 850 different random numbers. The average random number called for is between 1 and 20. This makes the chances of getting two identical pictures roughly 1 in 20 to the power of 850.

With all these random numbers, a somewhat random landscape has been made. Unfortunately, it is still no match for the variety and diversity of the landscapes found in nature. This program was not intended to duplicate nature though. To do so is an impossible task. If anything, these drawings will impress you because they are drawn by your 100% logical, digital, electronic computer. Furthermore, they show the beginning of the expanding possibilities of computer art. The last thought that the pictures impart is an immense appreciation for the beauty in the orderly chaos of nature.