Mandelbrot set: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Cowgol) |
(→Python with and without NumPy (no optimizations): Added normalized iteration count for smooth coloring) |
||
Line 7,156: | Line 7,156: | ||
===Python with and without NumPy (no optimizations)=== |
===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 math as mt |
||
import matplotlib.pyplot as plt |
|||
def linspace(start, stop, num): |
def linspace(start, stop, num): |
||
Line 7,168: | Line 7,168: | ||
d, n = 200, 50 # pixel density & number of iterations |
d, n = 200, 50 # pixel density & number of iterations |
||
r = |
r = 1000 # escape radius (must be greater than 2) |
||
x = linspace(-2.5, 1.5, 4 * d + 1) |
x = linspace(-2.5, 1.5, 4 * d + 1) |
||
Line 7,182: | 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) |
||
Line 7,189: | Line 7,191: | ||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
||
d, n = 200, |
d, n = 200, 100 # pixel density & number of iterations |
||
r = |
r = 1000 # escape radius (must be greater than 2) |
||
x = np.linspace(-2.5, 1.5, 4 * d + 1) |
x = np.linspace(-2.5, 1.5, 4 * d + 1) |
||
Line 7,206: | Line 7,208: | ||
T[M] = k + 1 |
T[M] = k + 1 |
||
N = abs(Z) >= r # normalized iteration count (smooth coloring) |
|||
⚫ | |||
T[N] = T[N] - np.log2(np.log(abs(Z[N])) / np.log(r)) |
|||
⚫ | |||
plt.savefig("Mandelbrot.png", dpi=250)</lang> |
plt.savefig("Mandelbrot.png", dpi=250)</lang> |
||