2018-10-03 18:59:01 +00:00
|
|
|
# setup: N=10
|
|
|
|
# run: julia(1., 1., N, 1.5, 10., 1e4)
|
2018-04-05 22:07:33 +00:00
|
|
|
|
2018-10-03 18:59:01 +00:00
|
|
|
# pythran export julia(float, float, int, float, float, float)
|
2018-04-05 22:07:33 +00:00
|
|
|
import numpy as np
|
2018-10-03 18:59:01 +00:00
|
|
|
|
2018-04-05 22:07:33 +00:00
|
|
|
|
|
|
|
def kernel(zr, zi, cr, ci, lim, cutoff):
|
2020-06-28 18:24:40 +00:00
|
|
|
""" Computes the number of iterations `n` such that
|
2018-04-05 22:07:33 +00:00
|
|
|
|z_n| > `lim`, where `z_n = z_{n-1}**2 + c`.
|
2020-06-28 18:24:40 +00:00
|
|
|
"""
|
2018-04-05 22:07:33 +00:00
|
|
|
count = 0
|
2018-10-03 18:59:01 +00:00
|
|
|
while ((zr * zr + zi * zi) < (lim * lim)) and count < cutoff:
|
2018-04-05 22:07:33 +00:00
|
|
|
zr, zi = zr * zr - zi * zi + cr, 2 * zr * zi + ci
|
|
|
|
count += 1
|
|
|
|
return count
|
|
|
|
|
2018-10-03 18:59:01 +00:00
|
|
|
|
2020-06-28 18:24:40 +00:00
|
|
|
def julia(cr, ci, N, bound=1.5, lim=1000.0, cutoff=1e6):
|
|
|
|
""" Pure Python calculation of the Julia set for a given `c`. No NumPy
|
2018-04-05 22:07:33 +00:00
|
|
|
array operations are used.
|
2020-06-28 18:24:40 +00:00
|
|
|
"""
|
2018-04-05 22:07:33 +00:00
|
|
|
julia = np.empty((N, N), np.uint32)
|
|
|
|
grid_x = np.linspace(-bound, bound, N)
|
|
|
|
for i, x in enumerate(grid_x):
|
|
|
|
for j, y in enumerate(grid_x):
|
2018-10-03 18:59:01 +00:00
|
|
|
julia[i, j] = kernel(x, y, cr, ci, lim, cutoff)
|
2018-04-05 22:07:33 +00:00
|
|
|
return julia
|