首页 > 解决方案 > Mandelbrot 使用枕头库在 python 中设置放大

问题描述

我不知道如何放大曼德布罗集以及如何将坐标更改为缩放。我想知道我应该设置图像的中心,例如:x= -0.3123 和 y = -0.1212 现在缩放它还是将 x,y 更改为任意数字?谁能给我解释一下?我的代码:

import math

from PIL import Image

height = 360
width = 640

#plot window
X_START = -2.5
X_END = 2.5
Y_START = -1.5
Y_END = 1.5
base_zoom = 1
for i in range(1,30):
    img = Image.new("HSV", (width, height), 0)
    X_START = -2.5 * base_zoom
    X_END = 2.5 * base_zoom
    Y_START = -1.5 * base_zoom
    Y_END = 1.5 * base_zoom
    maxIter = 100
    pixels = img.load()
    for x in range(width):
        print(f"Did: {math.floor(x / width * 1000 / 10)} %  of picture nr {i}")
        for y in range(height):

            a = (x / width) * (X_END - X_START) + X_START
            b = (y/ height) * (Y_END - Y_START) + Y_START


            ca = a
            cb = b

            n = 0


            while n<maxIter:

                aa = -2
                bb = 2 * a * b


                if abs(aa + bb) > 4:
                    bright = int(255 * n % maxIter)
                    saturation = 185
                    value = 218
                    pixels[x, y] = (bright, saturation, value)
                a = aa
                b = bb
                n+=1







    base_zoom *= 0.5
    # img.show()
    img.convert('RGB').save(f'pictures_mandelbrot\picture{i}.BMP')


标签: pythonzoomingmandelbrot

解决方案


推荐阅读