Skip to content

Instantly share code, notes, and snippets.

@bitemyapp
Created March 22, 2012 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitemyapp/2156774 to your computer and use it in GitHub Desktop.
Save bitemyapp/2156774 to your computer and use it in GitHub Desktop.
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