lackey@Alliant.COM (Stan Lackey) (09/01/88)
A co-worker recently implemented Mandelbrot on a system at work, and I was impressed with the results. So I figured, why not try it on my you-know-what. I was very pleased with the results, never expecting such a tiny program to create such a nice display. For any neo's out there, the algorithm is to test the magnitude of imaginary numbers as they are repeatedly squared (sort of) and plot a color depending on the number of times the number was squared before its magnitude exceeded the value 2. (Numbers that will never exceed a magnitude of 2 are numbers in the "Mandelbrot Set".) This program simply uses gr.11 which has 16 colors. The color selected by the algorithm is the color selected to plot. If the point has exceeded 15 squarings and has still not exceeded the limit, it is assumed in the Mandelbrot set and drawn as black. This is, of course, an approximation. There are no bells and whistles (add them yourself!) but here goes. In BASIC, of course! 10 REM MANDELBROT PATTERNS 20 RS=1/40 : IS=RS/4 : REM INCREMENTS FOR REAL AND IMAGINARY AXES 30 ORGR=1.5 : ORGI = 0.6 : REM DEFINES WHERE IN THE COMPLEX PLANE TO PLOT 100 GRAPHICS 11 200 FOR S=0 TO 79 205 R=S*RS-ORGR : REM SCALE HORIZ (REAL) AXIS 210 FOR T=0 TO 191 215 I=T*IS-ORGI : REM SCALE VERT (IMAGINARY) AXIS 220 C=1 : REM INITIALIZE 225 COLOR 1 : PLOT S,T : REM JUST TO SHOW WHERE CURRENT POINT IS 230 R1=R : I1=I : REM LOCALS FOR ITERATIVE CALCULATIONS 235 IF ABS(R1)<1.0E-49 THEN R1=0 : REM STUPID ATARI TAKES UNDERFLOW TRAPS 236 IF ABS(I1)<1.0E-49 THEN I1=0 239 R12=R1*R1 : I12=I1*I1 : REM SQUARE REAL&IMAG PARTS 240 IF R12+I12>4 THEN 300 : REM CHECK MAGNITUDE. COMPARE TO 4 TO AVOID SQRT 250 R2=R12-I12+R : I2=2*R1*I1+I : REM SQUARE AND ADD IN ORIG VALUE 260 C=C+1 : IF C>15 THEN C=0 : GOTO 300 : COUNT INTERATIONS, TEST TERM VALUE 270 R1=R2 : I1=I2 280 GOTO 235 300 COLOR C 305 PLOT S,T 310 NEXT T 320 NEXT S 400 GOTO 400 Under Turbo, it takes approx. 1 hour to render a screen. The values RS, ORGR and ORGI scale the drawing and select origin coordinates. The values in the program draw most if the Mandelbrot set, but is very slow because of all the black. Some other values: RS ORGR ORGI Picture 1/10 2.5 2.4 Small version of the full set, centered on the screen 1/20 2.5 1.2 Larger version of the set 1/40 1.5 0.6 Full screen of the set, with a little offscreen 1/60 1.4 0.5 Close-up of the upper left corner of the set* * Make sure you do this one! Try it! You will be impressed. Possible bells, whistles, etc.: 1) Save/restore pictures to disk 2) Select and area to blow up, using paddle or joystick 3) "Quick draw" at lower resolution to preview patterns 4) Calculate all 4 points in a gr.11 pixel, and average the result Another thing you may want to know - The patterns get more interesting at higher resolution (smaller and smaller values of RS). As far as I know, more and more detail can be seen at arbitrarily small values. Have fun! -Stan