Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
30
Task/Mandelbrot-set/Python/mandelbrot-set-5.py
Normal file
30
Task/Mandelbrot-set/Python/mandelbrot-set-5.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def linspace(start, stop, num):
|
||||
return [start + (stop - start) / (num - 1) * k for k in range(num)]
|
||||
|
||||
|
||||
def zeros(rows, cols):
|
||||
return [[0 for j in range(cols)] for i in range(rows)]
|
||||
|
||||
|
||||
d, n = 100, 50 # pixel density & number of iterations
|
||||
r = 2.5 # escape radius (must be greater than 2)
|
||||
|
||||
x = linspace(-2.5, 1.5, 4 * d + 1)
|
||||
y = linspace(-1.5, 1.5, 3 * d + 1)
|
||||
|
||||
T = zeros(len(y), len(x))
|
||||
|
||||
for i, b in enumerate(y):
|
||||
for j, a in enumerate(x):
|
||||
u, v = 0.0, 0.0
|
||||
for k in range(n):
|
||||
u, v = u ** 2 - v ** 2 + a, 2 * u * v + b
|
||||
if not u ** 2 + v ** 2 < r ** 2:
|
||||
break
|
||||
T[i][j] = k + 1
|
||||
|
||||
plt.imshow(T, cmap=plt.cm.twilight_shifted)
|
||||
plt.savefig("mandelbrot.png", dpi=200)
|
||||
22
Task/Mandelbrot-set/Python/mandelbrot-set-6.py
Normal file
22
Task/Mandelbrot-set/Python/mandelbrot-set-6.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
d, n = 100, 50 # pixel density & number of iterations
|
||||
r = 2.5 # escape radius (must be greater than 2)
|
||||
|
||||
x = np.linspace(-2.5, 1.5, 4 * d + 1)
|
||||
y = np.linspace(-1.5, 1.5, 3 * d + 1)
|
||||
|
||||
A, B = np.meshgrid(x, y)
|
||||
C = A + B * 1j
|
||||
|
||||
Z = np.zeros_like(C)
|
||||
T = np.zeros(C.shape)
|
||||
|
||||
for k in range(n):
|
||||
M = abs(Z) < r
|
||||
Z[M] = Z[M] ** 2 + C[M]
|
||||
T[M] = k + 1
|
||||
|
||||
plt.imshow(T, cmap=plt.cm.twilight_shifted)
|
||||
plt.savefig("mandelbrot.png", dpi=200)
|
||||
Loading…
Add table
Add a link
Reference in a new issue