-
Notifications
You must be signed in to change notification settings - Fork 6
/
mandelbrot_python.py
50 lines (40 loc) · 1.05 KB
/
mandelbrot_python.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
41
42
43
44
45
46
47
48
49
# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
#
# contributed by Tupteq
# modified by Simon Descarpentries
import sys
from array import array
def main():
cout = sys.stdout.write
size = int(sys.argv[1])
fsize = float(size)
xr_size = xrange(size)
xr_iter = xrange(50)
bit_num = 7
byte_acc = 0
result = []
local_abs = abs
cout ("P4\n%d %d\n" % (size, size))
for y in xr_size:
fy = 2j * y / fsize - 1j
for x in xr_size:
z = 0j
c = 2. * x / fsize - 1.5 + fy
for i in xr_iter:
z = z * z + c
if local_abs(z) >= 2.: break
else:
byte_acc += 1 << bit_num
if bit_num == 0:
result.append (byte_acc)
bit_num = 7
byte_acc = 0
else:
bit_num -= 1
if bit_num != 7:
result.append (byte_acc)
bit_num = 7
byte_acc = 0
cout (array ('B', result).tostring ())
main()