'''This program visualises a Julia set (cf. Chapter 9.3).
The axis window is defined by means of the following parameters:
ux = smallest x-coordinate
ox = largest x-coordinate
nx = number of grid points on the x-axis
uy = smallest x-coordinate
oy = largest x-coordinate
ny = number of grid points on the y-axis
The parameter kmax determines the number of iterations.
The parameter c has the same meaning as in the textbook.
'''
import numpy as np
import matplotlib.pyplot as plt
ux, ox, nx = -1.8, 1.8, 400
uy, oy, ny = -1.15, 1.15, 255
x = np.linspace(ux, ox, nx)
y = np.linspace(uy, oy, ny)
xx, yy = np.meshgrid(x, y)
z = xx + yy*1j # z is initialized as the complex plane
c = -1.25
'''Some example values for c you might want to try.'''
# c = -0.75
# c = 0.35+0.35j
# c = -0.03+0.655j
# c = -0.12+0.74j
# c = 0.365-0.3j
kmax = 80 # Increase this number to improve the quality of the plot
'''This will cause some runtime warnings, which can be ignored.
The computation might take a few seconds to compute.
'''
for k in range(kmax):
z = np.power(z,2) + c
z = np.fmin(100,abs(z))
fig = plt.figure()
plt.pcolormesh(xx, yy, z, edgecolor='white', linewidth='0')
plt.gray()
plt.show()