Mandelbrot set: Difference between revisions

→‎Python with and without NumPy (no optimizations): Added normalized iteration count for smooth coloring
(Add Cowgol)
(→‎Python with and without NumPy (no optimizations): Added normalized iteration count for smooth coloring)
Line 7,156:
===Python with and without NumPy (no optimizations)===
Actually the same, but without optimizations and therefore better suited for teaching. At first without NumPy, but already with complex numbers.
<lang python>import matplotlib.pyplotmath as pltmt
import matplotlib.pyplot as plt
 
 
def linspace(start, stop, num):
Line 7,168:
 
d, n = 200, 50 # pixel density & number of iterations
r = 2.51000 # escape radius (must be greater than 2)
 
x = linspace(-2.5, 1.5, 4 * d + 1)
Line 7,182:
z = z ** 2 + c
T[i][j] = k + 1
if abs(z) >= r: # normalized iteration count (smooth coloring)
T[i][j] = T[i][j] - mt.log2(mt.log(abs(z)) / mt.log(r))
 
plt.imshow(T, cmap=plt.cm.twilight_shifted)
Line 7,189 ⟶ 7,191:
import matplotlib.pyplot as plt
 
d, n = 200, 50100 # pixel density & number of iterations
r = 2.51000 # escape radius (must be greater than 2)
 
x = np.linspace(-2.5, 1.5, 4 * d + 1)
Line 7,206 ⟶ 7,208:
T[M] = k + 1
 
N = abs(Z) >= r # normalized iteration count (smooth coloring)
plt.imshow(T, cmap=plt.cm.twilight_shifted)
T[N] = T[N] - np.log2(np.log(abs(Z[N])) / np.log(r))
 
plt.imshow(T ** 0.5, cmap=plt.cm.twilight_shifted)
plt.savefig("Mandelbrot.png", dpi=250)</lang>
 
305

edits