[Python] The output of my fractal program is in 4 inverted quarters

Discussão em 'Python' iniciado por Stack, Setembro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a python program that can render the mandelbrot set. My full program can output an image of the set, but for some reason, it displays it cut up into opposite facing quarters.

    This is the whole program.

    from PIL import Image
    from PIL import ImageShow
    from PIL import ImageColor as ImageColour
    colours = ["navy","darkblue","blue","cornflowerblue","lightsteelblue","lightskyblue","turquoise","palegreen","lawngreen"]
    def testpoint(c,zoom):
    zofn = 0.0
    count = 0
    while str(zofn)[1] != "n" and count < (5*zoom):
    #Change the formula following the "zofn =" to change the fractal formula.
    zofn = (zofn*zofn)+c
    count = count + 1
    if str(zofn)[1] != "n":
    return -1
    else:
    return count
    def mainprogram():

    zoom = int(input("Set Zoom Level. (Default: 10) "))*10
    centre_x = int(input("Input centre x value. (Default: -50) "))
    centre_y = int(input("Input centre y value. (Default: 0) "))
    display = ""
    for i in range((centre_y-250),(centre_y+250)):
    for x in range((centre_x-500),(centre_x+500)):
    coordinate = complex((x/zoom),(i/zoom))
    value = testpoint(coordinate,zoom)
    if value == -1:
    colour = (0,0,0)
    else:
    colour = ImageColour.getrgb(colours[value % len(colours)])
    result.putpixel((x,i),colour)
    print("line",(i+250),"done")
    ImageShow.show(result)
    mainprogram()
    result = Image.new("RGB",(1000,500),"Black")
    mainprogram()


    [​IMG]

    It seems like each quadrant should be flipped the other way around. I've tried fiddling with the range for the for i in range((centre_y-250),(centre_y+250)) loop, with very little difference. I'm very new to programming, so I don't really know what I'm doing.

    Continue reading...

Compartilhe esta Página