mandprog

The Mandelbrot set is perhaps the world's best known fractal. It consists of a mapping of all
of the Julia sets. Each number is composed of a real and imaginary part in the form a+bi,
where i is the square root of -1. Take any such number, square it, add it to itself, square it,
add it to itself, and repeat this process ad infinitum. If the result runs to infinity then ignore it.
If it stays below that, basically within 2, then graph it is a Julia set. All of these sets graphed
form the Mandelbrot set, named after Benoit Mandelbrot who is, along with Lorenz and
others, one of the best known chaoticians.

The following program is for C and is written by S.J. Mattie Thompson.

Mandelbrot set program code

PROGRAM MANDELBROT

!--------------------------------------------------------
!  Generate the Mandelbrot set.
!
!  Author:  S.J. Mattie Thompson
!  Date:  April 28, 1993
!  Updated July 06, 1994 for the MacIntosh IIci
!-------------------------------------------------------------------------------

          CALL INITIAL (NX, NY, XL, XR, YB, YT, NITER)
          LET DY = (YT - YB)/NY
          LET DX = (XR - XL)/NX
          FOR J = 1 to NY
              LET Y = YB + (J - 1)*DY
              FOR I = 1 to NX
                  LET X = XL + (I - 1)*DX 
                  CALL CONVERGE (X, Y, NITER, ICOUNT)
                  CALL PLOT_POINT (X, Y, ICOUNT)
              NEXT I
          NEXT J
      END

      SUB INITIAL (NX, NY, XL, XR, YB, YT, NITER)



          ASK PIXELS NX, NY
          ASK MAX COLOR COLOR_MAX
          INPUT PROMPT "XMIN = ": XL
          INPUT PROMPT "XMAX = ": XR
          INPUT PROMPT "YMIN = ": YB
          INPUT PROMPT "YMAX = ": YT
          LET NITER = COLOR_MAX - 4
          LET SCALE = (NX/NY - 1)*(YT - YB)
          LET XL = XL - SCALE/2
          LET XR = XR + SCALE/2
          CLEAR
          SET WINDOW XL, XR, YB, YT
          SET BACK "black"

      END SUB

      SUB CONVERGE (X, Y, NITER, ICOUNT)

          LET CX = 0
          LET CY = 0
          LET ZX = 0
          LET ZY = 0
          LET ZABS = 0
          LET ICOUNT = 0
          FOR K = 1 to NITER
              LET ZX = CX*CX + CY*CY + X
              LET ZY = 2*CX*CY + Y
              LET ZABS = SQR(ZX*ZX + ZY*ZY)
              IF (ZABS > 2) THEN
                  LET ICOUNT = ICOUNT + 1
                  EXIT SUB
              END IF
              LET CX = ZX
              LET CY = ZY
              LET ICOUNT = ICOUNT + 1
          NEXT K

      END SUB

      SUB PLOT_POINT (X, Y, ICOUNT)



          SET COLOR ICOUNT + 4
          PLOT POINTS: X, Y


END SUB

 

 

This program is written by S.J. Mattie Thompson.