APPLICATIONSCREATION GRAPHIQUE ★ MANDELBROT GENERATOR ★

Mandelbrot GeneratorApplications 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 ★ 

All set for Mandelbrot: a type-in on a fascinating frontier of maths, guided by RpM

In the age of the supercomputer whole new areas of problem-solving have been invented because they're possible. Complex equations involving hundreds of thousands of calculations have become manageable What would have taken hundreds of man-years to complete can take seconds on a powerful computer. Several mathematicians' theories have been explored in depth as a result of the computer. The Mandelbrot set - which stems from fractals is both obscure and spectacular. Much has been made of Benoit Mandelbrot and the set he discovered in 1974. Why? Look at the colourful eye-catching designs of ever-increasing complexity No use whatsoever - but breathtaking.

The Mandelbrot set is pictured as an area in two dimensions It's a collection of points defined by a simple repeated function You can see the complete Mandelbrot set in the picture the black region. The coloured bands represent the behaviour of points as they get close to the set.

It's the complexity of the shape that makes the Mandelbrot set so fascinating: the more you enlarge and examine minute areas of the set. the more complex it gets. Although the area is finite lies within the circle defined by x² + j² = 4 (which I'm not going to prove, you can get further details from Mandelbrot's book The Fractal Geometry of Nature) - the edge is infinitely complex and of infinite length. Mathematicians have a word for this: fractal. A few recent games use fractal graphics to build, say. a real-looking mountain from only an equation Eidolon and Koronis Rift are two Enough of the background information. Let's get down to the nitty-gritty of things. Here is a type-in that will produce the entire Mandelbrot set and the other areas seen on this page.

Mandelbrot Generator

Alex Clark, the man from Lamlash in Strathclyde, is responsible for the listing capable of producing the spectacular Mandelbrot set. (And thanks to all the other readers who submined versions as a result of Owen Cunningham's letter in Reaction 21.) It has two ways of operation: automatic mode draws the complete Mandelbrot set and six other interesting locations from the set: manual mode lets you select and view an area of the set. In either case the final design is saved to disk or cassette. It is best to run the program and leave Arnold to do his bit for a day or so: each picture takes between three and eight hours to produce.

1 ' Mandelbrot generator
2 ' by Alex Clark
3 ' Amstrad Action     August 87
10 MODE 1: MEMORY &4FFF: DIM c%(255)
20 INPUT"Automatic or manual operation? (a/m): ";am$
30 IF LEFT$(LOWER$(am$),1)="a" THEN GOSUB 120 ELSE GOSUB 50
40 END

Alex has been rather clever in the way he has used LEFT$ and LOWER$ in this line. LEFT$ (string expression, required length) is the standard format for the command. Its function is to extract the number of characters from a string (specified by required length) starting from the left of the string.

LOWER$ forces a string to lower-case - UPPER$ does the opposite. It is now easy to see what line 30 does to your input -which is held in am$ : the command LEFT$ (LOWER$ (am$) ,1) = a will force am$ to lowercase and interest itself in the leftmost character only. If the expression falls true, that is, finds that your input consists of an a , you'll be whisked off to line 120 , otherwise you're banished to line 50.

Dicing with data

Notice line 100, which reads a$= "!" + a$. The filename is held in a$. The exclamation mark prefixed to a$ prevents the SAVE message appearing on screen (which would rum five hours' computer time).

50 ' *** "j" "k" and "q" manual input
60 INPUT "Enter j... [real axis start]: ";j
70 INPUT "Enter k... [imaginary axis start]: ";k
80 INPUT "Enter q... [axes' length]: ";q
90 INPUT "Enter filename to save picture under: ";a$
100 a$="!"+a$
110 GOSUB 280: GOSUB 540: MODE 1: RETURN

Once the program has accepted your input it will GOSUB 260 which does the calculating, GOSUB 540 (draws up the picture and saves it) and finally RETURNS whence it came.

120 ' *** Load in your own data for "j" "k" and "q"
130 ' or run this routine to give five good examples
140 ' from the Mandelbrot set ***
150 FOR a=1 TO 6: READ xa(a),ya(a),sa(a): NEXT
160 ' *** Coordinatess for entire set ***
170 DATA -2.0,-1.25,2.5
180 ' *** Interesting locations from set ***
190 DATA -0.9, 0.15, 0.2
200 DATA 0.353, 0.647, 0.005
210 DATA 0.34, 0.63, 0.04
220 DATA -0.737, 0.25, 0.025
230 DATA -0.725, 0.257, 0.006
240 FOR pics=1 TO 6
250 a$="!mandpic"+MID$(STR$(pics),2,1)
260 j=xa(pics): k=ya(pics): q=sa(pics)
270 GOSUB 280: GOSUB 540: MODE 1: NEXT: RETURN

If you picked automatic then you'll have landed here. Line 150 reads in the data starting at 170 which holds the coordinates for the entire Mandelbrot set and five other locations in and around the set. If you wish you can replace the existing data with some of your own.

The data is placed into arrays. Array xa will hold the six different j values, ya the six k values and so on.

Line 150 contains an interesting example of string-handling: a$ holds |mandpic. However, there is a plus sign following the closing quotemark , indicating more to a$ than is immediately obvious. The plus is followed by MID$ and a smattering of assorted characters. The function MID$ has the format MID$ (string variable, position, new string length). It behaves in a similar way to LEFT$. The string variable in this case is STR$ (pics). The variable pics ranges from one to six (defined in the for-next loop, line 240). STR$ will convert a numeric expression into string form. So the net result is that a$ will contain |mandpic1 , with the final digit increasing each time until 6.

Assigning variables

The next section of the program is responsible for working out and storing the different points of the Mandelbrot set. You should have no trouble following this part. What you may not have come across is the form variable%. The percent-sign tagged onto a Basic variable's name indicates a special type an integer variable. An integer is a whole number; it does not allow a fractional part. There is a good reason for using this form of variable: it takes up less space in memory and consequently increases execution speed.

280 ' *** Mandelbrot set generator ***
290 BORDER 0: INK 0,0: INK 1,13: PAPER 0: PEN 1: MODE 1
300 PRINT "RUNNING"
310 tot=0
320 s%=255
330 h=q/128
340 add=&5000
350 FOR j%=0 TO 127
360 t=TIME
370 FOR k%=0 TO 127
380 u=j+h*j%
390 v=k+h*k%
400 n%=-1:x=0:y=0
410 y2=y*y
420 x2=x*x
430 y=2*x*y+v
440 x=x2-y2+u
450 n%=n%+1
460 IF n%=s% OR x2+y2>=4 THEN 470 ELSE 410
470 POKE add,n%: add=add+1: NEXT
480 PRINT j%+1;"completed out of 128 runs taking"
490 se=INT((TIME-t)/300): mi=INT(se/60): sec=se-(mi*60)
500 PRINT mi;"mins  ";sec;"secs"
510 tot=tot+mi+(sec/60): NEXT
520 PRINT "end after about";INT(tot);"minutes"
530 RETURN

The listing works out the points for the Mandelbrot set within an area 128 by 128. Each point is worked out individually - this amounts to an incredible 16,384 points to calculate. Given that each calculation with all its stages takes approximately one second, it's easy to understand why Arnold needs five hours to draw a single picture.

Drawing the set

The data for the Mandelbrot set is stored from memory location &5000 (in decimal, 20480). If a point is within the set it will have a value 255. The nearer the point is to the set. the higher its value. Points of the same value will have identical colours assigned to them, rather like contours on a map. In theory there could be 256 colours in the final display, but in practice too many colours would produce a confusing display. Not only that, the Amstrad can display a maximum of only 16 colours. So we compromise: ranges of numbers will have certain colours assigned to them.

540 ' *** Mandelbrot drawer ***
550 ' *** Initialise ***
560 maxcol%=15
570 FOR n%=0 TO 255
580 c%(n%)=0
590 NEXT
600 ' *** Find max and min values ***
610 add=&5000
620 FOR n%=1 TO 128*128
630 b%=PEEK(add): add=add+1
640 c%(b%)=c%(b%)+1
650 NEXT
660 ' *** Assign colours to values ***
670 ma=(128*128-c%(255))/maxcol%
680 c%(255)=0
690 j%=maxcol%
700 t%=0
710 FOR n%=0 TO 254
720 t%=t%+c%(n%)
730 c%(n%)=j%
740 IF t%>=ma*(maxcol%-j%+1) THEN j%=j%-1: IF j%<1 THEN j%=1
750 NEXT
760 ' *** Draw Set ***
770 MODE 0: ORIGIN 64,72
780 RESTORE 790:FOR a%=0 TO 15:READ col%:INK a%,col%:NEXT
790 DATA 0,4,1,2,9,12,18,25,24,15,6,7,16,10,13,26
800 h%=8
810 add=&5000
820 FOR j%=0 TO 127
830 FOR k%=0 TO 127
840 a%=PEEK(add): add=add+1
850 b%=c%(a%)
860 PLOT j%*4,k%*2,b%
870 NEXT
880 NEXT
890 ' *** Save Screen ***
900 SAVE a$ + ".pic", b, &C000, &4000
910 RETURN
920 END

Now, while wait mg for your screen to fill, has anyone written a short, fast machine code version? Please send it in.

AA

★ PUBLISHER: Amstrad Action
★ YEAR: 1986
★ CONFIG: AMSDOS + 64K
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: Alex Clark

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listings:
» Mandelbrot  Generator    (Amstrad  Action)    ENGLISHDATE: 2020-04-22
DL: 117 fois
TYPE: ZIP
SIZE: 5Ko
NOTE: Uploaded by CPCLOV ; 40 Cyls
.HFE: NON

» Mandelbrot  Generator    (Amstrad  Action)    LISTING    ENGLISHDATE: 2018-08-07
DL: 82 fois
TYPE: text
SIZE: 4Ko
NOTE: Uploaded by CPCLOV

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.
★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Simplification de Fractions / Simplification de Fraction (Amstrad Magazine)
» Applications » CPC464 Lotto-statistik 6/49
» Applications » Disctimer (CPC Amstrad International)
» Applications » RAM-Disc (Computer Partner)
» Applications » Letra Cursiva (Amstrad Magazine)
» Applications » Anti-Erreurs (CPC Infos)

CPCrulez[Content Management System] v8.7-desktop
Page créée en 192 millisecondes et consultée 534 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.