def gen_image(key, w, h, cre, cim, cmap):
    start = time.perf_counter()
    m = julia_fast.julia_set(w, h, cre + cim*1j)
    end = time.perf_counter()-start
    print('Made a {} x {} image in {} s'.format(w, h, end))

    image_data = np.empty((h,w,3), dtype=np.uint8)
    colors = 255*np.array(getattr(cm,cmap).colors)
    for j, i in product(range(h), range(w)):
        image_data[j, i, :] = colors[m[j,i]]

    image = Image.fromarray(image_data, mode='RGB')

    stream = io.BytesIO()
    image.save(stream, format='png')
    stream.seek(io.SEEK_SET)
    store[key] = stream.read()
Beispiel #2
0
def gen_image(w, h, cre, cim, cmap):
    start = time.perf_counter()
    m = julia_fast.julia_set(w, h, cre + cim * 1j)
    end = time.perf_counter() - start
    print('Made a {} x {} image in {} s'.format(w, h, end))

    image_data = np.empty((h, w, 3), dtype=np.uint8)
    colors = 255 * np.array(getattr(cm, cmap).colors)
    for j, i in product(range(h), range(w)):
        image_data[j, i, :] = colors[m[j, i]]

    image = Image.fromarray(image_data, mode='RGB')

    stream = io.BytesIO()
    image.save(stream, format='png')
    stream.seek(io.SEEK_SET)
    return stream.read()
def gen_image(key, w, h, cre, cim, cmap):
    # This is well designed, but it is not responsive because
    # of the gil.
    start = time.perf_counter()
    m = julia_fast.julia_set(w, h, cre + cim*1j)
    end = time.perf_counter()-start
    
    image_data = np.empty((h,w,3), dtype=np.uint8)
    colors = 255*np.array(getattr(cm, cmap).colors)

    for j,i in product(range(h), range(w)):
        image_data[j,i,:] = colors[m[j,i]]

    image = Image.fromarray(image_data, mode='RGB')
    
    stream = io.BytesIO()
    image.save(stream, format='png')
    stream.seek(io.SEEK_SET)
    print('Made {} x {} image in {} seconds'.format(w, h, end))
    store[key] = stream.read()