By now you have seen the plotter code we have prepared for you, and you have even played with it a bit. Below we copy it so we can use it again in this notebook, but we will also provide you with a way to use custom color maps (a.k.a. color schemes).

In [1]:
using Plots

function mandelbrot_law(current_state, parameter)
    next_state = current_state^2+parameter 
    return next_state
end

function mandelbrot_when_explodes(parameter, length) 
    current_state = 0
    for i in 2:length
        new_state = mandelbrot_law(current_state, parameter)
        if abs(new_state) > 20
            return i
        else
            current_state = new_state
        end
    end
    return length
end

function get_grid_of_coordinates(rmin,rmax,imin,imax,step)
    real_coordinate = rmin:step:rmax
    imag_coordinate = imin:step:imax
    grid_of_complex_coordinates = zeros(ComplexF64, length(imag_coordinate), length(real_coordinate))

    for i_real in 1:length(real_coordinate)
        for i_imag in 1:length(imag_coordinate)
            grid_of_complex_coordinates[i_imag,i_real] = real_coordinate[i_real] + 1im * imag_coordinate[i_imag]
        end
    end
    return grid_of_complex_coordinates
end

function plot_mandelbrot(rmin,rmax,imin,imax,step,length)
    grid_of_complex_coordinates = get_grid_of_coordinates(rmin,rmax,imin,imax,step)
    heatmap(rmin:step:rmax,imin:step:imax, mandelbrot_when_explodes.(grid_of_complex_coordinates, length), ratio=1)
end