-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmandelbrot.py
More file actions
68 lines (63 loc) · 1.8 KB
/
mandelbrot.py
File metadata and controls
68 lines (63 loc) · 1.8 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import random
import sys
import time
import numpy as np
def mandelbrot(exp):
max = 4
it = 10
chardnum = 2
chararr = '£$%&ç@#*+?'
x_axis = [_ * 0.05 for _ in range(-max * 7, max * 7)]
y_axis = [_ * 0.05 for _ in range(-max * 10, max * 10)]
out = ""
for x in x_axis:
conc = ""
for y in y_axis:
c = complex(y, x)
res = 0
for i in range(it):
if i == 0:
res = c
else:
res = calc(res, c, exp)
if abs(res) >= max:
break
if abs(res) <= max / 2:
conc += f"{random.choice(chararr)}" * chardnum
else:
conc += " " * chardnum
out += f"{conc}\n"
print(out, f"printing [ Z=Z^N + C ] with N = {str(exp)[0:4] if exp < 10 else str(exp)[0:5]}")
def calc(x, c, exp):
return (x**exp) + c
def main():
exp = 2
iterate = False
if len(sys.argv) > 1:
if sys.argv[1] == "-i" or sys.argv[1] == "--iterate":
iterate = True
exp = float(sys.argv[2])
else:
exp = float(sys.argv[1])
if iterate:
step = 0.05
arr = np.arange(1, exp + step, step)
try:
for i in arr:
mandelbrot(i)
if i > 1 and i < 8 and round(i, 2).is_integer():
time.sleep(1)
elif i <= 3:
time.sleep(0.03)
else:
time.sleep(0.01)
if i != arr[-1]:
print("\x1b[H")
except KeyboardInterrupt:
print("\x1b[H")
os.system("cls" if sys.platform == 'win32' else "clear")
else:
mandelbrot(exp)
if __name__ == '__main__':
main()