In this recipe, we will combine the famous Mandelbrot fractal (see http://en.wikipedia.org/wiki/Mandelbrot_set) and the image of Lena. The Mandelbrot set was invented by the mathematician Benoit Mandelbrot. These types of fractals are defined by a recursive formula, where you calculate the next complex number in a series by multiplying the current complex number you have by itself and adding a constant to it. More details will be covered in this recipe.
Install SciPy if necessary. The See also section has a reference to the related recipe.
Start by initializing the arrays, followed by generating and plotting the fractal, and finally combining the fractal with the Lena image:
Initialize the
x
,y
, andz
arrays, corresponding to the pixels in the image area with themeshgrid()
,zeros()
, andlinspace()
functions:x, y = np.meshgrid(np.linspace(x_min, x_max, SIZE), np.linspace(y_min, y_max, SIZE)) c = x + 1j * y z = c.copy() fractal...