Julia set: Difference between revisions
Content deleted Content added
→Vectorized: Improved algorithm - >3 times faster |
|||
Line 1,451: | Line 1,451: | ||
[https://imgur.com/a/o3j9Zzn Example output.] |
[https://imgur.com/a/o3j9Zzn Example output.] |
||
<lang python>""" |
<lang python>""" |
||
Solution from: |
|||
This solution is an improved version of an efficient Julia set solver |
|||
https://codereview.stackexchange.com/questions/210271/generating-julia-set |
|||
from: |
|||
'Bauckhage C. NumPy/SciPy Recipes for Image Processing: |
|||
Creating Fractal Images. researchgate. net, Feb. 2015.' |
|||
""" |
""" |
||
from functools import partial |
from functools import partial |
||
Line 1,493: | Line 1,491: | ||
:return: 2D pixels array of intensities |
:return: 2D pixels array of intensities |
||
""" |
""" |
||
⚫ | |||
imaginary_axis, real_axis = np.ogrid[ |
|||
min_coordinate.real: max_coordinate.real: width * 1j] |
|||
z = (re + 1j * im).flatten() |
|||
⚫ | |||
complex_plane = real_axis + 1j * imaginary_axis |
|||
live, = np.indices(z.shape) # indexes of pixels that have not escaped |
|||
iterations = np.empty_like(z, dtype=int) |
|||
for |
for i in range(iterations_count): |
||
z_live = z[live] = mapping(z[live]) |
|||
escaped = abs(z_live) > threshold |
|||
iterations[live[escaped]] = i |
|||
live = live[~escaped] |
|||
if live.size == 0: |
|||
break |
break |
||
else: |
|||
complex_plane[mask] = mapping(complex_plane[mask]) |
|||
iterations[live] = iterations_count |
|||
return |
return iterations.reshape((height, width)) |
||
Line 1,521: | Line 1,522: | ||
plt.axis('off') |
plt.axis('off') |
||
plt.imshow(image, |
plt.imshow(image, |
||
cmap=' |
cmap='nipy_spectral_r', |
||
origin='lower') |
origin='lower') |
||
plt.show() |
plt.show() |