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
|
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import time
# c-mesh limits
limitre = ( -2, 1 )
limitim = ( -1.5, 1.5 )
def lota(c, T, l):
z = 0
for i in range(l):
nz = z*z + c
# Check if we found or z
if np.abs(nz) > T:
break
z = nz
else:
# If we did not find z, use l
return l
return np.abs(z)
def mangel(pre, pim, T, l):
# Preallocate result array and z array
rs = np.zeros((pre, pim))
z = np.zeros((pre, pim))
# Calculate C matrix
re = np.linspace(limitre[0], limitre[1], pre)
im = np.linspace(limitim[0], limitim[1], pim)
# Calculate C by multiplying the scalers in. Remember to move it to the beggining og the c-mesh limit
grid = np.add.outer(re, 1j * im)
for i in range(l):
z = z*z + grid
# Extract all the ones that are under the threshold
below = (np.abs(z) < T)
rs += below
rs[ rs==rs.max() ] = l
rs /= l
return rs
start = time.time()
arr = mangel(500, 500, 2, 100)
end = time.time()
plt.imshow(arr, cmap=plt.cm.hot, vmin=0, vmax=1)
plt.savefig("test.png")
plt.savefig("test.pdf")
print(f"Took {end - start} seconds")
|