Created
September 20, 2016 20:00
-
-
Save irmen/c6b12b4cf88a6a4fcf5ff721c7089078 to your computer and use it in GitHub Desktop.
complex number calculation test program
This file contains 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
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