Created
March 22, 2012 07:03
-
-
Save bitemyapp/2156774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from array import array | |
from multiprocessing import Pool | |
def do_row(fy): | |
local_abs = abs | |
two_over_size = 2.0 / size | |
xr_offs = range(7, -1, -1) | |
xr_iter = range(50) | |
result = array('B') | |
for x in range(7, size, 8): | |
byte_acc = 0 | |
for offset in xr_offs: | |
z = 0j | |
c = two_over_size * (x - offset) + fy | |
for i in xr_iter: | |
z = z * z + c | |
if local_abs(z) >= 2: | |
break | |
else: | |
byte_acc += 1 << offset | |
result.append(byte_acc) | |
if x != size - 1: | |
result.append(byte_acc) | |
return result.tostring() | |
def main(out): | |
out.write(('P4\n%d %d\n' % (size, size)).encode('ASCII')) | |
pool = Pool() | |
step = 2.0j / size | |
for row in pool.imap(do_row, (step*y-(1.5+1j) for y in range(size))): | |
out.write(row) | |
if __name__ == '__main__': | |
size = int(sys.argv[1]) | |
main(open("out", "wb")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment