APPLICATIONSCREATION GRAPHIQUE ★ 2D/3D FRACTAL LANDSCAPE (AMSTRAD COMPUTER USER) ★

2D/3D Fractal Landscape (Amstrad Computer User)Applications Creation Graphique
★ 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 ★ 

Dean Cracknel starts a series of articles on generating Fractals.

The next time you are passing through Norway, on your way to the shops look at the fjords, because they are well worth a visit. No matter how closely you look at them they still have crinkly edges, looking like smaller fjords.

If you wanted to create fjords of your own, there are two ways to do so. The first involves rubbing large amounts of rock, sea and ice together for a few million years but, more often than not. all you will have is cold, muddy seawater. The second approach is to take a computer, like a CPC, apply fractal transformations to some random numbers and, within minutes - instant fjords.

The magic word of course, is fractal. It is a very simple function which, produces very complex patterns and has become synominous with computer graphics. You may have already seen Mandelbrot Set and Dragon curve programs and you may have played games thich feature fractal landscapes, such as Koronis Rift, Sentinel or, more recently, Captain Blood.

Fractals are shapes produced by applying a series of rules repeatedly to a simpler shape; the more times you apply the rules, the more complex the shape becomes, revealing more detail and allowing you to look closer at the shape

If small errors creep into the calculations, the pattern will deviate quickly from the original shape to produce a new but still related shape. An example is to take two points, A and B. 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, for instance. “At the midpoint the new height is the average of the two original heights This will give us three points; the second application makes five points, the third makes nine.

Each time the rule is applied, new points are created and this could continue until there are an infinite number of points and the distance between them is so small as to be unmeasurable. Listing one illustrates this technique. Because we are plotting the results to the screen, the program will stop when 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".

Program 1. Hint: use AUTO1000 to type-in the listing.

« List "PROGM.BAS” here »

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. In the example, 5 has been used. As you will see, the effect is to draw a straight line between the two points. Incidentaley, this is a faster method than the ones used traditionally by line-drawing rountines but is never used because each point on the line has to be held in an array, which is generally impracticable. This does not look like a landscape, 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-half) + height(midx+half))/2 + (1-2*RND)*10

Save the modified program and run it. Now the line changes into a line which weaves randomly round the original. Unfortunately this line is very erratic and still does not resemble any natural geological occurrence. So now make the amount of error we add smaller for points which are closer together by changing lines 1150 and 1180 to read:

1150 height(midx)=( height(midx-half) + height(midx+half) )/2 + (1-2*RND) 'maxh

1180 midpoint=half: maxh=maxh 12 Finally, we have a smooth random curve which could
easily be used to represent the horizon of an imaginary landscape: the results of all three versions of the program are shown in figure one. Now we can state out 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”, which looks like:

height A + height B

height M = --------------- + RAND (distance B - distance A)

All that we 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, listing two for each pair of points which make up the line in listing one we are now considering for points which make a square and we are calculating the midpoints each edge and of the centre - a, b, c, d, and m of figure two. The subroutine ‘‘sub 1"

calculates those midpoints, the WHILE..WEND loop and the pair of FOR...NEXT loopes ensure that they are calculated tor all points in the array in much the same way as listing one.

« List "PROG1-2.BAS" here »

On running this program a pattern will build up. Long before it is complete you will be able to determine the general shape. As the program progresses, more detail will be revealed. If we imagine that all the black and blue areas are seas and the green and brown regions are land masses, the final image looks convincingly like a contour map with the coastline having the characteristic crinkliness of a Norwegian fjord. Change the variable “size" to 128 to produce figure three; this will take some time to plot.

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

Sub 5:

« List "SUB-5.BAS" here »

and call it from line 1180 thus:

1180 GOSUB1500

The result of this additional routine is shown in figure four which, although lacking in perspective, 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 begin to emerge. The following month we will convert the isometric projection routine of subroutine 5 into a true perspective image. In the meantime, experiment with the routines and see what can be achieved by modifying the program.

ACU

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

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» 2D-3D  Fractal  Landscape    (Amstrad  Computer  User)    ENGLISHDATE: 2023-12-05
DL: 38
TYPE: ZIP
SiZE: 6Ko
NOTE: 40 tracks
.HFE: Χ
.DSK: √

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

Lien(s):
» Applications » Fraktal Generator 3D
» Applications » Fraktalsee Plus
» Applications » Mandelbrot Generator
» Applications » Fractals on Amstrad (Popular Computing Weekly)
» Applications » Fractals Land (Happy Computer)
» Applications » Graphic - Mandelbrot Set (Computing With the Amstrad)
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 591 millisecondes et consultée 1490 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.