image[py, px] = MAX_COUNT
            for i in range(MAX_COUNT):
                z = iterate(z)
                if converged(z) > 0:
                    image[py, px] = i
                    break


def colorise(counts):
    counts = np.reshape(counts, (counts.shape[0], counts.shape[1]))
    max_count = int(np.max(counts))
    colormap = make_npcolormap(
        max_count + 1,
        [Color(0), Color('darkblue'),
         Color('yellow'),
         Color(1)], [0.5, 2, 7])
    outarray = np.zeros((counts.shape[0], counts.shape[1], 3), dtype=np.uint8)
    apply_npcolormap(outarray, counts, colormap)
    return outarray


data = make_nparray_data(paint, 600, 600, channels=1)

filename = temp_file('newton-cube-time.dat')
save_nparray(filename, data)
data = load_nparray(filename)

frame = colorise(data)

save_nparray_image('newton-cube-time.png', frame)
from generativepy.nparray import make_nparray_frame, save_nparray, load_nparray
from generativepy.utils import temp_file
from generativepy.movie import save_frame
'''
saving and loading nparray example
'''


def paint(array, pixel_width, pixel_height, frame_no, frame_count):
    array[10:150, 60:300] = [255, 255, 0]


frame = make_nparray_frame(paint, 500, 300)
save_nparray(temp_file("saved-nparray.dat"), frame)
frame2 = load_nparray(temp_file("saved-nparray.dat"))
save_frame(temp_file("save-reload-nparray.png"), frame2)