# cython: language_level=3 import sys def escapes(cr: float, ci: float, it: int) -> bool: """ Does iterating z <- z^2 + c escape after it iterations? """ zr: float = 0.0 zi: float = 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: float, xmax: float, xstep: int, ymin: float, ymax: float, ystep: int, iterations: int, ) -> None: 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])) if __name__ == "__main__": xstep = int(sys.argv[1]) ystep = int(sys.argv[2]) iters = int(sys.argv[3]) mandel(-2.0, 1.0, xstep, -1.0, 1.0, ystep, iters)