# pypy .../pypy-source/rpython/translator/goal/translate.py targetmandel.py # ./targetmandel-c 400 160 10000 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 def toChar(p): if p: return " " else: return "X" 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( escapes(x, y, iterations) ) print("".join([toChar(p) for p in row])) def main(args): xstep = int(args[1]) ystep = int(args[2]) iters = int(args[3]) mandel(-2.0, 1.0, xstep, -1.0, 1.0, ystep, iters) return 0 def target(driver,args): return main,None