Advertisement
Procy0n

Unit 1, Mandelbrot (Python, v3)

Jul 22nd, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 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. def c(x, y):
  10.     x0 = (3.5 / width) * x - 2.5
  11.     y0 = (2.0 / height) * y - 1
  12.     xi = yi = iteration = 0
  13.  
  14.     while xi**2 + yi**2 < 4 and iteration < MAX_ITER:
  15.         xtemp = xi**2 - yi**2 + x0
  16.         yi = 2*xi*yi + y0
  17.         xi = xtemp
  18.         iteration += 1
  19.  
  20.     if (iteration == MAX_ITER):
  21.         return " "
  22.     return SYMBOLS[(iteration - 1) % 8]
  23.  
  24. for y in range(height):
  25.     print "".join([c(x, y) for x in range(width)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement