mandelbrot.py 795 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import sys
  2. def main():
  3. cout = sys.stdout.write
  4. size = 4000
  5. xr_size = range(size)
  6. xr_iter = range(50)
  7. bit = 128
  8. byte_acc = 0
  9. cout("P4\n%d %d\n" % (size, size))
  10. size = float(size)
  11. for y in xr_size:
  12. fy = 2j * y / size - 1j
  13. for x in xr_size:
  14. z = 0j
  15. c = 2. * x / size - 1.5 + fy
  16. for i in xr_iter:
  17. z = z * z + c
  18. if abs(z) >= 2.0:
  19. break
  20. else:
  21. byte_acc += bit
  22. if bit > 1:
  23. bit >>= 1
  24. else:
  25. cout(chr(byte_acc))
  26. bit = 128
  27. byte_acc = 0
  28. if bit != 128:
  29. cout(chr(byte_acc))
  30. bit = 128
  31. byte_acc = 0
  32. main()