from numba import jit from numpy import arange import sys if sys.version_info >= (3, 0): # make it "just work" in Python3 range = xrange @jit def escapes(cr, ci, it): """ Does iterating z <- z^2 + c escape after it iterations? """ zr = 0.0 zi = 0.0 for i in xrange(it): # z <- z^2 + c zr,zi = zr*zr - zi*zi + cr, 2*zr*zi + ci if zr*zr + zi*zi > 4: return True return False @jit def toChar(p): if p: return "_" else: return "X" @jit def mandel(xmin,xmax,xstep, ymin,ymax,ystep, iterations): for yc in xrange(ystep): y = yc*(ymax-ymin)/ystep + ymin row = [] for xc in xrange(xstep): x = xc*(xmax-xmin)/xstep + xmin row.append( toChar(escapes(x, y, iterations)) ) #print("".join([toChar(p) for p in row])) for xc in xrange(xstep): sys.stdout.write(row[xc]) print mandel(-2.0, 1.0, 256, -1.0, 1.0, 256, 100000)