-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.py
51 lines (43 loc) · 1.18 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
import numpy
from numba import jit
import matplotlib.pyplot as plt
import time
from tqdm import tqdm
def time_it(func):
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args,**kwargs)
end = time.time()
print(func.__name__ +" took " + str((end-start)*1000) + " ms")
return result
return wrapper
@jit
#@jit(nopython=True, parallel=True)
def mandelbrot(Re,Im,max_iter):
c=complex(Re,Im)
z=0.0j
for i in range(max_iter):
z=z*z+c
if(z.real*z.real+z.imag*z.imag)>=4:
return i
return max_iter
dim=2000
columns=dim
rows=dim
iterration=1000
result=numpy.zeros([rows,columns])
@time_it
#@jit
def main():
for row_index, Re in enumerate(tqdm(numpy.linspace(-2,1, num=rows))):
for column_index, Im in enumerate(numpy.linspace(-1,1,num=columns)):
result[row_index,column_index]=mandelbrot(Re,Im,iterration)
print("Dimensions :",dim," * ",dim)
print("Itération : ",iterration)
main()
plt.figure(dpi=150)
plt.imshow(result.T, cmap='hot',interpolation='bilinear',extent=[-2,1,-1,1])
plt.xlabel("Re")
plt.ylabel("Im")
plt.title("Figure de Mandelbrot")
plt.show()