Advertisement
Procy0n

Unit 1, Mandelbrot (Python, v2)

Jul 22nd, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. # Limit for maximum iterations
  2. MAX_ITER = 256
  3. SYMBOLS = ".:coCO8@"
  4.  
  5.    
  6. height = input("Enter size of the fractal (height and width)\n")
  7. width = input()
  8.  
  9. for y in range(height):
  10.     line = []
  11.  
  12.     for x in range(width):
  13.         x0 = (3.5 / width) * x - 2.5
  14.         y0 = (2.0 / height) * y - 1
  15.         xi = yi = 0.0
  16.         iteration = 0
  17.  
  18.         while xi*xi + yi*yi < 4 and iteration < MAX_ITER:
  19.             xtemp = xi*xi - yi*yi + x0
  20.             yi = 2*xi*yi + y0
  21.             xi = xtemp
  22.             iteration += 1
  23.  
  24.         if (iteration == MAX_ITER):
  25.             line.append(" ")
  26.         else:
  27.             line.append(SYMBOLS[(iteration - 1) % 8])
  28.  
  29.     print "".join(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement