示例#1
0
def julia_converges(x: float, y: float, max_steps: int, cx: float,
                    cy: float) -> bool:
    '''
    Returns True/False if the point (x y) does/doesn't meet the
    convergence condition.
    Method:
    1. Create the complex value z = Complex(x,y)
    2. Create the complex value c = Complex(cx,cy)
    3. Enter a loop, in which you update z:
       z = z.times(z).plus(c)
    4. Exit the loop when z gets too big (magnitude > 2: no convergence), or
       the loop has run max_steps times (converges).
    '''
    z = Complex(x, y)
    c = Complex(cx, cy)
    for i in range(100):  # 100 iters
        z = z.times(z).plus(c)  # iterate
        if z.magnitude() > 2:  # more than 2
            return False  # not in Julia Set
    return True  # after 100 iters, is still < 2