コード例 #1
0
ファイル: mandelbrot.py プロジェクト: Quackmatic/mandelbrot
def basic_mandelbrot(x, y):
    """
    Calculate and return the RGB colour for a given (x, y) pixel.
    :param x: The X coordinate of the pixel.
    :param y: The Y coordinate of the pixel.
    :return: A tuple (R,G,B) of values 0-255.
    """
    # Scale X and Y to the viewport bounded by (X1, Y1) and (X2, Y2).
    x = scaled(x, 0, MAX_Y, X1, X2)
    y = scaled(y, 0, MAX_Y, Y1, Y2)

    # Set the initial value z0 and the constant c.
    z = complex(0, 0)
    c = complex(x, y)

    # Count the number of iterations to escape an arbitrary "bound".
    for i in range(MAX_ITERATION):
        z = z*z + c
        if abs(z) > 4:
            break
    else:
        # We haven't escaped in time - return a default colour of black.
        return 0, 0, 0

    # Return a color based on this escape time.
    return color(i)
コード例 #2
0
ファイル: mandelbrot.py プロジェクト: bedekelly/mandelbrot
def basic_mandelbrot(x, y):
    """
    Calculate and return the RGB colour for a given (x, y) pixel.
    :param x: The X coordinate of the pixel.
    :param y: The Y coordinate of the pixel.
    :return: A tuple (R,G,B) of values 0-255.
    """
    # Scale X and Y to the viewport bounded by (X1, Y1) and (X2, Y2).
    x = scaled(x, 0, MAX_Y, X1, X2)
    y = scaled(y, 0, MAX_Y, Y1, Y2)

    # Count the number of iterations to escape an arbitrary "bound".
    i = count_its(x, y, MAX_ITERATION)

    # Return a color based on this escape time.
    if i == MAX_ITERATION:
        return 0, 0, 0
    return color(i)