home *** CD-ROM | disk | FTP | other *** search
- { MANDELBROT
-
- 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 modificatins 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 inter-
- changeably. A change will cause compatability problems.
-
- }
-
- Program Mandelbrot;
- {$U-}
-
- type
- Special = String[23];
-
- chunk = record
- Val1:Special;
- Val2:Special;
- Val3:Special;
- Val4:Special;
- littlechunk : array[0..319,0..199] of byte;
- end;
-
- Const
-
- Beep :Char = ^G;
-
- var
-
- XPic,YPic,Color :Integer;
- RealUpper,RealLower,ImagUpper,ImagLower :Real;
- Name :string[20];
- N : byte;
- chunkfile : file of chunk;
- ChunkRec : Chunk;
- c,choice : char;
-
- Procedure Generate;
-
- 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 each followed by a CR.');
- Readln(RealLower);
- Readln(RealUpper);
- Readln(ImagLower);
- readln(ImagUpper);
- Writeln('Enter filename:');
- Readln(Name);
- 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;
- ZI:=0;
- Plot(XPic-1,YPic-1,3);
- RealPart:=RealLower+Int(Xpic)*Stepx;
- Imaginary:=ImagLower+Int(Ypic)*StepY;
- ZrSquared:=0;
- ZISquared:=0;
- repeat
- ZI:=ZI*ZR*2+imaginary;
- Zr:=ZrSquared+REALPart-ZISquared;
- N:=N+1;
- ZrSquared:=Sqr(Zr);
- ZISquared:=Sqr(ZI);
- Until ((ZrSquared+ZISquared)>4) or (N>254);
- Color:=3-(N shr 6); {make 0 to 255 into 15 to 0 for graphing}
- Plot(XPic-1,Ypic-1,Color);
- ChunkRec.LittleChunk[xpic,ypic]:=n;
- End;
- if keypressed then
- Begin
- Read(Kbd,c);
- if c = Chr(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;
-
- Procedure Print;
-
- var
-
- RealUpper,RealLower,ImagUpper,ImagLower :Real;
- N :Byte;
- z :String[10];
- Breakpoint1,Breakpoint2,EPosition,Palet,error :Integer;
-
- Function Value(numstring: Special) : Real;
-
- var
- temporary : real;
-
- Begin
- If Numstring[21]='0' then delete(numstring,21,1); {If written by 8087 version}
- Repeat
- Delete(numstring,1,1);
- until Ord(NumString[1])<>32; {delete spaces}
- Val(NumString,temporary,error);
- Value := temporary;
- End;
-
- Begin
- Writeln('Enter Filename for data');
- Readln(Name);
- 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);
- 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');
- Readln(Breakpoint1);
- Readln(Breakpoint2);
- Writeln('When display is complete enter a "P" to change palettes or');
- Writeln('any other character to exit. Enter return to display plot');
- Read(z);
- GraphcolorMode;
- 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}
- Palet := (Palet+1) AND 3;
- If UpCase(c) = 'P' then Palette(Palet);
- Until Upcase(c) <> 'P';
- textmode;
- End;
-
- Begin
- Repeat
- ClrScr;
- Write('(C)reate a Mandelbrot file, (D)isplay a file or (E)xit ? ');
- Repeat Read(kbd,choice) until UpCase(choice) in['C','D','E'];
- Writeln;
- Case Choice of
- 'c','C' :Generate;
- 'd','D' :Print;
- end;
- until UpCase(choice) = 'E';
- end.