Skip to content

Commit 1146a94

Browse files
mandelbrot start
1 parent 689a015 commit 1146a94

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Diff for: ufo/mandelbrot0.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
def main():
6+
plt.imshow(mandelbrot(400, 400))
7+
plt.show()
8+
9+
10+
def mandelbrot(w, h, maxit=200):
11+
y, x = np.ogrid[-1.4:1.4:h * 1j, -2:0.8:w * 1j]
12+
c = x + y * 1j
13+
z = c
14+
divtime = maxit + np.zeros(z.shape, dtype=int)
15+
16+
for i in range(maxit):
17+
z = z ** 2 + c
18+
diverge = z * np.conj(z) > 2 ** 2
19+
div_now = diverge & (divtime == maxit)
20+
divtime[div_now] = i
21+
z[diverge] = 2
22+
return divtime
23+
24+
25+
if __name__ == "__main__":
26+
main()

Diff for: ufo/numpyogrid.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import numpy as np
2+
3+
4+
def main():
5+
first_ogid()
6+
7+
8+
def first_ogid():
9+
x, y = np.ogrid[1:4:1, 1:5:2]
10+
print(x)
11+
print(y)
12+
x, y = np.ogrid[1:4:3j, 1:5:2j]
13+
print(x)
14+
print(y)
15+
x=np.ogrid[1:5:2]
16+
print(x)
17+
18+
19+
if __name__ == "__main__":
20+
main()

0 commit comments

Comments
 (0)