Julia集合でも見て、ちょっと休憩。
julia.py
import numpy as np
import matplotlib.pyplot as plt
def julia_set(h, w, max_iter):
y, x = np.ogrid[-1.4:1.4:h*1j, -2:2:w*1j]
c = -0.7 + 0.27j
z = x + y*1j
divtime = max_iter + np.zeros(z.shape, dtype=int)
for i in range(max_iter):
z = z**2 + c
diverge = z*np.conj(z) > 2**2
div_now = diverge & (divtime == max_iter)
divtime[div_now] = i
z[diverge] = 2
return divtime
h, w = 1000, 1500
max_iter = 100
plt.figure(figsize=(12, 8))
plt.imshow(julia_set(h, w, max_iter), cmap='gist_earth', extent=[-2, 2, -1.4, 1.4])
plt.colorbar()
plt.title('Julia Set')
plt.xlabel('Re(z)')
plt.ylabel('Im(z)')
plt.tight_layout()
plt.show()