Mandelbrot set: Difference between revisions
Content deleted Content added
→{{header|TeX}}: Separated solutions by language and minimalised. |
→Python with and without NumPy (no optimizations): Heading changed: Escape time and normalized iteration count (Basic) |
||
Line 7,154: | Line 7,154: | ||
plt.show()</lang> |
plt.show()</lang> |
||
===Basic: Escape time and normalized iteration count=== |
|||
===Python with and without NumPy (no optimizations)=== |
|||
Actually the same, but without optimizations and therefore better suited for teaching. At first without NumPy, but already with complex numbers. |
Actually the same, but without optimizations and therefore better suited for teaching. At first without NumPy, but already with complex numbers. |
||
<lang python>import |
<lang python>import matplotlib.pyplot as plt |
||
import matplotlib.pyplot as plt |
|||
Line 7,183: | Line 7,182: | ||
z = z ** 2 + c |
z = z ** 2 + c |
||
T[i][j] = k + 1 |
T[i][j] = k + 1 |
||
if abs(z) >= r: # normalized iteration count (smooth coloring) |
|||
T[i][j] = T[i][j] - mt.log2(mt.log(abs(z)) / mt.log(r)) |
|||
plt.imshow(T, cmap=plt.cm.twilight_shifted) |
plt.imshow(T, cmap=plt.cm.twilight_shifted) |
||
plt.savefig("Mandelbrot.png", dpi=250)</lang> |
plt.savefig("Mandelbrot.png", dpi=250)</lang> |
||
At second with NumPy and complex matrices. The ''normalized iteration count'' algorithm is used, which provides a smooth transition of colors between iterations (cf. Wikipedia: [https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Continuous_(smooth)_coloring ''Plotting algorithms for the Mandelbrot set: Continuous (smooth) coloring'']). |
|||
At second with NumPy and complex matrices. |
|||
<lang python>import numpy as np |
<lang python>import numpy as np |
||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |