forked from ilanschnell/bitarray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandel.py
40 lines (31 loc) · 844 Bytes
/
mandel.py
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
import sys
from bitarray import bitarray
from numba import jit # type: ignore
width, height = 4000, 3000
maxdepth = 500
@jit(nopython=True)
def mandel(c):
d = 0
z = c
while abs(z) < 4.0 and d <= maxdepth:
d += 1
z = z * z + c
return d
def main():
data = bitarray(endian='big')
for j in range(height):
sys.stdout.write('.')
sys.stdout.flush()
y = +1.5 - 3.0 * j / height
for i in range(width):
x = -2.75 + 4.0 * i / width
c = mandel(complex(x, y)) % 2
data.append(c)
print("done")
with open('out.ppm', 'wb') as fo:
fo.write(b'P4\n')
fo.write(b'# partable bitmap image of the Mandelbrot set\n')
fo.write(b'%i %i\n' % (width, height))
data.tofile(fo)
if __name__ == '__main__':
main()