Created
August 31, 2011 10:31
-
-
Save masahitojp/1183262 to your computer and use it in GitHub Desktop.
mandelbrot
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 | |
def mandelbrot(cr,ci): | |
limit=95 | |
iterations =0 | |
c=complex(cr,ci) | |
z=0+0j | |
while iterations < limit and abs(z) < 10: | |
z=z*z+c | |
iterations+=1 | |
return iterations | |
def mandelbrot_calc(top_left_r,top_left_i,right_bottom_r,right_bottom_i, res): | |
cur_i = top_left_i | |
while cur_i > right_bottom_i: | |
sys.stdout.write("|") | |
cur_r = top_left_r | |
while cur_r < right_bottom_r: | |
ch = 127 - mandelbrot(cur_r, cur_i) | |
sys.stdout.write(chr(ch)) | |
cur_r += res | |
sys.stdout.write("|\n") | |
cur_i -= res | |
if __name__=="__main__": | |
# topleft = (-2,1) | |
# bottomright = (1,-1) | |
mandelbrot_calc(-2,1, 1, -1, 0.04) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment