Ensemble de Mandelbrot

L'ensemble de Mandelbrot

import numpy as np
import matplotlib.pyplot as plt
from numba import jit

@jit
def duree_de_vie(c,N=256):
    z=c
    duree = 0
    j=0
    while (j<N and abs(z)<=2):
        z=z*z+c
        duree+=1
        j+=1
    return duree % N

@jit
def mandelbrot(N=256,res=256,xc=0,yc=0,delta=2):
    x=np.linspace(xc-delta,xc+delta,res)
    y=np.linspace(yc-delta,yc+delta,res)
    dessin = np.zeros((res,res))
    for k in range(res):
        for l in range(res):
            dessin[k,l] = duree_de_vie(x[l]+y[k]*1j,N)
    return dessin

@jit
def main():
    N=128
    res=1024
    xc=0; yc=0; delta=2 #mandelbrot
    # xc,yc,delta=-.75,0.1,.01 #hippocampes
    # xc,yc,delta=.275,0,.01 #Elephants
    # xc,yc,delta=-.088,0.654,.01 #Spirales triples
    # xc,yc,delta=.274,0.482,.01 #Spirales quadruples
    # xc,yc,delta=-1.36,0.005,.02 #Sceptres
    # xc,yc,delta=-.1002,0.8383,.005 #Doubles sceptres
    # xc,yc,delta=-1.108,0.230,.01 #Sceptres
    # xc,yc,delta=-1.75,0,.05 #Mini Mandelbrot
    # xc,yc,delta=-.1592,-1.0317,.01 #Mini Mandelbrot
    # xc,yc,delta = -1.7112,0,0.0005 # test
    dessin=mandelbrot(N,res,xc,yc,delta)
    plt.clf()
    plt.imshow(dessin, cmap='nipy_spectral')
    plt.colorbar()
    plt.draw()
    plt.show()

def zoom_mini_mb():
    N=128
    res=500
    xc,yc=-.1592,-1.0317 #Mini Mandelbrot
    delta = np.geomspace(1,0.01,num=100)
    for i in range(len(delta)):
        dessin=mandelbrot(N,res,xc,yc,delta[i])
        plt.clf()
        plt.imshow(dessin, cmap='nipy_spectral')
        plt.draw()
        plt.pause(.01)
    plt.show()

main()
# zoom_mini_mb()