Exemple #1
0
def update_mandelbrot_set():
    """
    updates the raw data of the mandelbrot set corresponding to the current user input. Therefore the currently observed
    part of the mandelbrot set is computed using the given maximum iteration number. The output data is written to the
    corresponding bokeh.models.ColumnDataSource
    """
    view_data = my_bokeh_utils.get_user_view(plot)

    x0 = view_data['x_start'][0]
    xw = view_data['x_end'][0] - x0
    y0 = view_data['y_start'][0]
    yw = view_data['y_end'][0] - y0

    print "calculating mandelbrot set."
    mandel_iterations = mandel.mandel(
        x0,
        y0,
        xw,
        yw,  # user view
        mandelbrot_settings.x_res,
        mandelbrot_settings.y_res,  # resolution
        slider_max_iterations.value,  # maximum number of iterations
        mandelbrot_settings.iteration_bound)
    print "done."

    print "updating raw data."
    source_mandel_raw.data = dict(its=[mandel_iterations],
                                  max_iter=[int(slider_max_iterations.value)])
    print "data was updated."
def update_mandelbrot_set():
    """
    updates the raw data of the mandelbrot set corresponding to the current user input. Therefore the currently observed
    part of the mandelbrot set is computed using the given maximum iteration number. The output data is written to the
    corresponding bokeh.models.ColumnDataSource
    """
    view_data = my_bokeh_utils.get_user_view(plot)

    x0 = view_data['x_start'][0]
    xw = view_data['x_end'][0] - x0
    y0 = view_data['y_start'][0]
    yw = view_data['y_end'][0] - y0

    print "calculating mandelbrot set."
    mandel_iterations = mandel.mandel(x0, y0, xw, yw,  # user view
                                      mandelbrot_settings.x_res, mandelbrot_settings.y_res,  # resolution
                                      slider_max_iterations.value,  # maximum number of iterations
                                      mandelbrot_settings.iteration_bound)
    print "done."

    print "updating raw data."
    source_mandel_raw.data = dict(its=[mandel_iterations], max_iter=[int(slider_max_iterations.value)])
    print "data was updated."
Exemple #3
0
from pylab import *
from numpy import NaN
from mandel import mandel

X = arange(-2, .5, .002)
Y = arange(-1, 1, .002)
Z = zeros((len(Y), len(X)))

for iy, y in enumerate(Y):
    print(iy, "of", len(Y))
    for ix, x in enumerate(X):
        v = mandel(x, y)
        if v >= 0:
            Z[iy, ix] = v
        else:
            Z[iy, ix] = NaN

imshow(Z,
       cmap=plt.cm.prism,
       interpolation='none',
       extent=(X.min(), X.max(), Y.min(), Y.max()))
xlabel("Re(c)")
ylabel("Im(c)")
savefig("mandelbrot_python.svg")
show()
from ppci.wasm import instantiate, read_wasm

import mandel
import x
import time

with open('mandel.wasm', 'rb') as f:
    module = read_wasm(f)

inst = instantiate(module, {'x': {'putc': x.putc}})

print(inst)
print('python -> wasm -> native code mandel:')
t1 = time.time()
inst.exports['mandel']()
t2 = time.time()

print('Python mandel:')
t3 = time.time()
mandel.mandel()
t4 = time.time()

dt_native = t2 - t1
dt_python = t4 - t3
print('native took:', dt_native, 'python took:', dt_python, 'speedup', dt_python / dt_native)

d = 3
frequency = 16
max_iterations = 10000
iteration_bound = 100
median_filtering_size = 0
gauss_filtering_sigma = 0.1

x0 = cx-d*.5
y0 = cy-d*.5
xw = d
yw = d

### main process starts here. ###

# calculate mandelbrot set
it_count = mandel.mandel(x0, y0, xw, yw, x_res, y_res, max_iterations, iteration_bound)

# apply some filters
if median_filtering_size is not 0:
    it_count = median_filter(it_count, size=median_filtering_size)
if gauss_filtering_sigma is not 0:
    it_count = gaussian_filter(it_count, sigma=gauss_filtering_sigma)

color = mandel_colormap.iteration_count_to_rgb_color(it_count, frequency, max_iterations)
print color.shape

# plot and save picture
img = smp.toimage(color) # Create a PIL image
img.save(name)
img.show()
d = 3
frequency = 16
max_iterations = 10000
iteration_bound = 100
median_filtering_size = 0
gauss_filtering_sigma = 0.1

x0 = cx - d * .5
y0 = cy - d * .5
xw = d
yw = d

### main process starts here. ###

# calculate mandelbrot set
it_count = mandel.mandel(x0, y0, xw, yw, x_res, y_res, max_iterations,
                         iteration_bound)

# apply some filters
if median_filtering_size is not 0:
    it_count = median_filter(it_count, size=median_filtering_size)
if gauss_filtering_sigma is not 0:
    it_count = gaussian_filter(it_count, sigma=gauss_filtering_sigma)

color = mandel_colormap.iteration_count_to_rgb_color(it_count, frequency,
                                                     max_iterations)
#print(color.shape)

# plot and save picture
img = smp.toimage(color)  # Create a PIL image
img.save(name)
img.show()
"""
Plot Mandelbrot
================

Plot the Mandelbrot ensemble.

"""

import numpy as np
import mandel
x = np.linspace(-1.7, 0.6, 1000)
y = np.linspace(-1.4, 1.4, 1000)
c = x[None,:] + 1j*y[:,None]
z = mandel.mandel(c, c)

import matplotlib.pyplot as plt
plt.imshow(abs(z)**2 < 1000, extent=[-1.7, 0.6, -1.4, 1.4])
plt.gray()
plt.show()