gpt4 book ai didi

python - Mandelbrot 设置平滑着色函数

转载 作者:行者123 更新时间:2023-11-28 17:00:03 24 4
gpt4 key购买 nike

我用 python 编写了 Mandelbrot 集,但它看起来很奇怪,所以我搜索了平滑的颜色。我已经使用对数和线性插值编写了一个平滑的着色函数,但无论我尝试什么,我都无法得到我想要的:

self.palette = [(3, 25, 61),(5, 43, 107),(7, 61, 153),(20, 96, 226),(20, 164, 226),(74, 181, 226),(138, 211, 242),(205, 234, 247),(225, 237, 242),(255,255,255)]

这是我的调色板

if n == self.max_iterations:
self.screen.set_at((x, y), (110, 13, 13))
else:
gradient = 1 + n - math.log(math.log(abs(m))) / math.log(2.0)
iteration = n + 1 - gradient
color1 = list(self.palette[n % 10])
if n % 10 <= 8:
color2 = list(self.palette[n % 10+1])
else:
color2 = list(self.palette[-1])

color = [[], [], []]
for number, elt in enumerate(color):
color[number] = color1[number] + (iteration % 1)*(color2[number]-color1[number])

self.screen.set_at((x, y), tuple(color))

这是我的着色函数

这是我得到的

如您所见,颜色是平滑的,但以错误的方式,颜色没有连续性

我想要这样的东西:

理想的结果

我们没有看到色差

最佳答案

看起来您是根据离散值(n,转义时间)选择像素颜色。

我建议:

1) 在一维线上绘制颜色与-n 的关系。它看起来是连续的吗?如果不是,请选择一个显示为连续 w.r.t. 的颜色图。增加 n.

2) 想办法让 n 连续,而不是离散。一种方法是计算观察窗口的最大逃逸时间,然后将所有其他逃逸时间除以该值,以产生更连续的场。请参阅有关转义时间规范化的链接:
https://linas.org/art-gallery/escape/escape.html

我相信,如果您同时满足上述两个条件,主图像周围的区域将看起来是连续的,而不是“等线”外观。

关于python - Mandelbrot 设置平滑着色函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55229472/

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