[Home]MandelbrotSet/ChrisHowlettPython

ec2-3-14-70-203.us-east-2.compute.amazonaws.com | ToothyWiki | MandelbrotSet | RecentChanges | Login | Webcomic

This assumes being run in a console window at least 80 characters wide, and at least 40 long (such as a Windows DOS prompt).

import sys
X_SIZE = 79.0
Y_SIZE = 40.0

X_MIN = -2.2
X_MAX = 1.0
Y_MIN = -1.5
Y_MAX = 1.5

DIVERGE_LOOKUP = [' ', '.', ',', ',', ',', '-', '-', '-', '-', '-',
                  '+', '+', '+', '+', '%', '%', '%', '%',
                  '@', '@', '@', '@', '#', '#', '#']

LIMIT = 25

dx = (X_MAX - X_MIN) / X_SIZE
dy = (Y_MAX - Y_MIN) / Y_SIZE

x = X_MIN
y = Y_MIN

while y < Y_MAX:
  while x < X_MAX:
    zr = x
    zi = y
    iter = 0
    while (iter < LIMIT and ((zr * zr + zi * zi) < 16)):
      zrn = zr * zr - zi * zi + x
      zin = 2 * zr * zi + y
      zr = zrn
      zi = zin
      iter += 1

    if iter >= LIMIT:
      sys.stdout.write(' ')
    else:
      sys.stdout.write(DIVERGE_LOOKUP[iter])

    x += dx

  sys.stdout.write('\n')
  x = X_MIN
  y += dy


ec2-3-14-70-203.us-east-2.compute.amazonaws.com | ToothyWiki | MandelbrotSet | RecentChanges | Login | Webcomic
This page is read-only | View other revisions | Recently used referrers
Last edited November 25, 2008 8:57 am (viewing revision 1, which is the newest) (diff)
Search: