{$R-,S+,I+,D+,T-,F-,V+,B-,N+,L+ } {$M 16384,0,655360 } Program Mandelbrot; uses graph,crt; type bigarray= array[0..639] OF integer; var choice,nrows,ncolumns,maxiterations,mincount,maxcount:integer; m,n,x,count,range,colorpicked,dummy,graphdriver,graphmode:integer; acorner,bcorner,side,gap,ac,bc,az,bz,size:double; f:text; g,h:text; outfile,outfileX,quit,tosave,visualfile:string; columnarray:bigarray; Procedure Determine_Range; Begin writeln('Enter the number of rows, or the maximum Y value.'); write(': '); readln(nrows); writeln('Enter the number of columns, or the maximum X value.'); write(': '); readln(ncolumns); writeln('For the Southwest corner: '); write(' Enter the real value (x-axis): '); readln(acorner); write(' Enter the imaginary value (y-axis): '); readln(bcorner); write('Enter the length of the rectangle: '); readln(side); gap:=side/nrows; write('Enter the maximum number of iterations (an integer): '); readln(maxiterations); writeln('Enter Output File Name.'); write(': '); readln(outfile); outfileX:=outfile+'x'; assign(f,outfile); assign(g,outfileX) End; Procedure Calculations; Begin rewrite(g); writeln(g,nrows); writeln(g,ncolumns); writeln(g,acorner); writeln(g,bcorner); writeln(g,gap); writeln(g,maxiterations); maxcount:=0; mincount:=maxiterations; writeln(g,mincount); writeln(g,maxcount); For m:=0 to nrows Do Begin bc:=bcorner +(m*gap); For n:=0 to ncolumns Do Begin ac:=acorner +(n*gap); az:=0; bz:=0; count:=0; Repeat az:=az*az-(bz*bz)+ac; bz:=2*az*bz+bc ; count:=count+1; size:=sqrt(az*az+bz*bz); Until (size>2.0) or (count>maxiterations); columnarray[n]:=count; if countmaxcount then maxcount:=count; end; For n:=0 to ncolumns do writeln(g,columnarray[n]); end; close(g); rewrite(f); writeln(f,nrows); writeln(f,ncolumns); writeln(f,acorner); writeln(f,bcorner); writeln(f,gap); writeln(f,maxiterations); writeln(f,mincount); writeln(f,maxcount); reset(g); for x:=1 to 8 do readln(g); for m:=0 to nrows do begin for n:=0 to ncolumns do readln(g,columnarray[n]); for n:=0 to ncolumns do writeln(f,columnarray[n]); end; close(f); erase(g); randomize; while not keypressed do begin x:=round(exp(random(900)/100)); sound(x); x:=random(1000); delay(x); nosound; delay(10); end; End; Procedure Assign_Colors; Begin End; Procedure Color; Begin For x:=1 to 15 Do Begin If (count>(mincount + (range*x)/15)) then colorpicked:=x; End; If count>maxiterations then colorpicked:=0 End; Procedure Make_Visual;Forward; Procedure Paint_Picture; Begin graphdriver:=9; graphmode:=2; initgraph(GraphDriver,GraphMode,''); reset(f); readln(f,nrows); readln(f,ncolumns); readln(f,acorner); readln(f,bcorner); readln(f,gap); readln(f,maxiterations); readln(f,mincount); readln(f,maxcount); range:=maxcount-mincount; For m:=0 to nrows Do Begin For n:=0 to ncolumns Do readln(f,columnarray[n]); For n:=0 to ncolumns Do Begin count:=columnarray[n]; Color; putpixel(n,m,colorpicked); end end; if tosave='Yes' then begin tosave:='No'; rewrite(h); writeln(h,nrows); writeln(h,ncolumns); for m:=0 to nrows do begin for n:=0 to ncolumns do columnarray[n]:=getpixel(n,m); for n:=0 to ncolumns do writeln(h,columnarray[n]); end; close(h); end; m:=1; for x:=1 to 30 do begin m:=2*m; sound(m); delay(100); nosound; delay(40); end; repeat ; until keypressed; closegraph; close(f) End; Procedure Save_File; Begin End; Procedure Load_File; Begin write('Enter file name to be loaded: '); readln(outfile); assign(f,outfile) End; Procedure Make_Visual; begin writeln; writeln; write('Enter name for visual file : '); readln(visualfile); tosave:='Yes'; assign(h,visualfile) end; Procedure Display_Visual; begin writeln; writeln; write('Enter name for visual file: '); readln(visualfile); assign(h,visualfile); reset(h); readln(h,nrows); readln(h,ncolumns); graphdriver:=9; graphmode:=2; initgraph(graphdriver,graphmode,''); for m:=0 to nrows do begin for n:=0 to ncolumns do readln(h,columnarray[n]); for n:=0 to ncolumns do putpixel(n,m,columnarray[n]); end; close(h); repeat ; until keypressed; closegraph; End; {Menu} Begin Quit:='No'; tosave:='No'; Repeat Begin Writeln(' Mandelbrot Menu'); writeln; writeln('1: Determine boundaries and range of operations.'); writeln; writeln('2: Do Calculations.'); writeln; writeln('3: Display_Visual.'); writeln; writeln('4: Assign colors.'); writeln; writeln('5: Paint picture.'); writeln; writeln('6: Save file.'); writeln; writeln('7: Load file.'); writeln; writeln('8: Make_Visual.'); writeln; writeln('9: Quit.'); writeln; writeln; write('Enter choice: '); readln(choice); case choice of 1: Determine_Range; 2: Calculations; 3: Display_Visual; 4: Assign_Colors; 5: Paint_Picture; 6: Save_File; 7: Load_File; 8: Make_Visual; 9: Quit:='Yes' end ; End; Until Quit='Yes' End.