-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmandelbrot_scatterplot.py
More file actions
36 lines (28 loc) · 997 Bytes
/
mandelbrot_scatterplot.py
File metadata and controls
36 lines (28 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
import matplotlib.pyplot as plt
import time
def complex_matrix(xmin, xmax, ymin, ymax, pixel_density):
re = np.linspace(xmin, xmax, int((xmax - xmin) * pixel_density))
im = np.linspace(ymin, ymax, int((ymax - ymin) * pixel_density))
return re[np.newaxis, :] + im[:, np.newaxis] * 1j
def is_stable(c, num_iterations):
z = 0
for _ in range(num_iterations):
z = z ** 2 + c
return abs(z) <= 2
def get_members(c, num_iterations):
mask = is_stable(c, num_iterations)
return c[mask]
pd = int(input("pixel density: "))
ni = int(input("number of iterations:"))
msc = input("color: ")
then = time.time()
c = complex_matrix(-2, 0.5, -1.5, 1.5, pixel_density=pd)
members = get_members(c, num_iterations=ni)
plt.scatter(members.real, members.imag, color=msc, marker=",", s=1)
plt.gca().set_aspect("equal")
plt.axis("off")
plt.tight_layout()
now = time.time()
print("seconds: " + str(now - then))
plt.show()