★ CODING ★ LISTINGS ★ LANDSCAPES (YOUR COMPUTER) ★ |
Landscapes (Your Computer) | Coding Listings |
Brian James concludes his scenic art program for the Amstrad. This MONTH we look further into the nature of probability which is the key concept in these programs for the Spectrum and Amstrad computers which generate landscape scenes spontaneously. Such a program first needs some basic knowledge about the subject to be portrayed. This knowledge is described by mathematical relationships. Some of these relationships are rigid ones — for example, solid features will hide the view behind them. Other relationships are not precisely defined; for example the slope of a mountainside may have almost any gradient, though very steep slopes occur only occasionally. The program must be allowed freedom of choice wherever possible, but must not be allowed to do unusual things too often. That is — suitable probability functions must be used. Listing 1 is a simple Basic program to demonstrate some probability distributions. The function RND returns a value between 0 and 1, with no bias. Therefore the combination x = a + RND *b gives a “flat” distribution — that is, equal probability of any value between the lower limit la) and the upper limit (a + b). Now we can combine the RND functions in different ways to produce more subtle distributions. Suppose we put x = a + (RND + RND + RND + RND)/4 * b This gives a hump-shaped distribution — a crude approximation to the famous “Normal” distribution. The values of x will tend to cluster around the middle with smaller probability of extreme values. Now consider x = a * RND ↑ 2 This will cause a skewed distribution, with small values of x having much greater probability than large values. A greater skew will be obtained from the function x = a* RND ↑ 4 and so on. It is important to realise that RND is different every time it is used — therefore RND + RND is NOT equal to 2 * RND Listing 2 is a very entertaining program using two-dimensional distributions to produce a multicoloured pulsating galaxy. The same distribution can be used for a cluster of leaves, daisies etc. These programs are in Basic, which is very easy to enter and very easy to experiment with. The Landscape Utility itself has been written in pure machine code, because of the sheer number of calculations which have to be done. Each new landscape is created in about 8-20 seconds. Suitable probability distributions can create surprisingly realistic mountain skylines. The slope must take values which are not too steep too often, not too straight, and not showing a regular pattern. There are big bumps and small bumps and even smaller bumps . . . The mathematical functions called fractals have this property of having an endless succession of smaller end smaller wiggles, in fact going on and on, to the infinitely small. They have been used to create mountain scenery with remarkable realism by Lucasfilm, using very expensive high-resolution equipment. However, true fractals are purely mathematical abstractions .. . they have an infinite length, because of the infinite number of wiggles on an ever-decreasing scale of size, and therefore cannot actually be shown on any video screen! However my own functions are not unrelated to fractals,, since they use two different magnitudes of wiggliness. There is a problem with the random number generators in the home computer. They are not truly random; they are “pseudorandom". This mcans each number is not actually independent. You will eventually come back to the same sequence and go round in a tig cycle. Also patterns can sometimes be found if you plot a random scatter of points. What should we call this kind of ant? I suggest the terms “artistic algorithms” or “computer creativity”. The simplest kind of program, which draws diagonal lines at random polygons, could be said to be “random art”.
|