#%%
import numpy as np
import matplotlib.pyplot as plt 

q,w = (-1.25,0.055)
#zoom = 1 / 1000000
end = 220
res = 150

for k in range (0,end,1):
    #zoom = (1 - (k / end))
    zoom = np.exp(-0.1*k)

    x_min = (q - zoom*2)
    x_max = (q + zoom)

    y_min = (w - zoom)
    y_max = (w + zoom)

    m = int(3 * res)
    n = int(2 * res)

    x = np.linspace(x_min,x_max,num=m).reshape((1,m))
    y = np.linspace(y_min,y_max,num=n).reshape((n,1))

    C = np.tile(x,(n,1)) + 1j * np.tile(y,(1,m))

    Z = np.zeros((n,m), dtype=complex)
    M = np.full((n,m), True, dtype=bool)
    N = np.zeros((n,m))

    for i in range (0,100):
        Z[M] = Z[M] * Z[M] + C[M]
        M[np.abs(Z) > 2] = False
        O = np.logical_not(M)
        P = O.astype(int)
        N[O] = N[O] + P[O]
        print(i)


    im = plt.figure(frameon=False)
    #im = plt.imshow(N, cmap="terrain_r",interpolation="none")
    #im = plt.matshow(N, cmap="binary",interpolation="none")
    im = plt.matshow(N, cmap="hot_r", interpolation="none")
    plt.axis("off")
    plt.savefig("mandel"+ str(k) +".png",
    dpi = res * (3/5),frameon=False,
    bbox_inches="tight", pad_inches=0)
    plt.show(im)

#CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r,
#  Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r,
#  Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r,
#  Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG,
#  PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr,
#  PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu,
#  RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu,
#  RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1,
#  Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral,
#  Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu,
#  YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd,
#  YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r,
#  binary, binary_r, bone, bone_r, brg, brg_r, bwr,
#  bwr_r, cividis, cividis_r, cool, cool_r, coolwarm,
#  coolwarm_r, copper, copper_r, cubehelix,
#  cubehelix_r, flag, flag_r, gist_earth,
#  gist_earth_r, gist_gray, gist_gray_r,
#  gist_heat, gist_heat_r, gist_ncar, gist_ncar_r,
#  gist_rainbow, gist_rainbow_r, gist_stern,
#  gist_stern_r, gist_yarg, gist_yarg_r, gnuplot,
#  gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r,
#  hot, hot_r, hsv, hsv_r, inferno, inferno_r, jet,
#  jet_r, magma, magma_r, nipy_spectral,
#  nipy_spectral_r, ocean, ocean_r, pink, pink_r,
#  plasma, plasma_r, prism, prism_r, rainbow,
#  rainbow_r, seismic, seismic_r, spring, spring_r,
#  summer, summer_r, tab10, tab10_r, tab20, tab20_r,
#  tab20b, tab20b_r, tab20c, tab20c_r, terrain,
#  terrain_r, twilight, twilight_r, twilight_shifted,
#  twilight_shifted_r, viridis, viridis_r, winter,
#  winter_r


# %%


# %%