gpt4 book ai didi

python - 多线程 mandelbrot 集

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:05:10 24 4
gpt4 key购买 nike

是否可以将 mandelbrot 集的公式(默认为 f(z) = z^2 + c)更改为不同的公式( f(z) = z^2 + c * e^(- z)是我需要的)在使用逃逸时间算法时,如果可能的话如何?我目前正在通过 FB36 使用此代码

# Multi-threaded Mandelbrot Fractal (Do not run using IDLE!)
# FB - 201104306
import threading
from PIL import Image
w = 512 # image width
h = 512 # image height
image = Image.new("RGB", (w, h))
wh = w * h
maxIt = 256 # max number of iterations allowed
# drawing region (xa < xb & ya < yb)
xa = -2.0
xb = 1.0
ya = -1.5
yb = 1.5
xd = xb - xa
yd = yb - ya
numThr = 5 # number of threads to run
# lock = threading.Lock()

class ManFrThread(threading.Thread):
def __init__ (self, k):
self.k = k
threading.Thread.__init__(self)
def run(self):
# each thread only calculates its own share of pixels
for i in range(k, wh, numThr):
kx = i % w
ky = int(i / w)
a = xa + xd * kx / (w - 1.0)
b = ya + yd * ky / (h - 1.0)
x = a
y = b
for kc in range(maxIt):
x0 = x * x - y * y + a
y = 2.0 * x * y + b
x = x0
if x * x + y * y > 4:
# various color palettes can be created here
red = (kc % 8) * 32
green = (16 - kc % 16) * 16
blue = (kc % 16) * 16
# lock.acquire()
global image
image.putpixel((kx, ky), (red, green, blue))
# lock.release()
break

if __name__ == "__main__":
tArr = []
for k in range(numThr): # create all threads
tArr.append(ManFrThread(k))
for k in range(numThr): # start all threads
tArr[k].start()
for k in range(numThr): # wait until all threads finished
tArr[k].join()
image.save("MandelbrotFractal.png", "PNG")

最佳答案

从代码中我推断出 z = x + y * ic = a + b * i。这对应于 f(z) - z ^2 + c。你想要 f(z) = z ^2 + c * e^(-z)

回想一下 e^(-z) = e^-(x + yi) = e^(-x) * e^i(-y) = e^(-x)(cos(y) - i*sin(y)) = e^(-x)cos(y) - i (e^(-x)sin(y))。因此,您应该将行更新为以下内容:

x0 = x * x - y * y + a * exp(-x) * cos(y) + b * exp(-x) * sin(y);
y = 2.0 * x * y + a * exp(-x) * sin(y) - b * exp(-x) * cos(y)
x = x0

如果你没有得到你所追求的特征差异化水平,你可能需要调整 maxIt(平均而言,现在可能需要更多或更少的迭代才能逃脱)但这应该是您所追求的数学表达式。

正如评论中所指出的,您可能需要调整标准本身,而不仅仅是最大迭代次数,以便获得所需的差异化水平:更改最大值对那些从不逃脱的人没有帮助。

您可以尝试推导一个良好的逃逸条件,或者只是尝试一些事情,看看您会得到什么。

关于python - 多线程 mandelbrot 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44830302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com