# pythran export mandel(float, float, int, float, float, int, int) def escapes(cr, ci, it): """ Does iterating z <- z^2 + c escape after it iterations? """ zr = 0.0 zi = 0.0 for i in range(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 mandel(xmin, xmax, xstep, ymin, ymax, ystep, iterations): for yc in range(ystep): y = yc * (ymax - ymin) / ystep + ymin row = [] for xc in range(xstep): x = xc * (xmax - xmin) / xstep + xmin row.append(escapes(x, y, iterations)) print("".join([" " if p else "X" for p in row]))