-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
53 lines (40 loc) · 932 Bytes
/
Copy pathpython.py
File metadata and controls
53 lines (40 loc) · 932 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#from numba import njit
max_real = 2.0
max_imag = max_real
number = 5000
max_radius = 50.0
iters = 100
#@njit
def iterate_until_escape(z):
z0 = z
for i in range(1, iters):
z0 = z0**2 - 0.5
if abs(z0) > max_radius:
return i
return 0
#@njit
def to_rgb(i):
if i == 0:
return "255 255 255 "
else:
b = 255 * i // iters
return "0 {0} {0} ".format(b)
#@njit
def jul(z):
return iterate_until_escape(z)
#@njit
def xloop(y):
return [
jul((2 * max_imag / number) * (x + 1j * y) - (2 + 2j))
for x in range(number)
]
def main():
with open("set.ppm", "w") as file:
file.write(f"P3\n{number} {number}\n255\n")
for y in range(number, 0, -1):
file.write("".join([
"0 {0} {0} ".format(it) if it != 0 else "255 255 255 "
for it in xloop(y)
]))
return
main()