Skip to content

Instantly share code, notes, and snippets.

@irmen
Created September 20, 2016 20:00
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 irmen/c6b12b4cf88a6a4fcf5ff721c7089078 to your computer and use it in GitHub Desktop.
Save irmen/c6b12b4cf88a6a4fcf5ff721c7089078 to your computer and use it in GitHub Desktop.
complex number calculation test program
from __future__ import print_function, division
import time
import sys
if sys.version_info < (3, 0):
range = xrange
def mandel():
res_x = 100
res_y = 100
maxiters = 5000
for y in range(res_y):
line = ""
for x in range(res_x):
zr = (x/res_x - 0.5) - 0.5
zi = (y/res_y - 0.5) * 2
z = complex(zr, zi)
c = z
for iters in range(maxiters+1):
if abs(z) > 2:
break
z = z*z + c
if iters >= maxiters:
line += " "
else:
line += chr(iters % 64 + 32)
print(line)
def iterate():
print("iterating...")
z = .1+.1j
c = z
for _ in range(12345678):
z = z*z + c
z = z*z + c
z = z*z + c
z = z*z + c
z = z*z + c
z = z*z + c
if abs(z) > 2:
raise ValueError("should not go towards infinity")
print(abs(z))
if __name__ == "__main__":
start = time.time()
mandel()
duration = time.time()-start
print("mandel draw took: %.2f sec" % duration)
start = time.time()
iterate()
duration = time.time()-start
print("iterate took: %.2f sec" % duration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment