-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMandelbrot.py
89 lines (71 loc) · 2.77 KB
/
Mandelbrot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from numpy import *
from matplotlib import pyplot as plt
def mandelbrot( h,w, maxit=40): #20
'''
Returns an image of the Mandelbrot fractal of size (h,w).
'''
y,x = ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ]
#y,x = ogrid[ -0.25:0.25:h*1j, -1.8:-1.3:w*1j ]
#y,x = ogrid[ -0.05:0.05:h*1j, -1.5:-1.4:w*1j ]
c = x+y*1j
z = c
divtime = maxit + zeros(z.shape, dtype=int)
for i in xrange(maxit):
z = z**2 + c
diverge = z*conj(z) > 2**2 # who is diverging
div_now = diverge & (divtime==maxit) # who is diverging now
divtime[div_now] = i +100 # note when
z[diverge] = 2 # avoid diverging too much
return divtime
def mandelbrot2( h,w,a=-2.,b=.8,c=-1.4,d=1.4, maxit=40): #20
'''
Returns an image of the Mandelbrot fractal of size (h,w).
'''
y,x = ogrid[ c:d:h*1j, a:b:w*1j ]
# y,x = ogrid[ -0.25:0.25:h*1j, -1.8:-1.3:w*1j ]
#y,x = ogrid[ -0.05:0.05:h*1j, -1.5:-1.4:w*1j ]
c = x+y*1j
z = c
divtime = maxit + zeros(z.shape, dtype=int)
for i in xrange(maxit):
z = z**2 + c
diverge = z*conj(z) > 2**2 # who is diverging
div_now = diverge & (divtime==maxit) # who is diverging now
divtime[div_now] = i +100 # note when
z[diverge] = 2 # avoid diverging too much
return divtime
#fig = plt.figure(figsize=(15,15))
plt.figure(figsize=(20,20))
#fig = plt.subplot(4,1,1)#,figsize=(20,20))
plt.imshow(mandelbrot2(1000,1000))
#s = "The Mandelbrot Set ([-2.0,0.8]x[-1.4,1.4], iterations = 40)"
#s = "The Mandelbrot Set ([-1.8,-1.3]x[-0.25,0.25], iterations = 40)"
s = "The Mandelbrot Set ([-1.5,-1.4]x[-0.05,0.05], iterations = 40)"
#plt.subplot(4,1,1).
plt.title(s)
plt.axis('off')
##fig = plt.figure(figsize=(15,15))
##fig = plt.subplot(4,1,2)
# plt.figure(figsize=(20,20))
# plt.imshow(mandelbrot2(1000,1000,-1.8,-1.3,-.25,0.25))
# s = "The Mandelbrot Set ([-1.8,-1.3]x[-0.25,0.25], iterations = 40)"
# #plt.subplot(4,1,2).
# plt.title(s)
# plt.axis('off')
# plt.figure(figsize=(20,20))
# #fig = plt.figure(figsize=(15,15))
# #fig = plt.subplot(4,1,3)
# plt.imshow(mandelbrot2(1000,1000,-1.5,-1.4,-0.05,0.05))
# s = "The Mandelbrot Set ([-1.5,-1.4]x[-0.05,0.05], iterations = 40)"
# #plt.subplot(4,1,3).
# plt.title(s)
# plt.axis('off')
# plt.figure(figsize=(20,20))
#fig = plt.figure(figsize=(15,15))
#fig = plt.subplot(4,1,4)
plt.imshow(mandelbrot2(1000,1000,-1.,-.6,0.,0.4))
s = "The Mandelbrot Set ([0,0.4]x[-1.,-0.6], iterations = 40)"
#plt.subplot(4,1,4).
plt.title(s)
plt.axis('off')
plt.show()