home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
turbopas
/
mndlbrot.arc
/
MNDLBR1.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1988-07-05
|
10KB
|
285 lines
{ MANDELBROT
[Downloaded from Delaware OPUS 17 Feb 87 as MNDLBR.PAS.
Tweaked for speed.
David Kirschbaum
Toad Hall
kirsch@braggvax.ARPA
]
This program generates and displays Mandelbrots. A Mandelbrot is a
graphic representation of the mandelbrot set and the fleeing points
around the set on the REAL/IMAGINARY plane. Mathmatically, a point
in the set is defined as a point which when iterated in the following
manner will remain finite after an infinite number of iterations:
1. c := point; z := 0; n := 0;
2. z := z*z + c;
3 n := n+1;
4. repeat until either z>2 or n is some large number
Obviously the iteration cannot be carried out to infinity so we set an
upper limit to 255. Thus "n" can just fit in one byte. Typically large
computers will only carry n to 1000, and there is very little difference
between 255 and 1000 iterations.
The Mandelbrot set representation is a breathtakingly beautiful thing.
You are encouraged to try and find an issue of August 1985 Scientific American
for some really fantastic photos, as well as a well written article.
To operate the program just answer the questions. A "C" will allow you
to generate a mandelbrot and a "D" will allow you to display it with different
"Breakpoints". The IBM can only display 4 colors and 255 is defined as black.
You must enter 2 breakpoints: a lower and an upper.
When n is between 0 and the lower breakpoint, color 1 will be displayed;
between breakpoint 1 and 2, color 2 will be displayed;
and when between 2 and 255, the third color is displayed.
Generating a file will usually require from 6 to 12 hours, or if an 8087
chip is used (and Turbo 8087 is used for compiling) the time is cut to
"only" 2 to 4 hours.
It is recommended that the full Mandelbrot be computed first
(RL,RU,IL,IU = -2,.5,-1.25,1.25), then blowups done from it.
Remember to enter a carriage return after each number.
A disk for the IBM and compatibles which has this program and about 6 of the
really good plots on it is available for $5 to cover the cost of the disk and
shipping.
A disk with an advanced version of this program which allows windowing
of an area in the display, so referencing is done automatically to
the generate portion for an easy magnification of a specific area,
is available for $15.
The advanced version will have standard as well as 8087 com files
and includes many more features, as well as color pictures of several
Mandelbrots and updates when new features are added.
To order or report bugs Reply to: Marshall Dudley or Compuserve
12402 W. Kingsgate Dr. #72416,3357
Knoxville, Tn. 37922
This program may be duplicated and given away free provided
this introduction is left untouched.
Modifications: You may wish to try some modifications to this program.
If this program is modified please indicate who and what mods were done below.
I would be interested in hearing about any good mods and can be reached as
above.
Please do not change the file structure. It was done in this manner so that
a file can be created and displayed by standard or 8087 turbo interchangeably.
A change will cause compatibility problems.
}
PROGRAM Mandelbrot;
{$U-} {no user interrupts for speed}
{$C-} {no Ctrl C either}
{$V-} {relax string type checking}
TYPE
Str23 = STRING[23]; {TH}
Chunk = RECORD
Val1 : Str23;
Val2 : Str23;
Val3 : Str23;
Val4 : Str23;
littlechunk : ARRAY[0..319, 0..199] OF Byte;
END;
CONST
BEEP : CHAR = ^G;
VAR
breakPoint1, {Toad Hall: make these global for speed}
breakPoint2,
xPic,yPic,color : INTEGER;
realPart,imaginary, {Toad Hall: make these global for speed}
zr,zi, {ditto}
stepX,stepY, {ditto}
zrSquared,ziSquared, {ditto}
realUpper,realLower,
imagUpper,imagLower : REAL;
TName,
Name : STRING[20];
n : Byte;
ChunkFile : FILE OF Chunk;
ChunkRec : Chunk;
C,Choice : CHAR;
PROCEDURE Generate;
(* Toad Hall: made these global
VAR
realPart,imaginary,
zr, zi,
stepX,stepY,
zrSquared,ziSquared : REAL;
*)
BEGIN
WRITELN('Enter Lower and upper limits of Real & Imaginary parts');
WRITELN('as: RL RU IL IU. Separate each with a space, end with a RETURN.');
(*
READLN(realLower);
READLN(realUpper);
READLN(imagLower);
READLN(imagUpper);
*)
Read(realLower, realUpper, imagLower, imagUpper);
Writeln;
WRITELN('Enter filename:');
Name := ''; {insure cleared in case null entry}
READLN(Name);
IF Name = '' THEN HALT;
GraphColorMode;
stepX := (realUpper-realLower)/320.0;
stepY := (imagUpper-imagLower)/200.0;
FOR xPic := 0 TO 319 DO BEGIN
FOR yPic := 0 TO 199 DO BEGIN
n := 0;
zr := 0.0;
zi := 0.0;
Plot(PRED(xPic), PRED(yPic), 3);
realPart := realLower + INT(xPic) * stepX;
imaginary := imagLower + INT(yPic) * stepY;
zrSquared := 0.0;
ziSquared := 0.0;
REPEAT
zi := zi * zr * 2.0 + imaginary;
zr := zrSquared + realPart - ziSquared;
n := SUCC(n);
zrSquared := SQR(zr);
ziSquared := SQR(zi);
UNTIL ((zrSquared + ziSquared) > 4.0) OR (n > 254);
color := 3 - (n ShR 6); {make 0 to 255 into 15 to 0 for graphing}
Plot(PRED(xPic), PRED(yPic), color);
ChunkRec.LittleChunk[xPic,yPic] := n;
END;
IF KeyPressed THEN BEGIN
READ(Kbd,C);
IF C = #3 THEN HALT;
END;
END;
TextMode;
WRITE(BEEP); {Beep at finish}
STR(realLower:23, ChunkRec.Val1);
STR(realUpper:23, ChunkRec.Val2);
STR(imagLower:23, ChunkRec.Val3);
STR(imagUpper:23, ChunkRec.Val4);
Assign(ChunkFile,Name);
REWRITE(ChunkFile);
WRITE(ChunkFile,ChunkRec);
CLOSE(ChunkFile);
WRITE(BEEP);
END; {of Generate}
PROCEDURE Print;
VAR
realUpper,
realLower,
imagUpper,
imagLower : REAL;
{ n : Byte; Toad Hall: use global n }
Z : STRING[10];
{ breakPoint1, Toad Hall: made these global
breakPoint2,
}
palet : INTEGER;
Rerun : BOOLEAN; {Toad Hall}
FUNCTION value(numstring : Str23) : REAL;
VAR
temporary : REAL;
error : INTEGER; {Toad Hall : moved from Print}
BEGIN
IF Numstring[21] = '0' {if written by 8087 version}
THEN DELETE(Numstring,21,1);
REPEAT
DELETE(Numstring,1,1);
UNTIL ORD(NumString[1]) <> 32; {delete spaces}
VAL(NumString,temporary,error);
value := temporary;
END; {of value}
BEGIN {Print}
WRITELN('Enter Filename for data');
READLN(TName);
IF TName <> '' THEN BEGIN
Name := TName;
Rerun := FALSE; {Toad Hall: New file, so not a loop}
END;
IF Name = '' THEN Halt;
IF NOT Rerun THEN BEGIN {Toad Hall}
Assign(ChunkFile,Name);
RESET(ChunkFile);
READ(ChunkFile,ChunkRec);
CLOSE(ChunkFile);
realLower := value(ChunkRec.Val1);
realUpper := value(ChunkRec.Val2);
imagLower := value(ChunkRec.Val3);
imagUpper := value(ChunkRec.Val4);
END;
REPEAT
IF Rerun THEN Read(breakPoint1, breakPoint2)
ELSE BEGIN
WRITELN('Real Boundries are: ',realLower:10:8,' ',realUpper:10:8);
WRITELN('Imaginary Boundries: ',imagLower:10:8,' ',imagUpper:10:8);
WRITELN('255 will be black, Enter breakpoints for other two shades');
Writeln(' Format: <RETURN> for no change, nnn nnn<RETURN> for new entry: ');
(*
READLN(breakPoint1);
READLN(breakPoint2);
*)
Read(breakPoint1, breakPoint2); {TH}
Writeln;
WRITELN('When display is complete enter a "P" to change palettes,');
WRITELN('"R" to rerun the same file (and perhaps enter new breakpoints),');
WRITELN('any other character to exit. Enter Return to display plot');
READ(Z);
GraphColorMode;
END;
FOR xPic := 0 TO 319 DO BEGIN
FOR yPic := 0 TO 199 DO BEGIN
n := ChunkRec.LittleChunk[xPic,yPic];
IF n = 255 THEN color := 0
ELSE IF (n < breakPoint1) THEN color := 3
ELSE IF (n < breakPoint2) THEN color := 2
ELSE color := 1;
Plot(xPic,yPic,color);
END;
END;
palet := 0;
REPEAT
READ(Kbd,C); {wait for an entry before erasing screen}
C := Upcase(C);
palet := SUCC(palet) AND 3;
IF C = 'P' THEN Palette(palet);
Rerun := (C = 'R');
UNTIL C <> 'P';
UNTIL NOT Rerun; {Toad Hall rerun loop}
TextMode;
END; {of Print}
BEGIN {main}
Name := '';
REPEAT
ClrScr;
WRITE('(C)reate a Mandelbrot file, (D)isplay a file or (E)xit ? ');
REPEAT
READ(Kbd,Choice);
Choice := Upcase(Choice)
UNTIL Choice IN ['C','D','E'];
WRITELN;
CASE Choice OF
'C' : Generate;
'D' : Print ;
END; {case}
UNTIL Choice = 'E';
END.