Mandelbrot set: Difference between revisions

Content added Content deleted
m (→‎{{header|Python}}: Minor change (save picture))
(→‎{{header|Python}}: a more mathematical spelling, as the students are used to it.)
Line 6,394: Line 6,394:
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt


n = 50 # number of iterations
dots = 100
r = 2.5 # escape radius (must be greater than 2)
iterations = 50


x = np.linspace(-2.0, 1.0, 3 * dots + 1)
x = np.linspace(-2.5, 1.5, 401)
y = np.linspace(-1.0, 1.0, 2 * dots + 1)
y = np.linspace(-1.5, 1.5, 301)


A, B = np.meshgrid(x, y)
A, B = np.meshgrid(x, y)
C = A + B * 1j


C = A + B * 1j
Z = np.zeros_like(C)
Z = np.zeros_like(C)
T = np.zeros(C.shape)


M = abs(Z) < r
escape_radius = 2.1 # must be greater than 2
for k in range(n):
escape_table = np.zeros(Z.shape)
Z[M] = Z[M] ** 2 + C[M]

not_escaped = abs(Z) < escape_radius
M = abs(Z) < r
T[M] = k + 1

for i in range(iterations):
Z[not_escaped] = Z[not_escaped] ** 2 + C[not_escaped]
not_escaped = abs(Z) < escape_radius
escape_table[not_escaped] = i + 1


plt.imshow(escape_table, cmap=plt.cm.twilight_shifted)
plt.imshow(T, cmap=plt.cm.twilight_shifted)
plt.savefig("image.png", dpi=150)</lang>
plt.savefig('image.png', dpi=200)</lang>


=={{header|R}}==
=={{header|R}}==