APPLICATIONSCREATION GRAPHIQUE ★ FRACTAL LANDSCAPE GENERATOR (AMSTRAD COMPUTER USER) ★

Fractal Landscape Generator (ACU 89/11)Fractal Landscape Generator (ACU 89/12)Fractal Landscape Generator (ACU 90/01)Fractal Landscape Generator (ACU 90/04)
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

Pining for the fjord

Make your own Norwegian landscape with our three-part fractals feature.

The next time you are passing through Norway on your way to the shops, take a good close look at the fjords because they are well worth the visit. Amazingly, no matter how closely you look at them, they still have crinkly edges, and these all look like smaller fjords.

If you were of a mind to create fjords of your own, there are two ways of going about it. The first involves rubbing large amounts of rock, sea and ice together for a few million years (but more often than not, you will only end up with cold, muddy seawater). The second approach is to take a computer, like a CPC, apply fractal transformations to some random numbers and within minutes: fjords.

The magic word here of course is “fractal". This is a very simple animal which produces very complex patterns and which has become synonymous with computer graphics. You may have already seen the Mandelbrot set and Dragon curve programs and may have played games like Ko-ronis Rift, Sentinel, or more recently, Captain Blood, which all feature fractal landscapes.

Fractals are shapes that are produced by repeatedly applying a series of rules to a simple shape; the more often you apply the rules, the more complex the shape becomes, revealing more detail and allowing you to look more closely at the shape.

If small errors creep into the calculations, the pattern will quickly deviate from the original shape, producing a new^, but still related shape. Take two points (A and B), for example, and give each a random height (height A and height B).

Next we need to invent a rule for creating a new' height for the point midway between them. “At the midpoint the new height is the average of the two original heights”, for instance. This will now give us three points; the second application makes five points;
the third, nine, and so on. Thus each time the rule is applied new points are created, this could carry on until there are an infinite number of points and the distance between them is so small as to be unmeasurable.

Program 1 illustrates this technique, because as we are plotting the results to the screen, the progam will stop wiien the distance between two points is “1”. The WHILE...WEND loop steps through the array, halving the STEP size for the FOR...NEXT loop, halving the distance between the points. Type in this listing and save it as “prog1.bas”.

When this program has been entered, saved and run, enter a number for the random number seed which will be used to generate two random points (5 has been used in the example). As you will see, the effect is to draw a straight line between the two points. (Incidentally, this is a faster method than those traditionally used by line-drawing routines, but it is never used because each point on the line has to be held in an array - which is generally impractical.) This does not look like a landscape, however, so a small random error is added to the calculation each time and the effect is somewhat different. To see this, change line 1150 to read:

1150 height[midx]=( height [midx-halfj + height[midx+half] )/2 + (1-2*RND)*10

Save the modified program and run it. The line now changes into one that randomly weaves around the original. Unfortunately, this line is very erratic and still does not resemble any natural geological occurrence. So now we make smaller the amount of error that we add for points that are closer together. We do this by changing line 1150 again, so that it now reads:

1150 height[midx]= (heightfmidx-half] + height[midx+half] )/2 + (1-2*RND)*maxh

and by changing line 1180 as well to read:

1180 midpoint=half: maxh=maxh / 2 Finally we have a smooth random curve that could easily be used to represent the horizon of an imaginary landscape. The results of all three versions of the program are shown in Fig. 1. Now we can state our refined rule: “At the midpoint the new height is the average of the two original heights, plus some error, which is proportional to the distance between them.” This looks like:

height M = ( heightA + heightB ) / 2
+ RAND (distance B - distance A)

All that is needed now is to use this simple rule to create a landscape in three dimensions, which involves adding a second axis (Y).

In the three-dimensional program. Program 2, for each pair of points that make up the line in Program 1, we are now considering four points that make up a square, and calculating the midpoints of each edge and of the centre (a,b,c,d and m of Fig. 2). The subroutine “sub 1” calculates these midpoints, and the WHILE...WEND loop and the pair of FOR.. .NEXT loops ensure that these are calculated for all points in the array - in much the same way as in Program 1.

On running this program, a pattern will build up; long before it is complete, you will be able to determine the general shape; and as the program progresses, more detail will be added. If you increase the ‘size' of the landscape, even more detail will be revealed. If we imagine that all the black and blue areas here are seas and the green and brown regions are land masses, the final image looks convincingly like a contour map, the coastline having the characteristic crinkliness of a Norwegian fjord. (Change the variable ‘size' to 128 to produce Fig. 3. This will take some time to plot.)

To view this map in a three-dimen-sional isometric form like those used to illustrate geography text books, add Subroutine 5 to the end of the program.

The result of this additional routine is shown in Fig. 4; although lacking in perspective, it does resemble a section of a landscape.

The slow Basic routine for calculating the fractal will be replaced next month by a faster machine code version, and the beginnings of the Landscape Generator Program will start to emerge. The following month will see the isometric projection routine of Subroutine 5 converted into a true perspective image. Experiment with the routines in the meanwhile, and see what can be achieved by modifying the program.

ACU

★ PUBLISHER: Amstrad Computer User
★ YEARS: 1988 , 1990
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ COLLECTION: AMSTRAD COMPUTER USER 1990
★ AUTHOR: Dean CRACKNELL
   

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Fractal  Landscape  Generator  v1.1    (Amstrad  Computer  User)    ENGLISHDATE: 2023-12-03
DL: 278
TYPE: ZIP
SiZE: 15Ko
NOTE: 40 tracks
.HFE: Χ
.DSK: √

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Mandelbrot Generator
» Applications » Fraktalsee Plus
» Applications » Machine code Mandelbrot
» Applications » Fractals Land (Happy Computer)
» Applications » Fraktales Gebirge (CPC Amstrad International)
» Applications » Fractal Landscapes (Amstar&CPC)
Je participe au site:
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 233 millisecondes et consultée 1886 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.