import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mplcolors
width = 256
height = 256
length = 40
maxiter = 40
fig = plt.figure(figsize=(float(width)/100, float(height)/100), edgecolor='k')
fig.subplots_adjust(left=0.0, right=1.0, top=1.0, bottom=0.0, wspace=0.0, hspace=0.0)
ax = fig.add_subplot(111)
x1 = -1.0
x2 = 1.0
y1 = (x1 - x2)/2 * float(height)/width
y2 = (x2 - x1)/2 * float(height)/width
y, x = np.ogrid[y1:y2:height*1j, x1:x2:width*1j]
cdict = {'red': ((0.0, 0.4, 0.4),
(0.5, 0.7, 0.7),
(1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0),
(0.5, 1.0, 1.0),
(1.0, 1.0, 1.0)),
'blue': ((0.0, 1.0, 1.0),
(0.5, 1.0, 1.0),
(1.0, 1.0, 1.0))}
my_cmap = mplcolors.LinearSegmentedColormap('my_colormap', cdict, 256)
for n in xrange(length):
t = float(n+1)/length
e = np.exp(2*np.pi*t*1j)
c = e/2*(1-e/2)
z = x + y*1j
divtime = maxiter + np.zeros(z.shape, dtype=int)
for k in xrange(maxiter):
z = z*z + c
diverge = z*np.conj(z) > 4
div_now = diverge & (divtime == maxiter)
divtime[div_now] = k
z[diverge] = 2
ax.cla()
ax.imshow(divtime, cmap=my_cmap)
ax.axis('off')
filename = 'JuliaSet_{:03}.png'.format(n+1)
fig.savefig(filename)