【问题标题】:smooth coloring algorithm for the mandelbrot set曼德布罗集的平滑着色算法
【发布时间】:2015-03-25 23:40:35
【问题描述】:

我知道已经回答了很多关于此的问题。但是,我的略有不同。每当我们实现我所理解的平滑着色算法时。

mu = 1 + n + math.log2(math.log2(z))  / math.log2(2)

其中 n 是转义迭代,2 是 z 的幂,如果我没记错,z 是该转义迭代中复数的模数。然后,我们在颜色之间的线性插值中使用这个重新归一化的转义值来产生一个平滑的带状曼德布罗集。我已经看到了其他问题的答案,我们通过 HSB 到 RGB 转换运行这个值,但是我仍然无法理解这将如何提供平滑的颜色渐变以及如何在 python 中实现它。

但是,每当我尝试实现它时,它都会生成浮点 RGB 值,但除了 .tiff 文件之外,我所知道的没有一种图像格式可以支持这一点,如果我们四舍五入到整数,我们仍然有不光滑的条带。那么,如果我们不能直接使用它产生的 RGB 值,这应该如何产生一个平滑的带状图像呢?我在下面尝试的示例代码,因为我不完全理解如何实现它,所以我尝试了一种在某种程度上产生平滑条带的解决方案。这会在两种颜色之间产生一个有点平滑的带状图像,对于整个场景,蓝色和逐渐变白的颜色,我们进一步放大场景到某个深度,所有东西都显得模糊。由于我使用 tkinter 来执行此操作,因此我必须将 RGB 值转换为十六进制才能将它们绘制到画布上。

我正在递归地计算集合,并且在我的其他函数(未在下面发布)中,我正在设置窗口宽度和高度,然后针对 tkinter 窗口的像素迭代这些并在内循环中计算此递归。

def linear_interp(self, color_1, color_2, i):

    r = (color_1[0] * (1 - i)) + (color_2[0] * i)
    g = (color_1[1] * (1 - i)) + (color_2[1] * i)
    b = (color_1[2] * (1 - i)) + (color_2[2] * i)
    rgb_list = [r, g, b]
    for value in rgb_list:
        if value > MAX_COLOR:
            rgb_list[rgb_list.index(value)] = MAX_COLOR
        if value < 0:
            rgb_list[rgb_list.index(value)] = abs(value)

    return (int(rgb_list[0]), int(rgb_list[1]), 
            int(rgb_list[2]))

def rgb_to_hex(self, color):
    return "#%02x%02x%02x" % color

def mandel(self, x, y, z, iteration):
    bmin = 100
    bmax = 255
    power_z = 2

    mod_z = math.sqrt((z.real * z.real) + (z.imag * z.imag))
    #If its not in the set or we have reached the maximum depth
    if  abs(z) >= float(power_z) or iteration == DEPTH:
        z = z
        if iteration > 255:
            factor = (iteration / DEPTH) * 255
        else:
            factor = iteration

        logs = math.log2(math.log2(abs(z) + 1 ) / math.log2(power_z))
        r = g = math.floor(factor + 5 - logs)

        b = bmin + (bmax - bmin) * r / 255
        rgb = (abs(r), abs(g), abs(round(b)))
        self.canvas.create_line(x, y, x + 1, y + 1,
                                fill = self.rgb_to_hex(rgb))

    else:

        z = (z * z) + self.c
        self.mandel(x, y, z, iteration + 1)

    return z

【问题讨论】:

标签: algorithm colors tkinter fractals mandelbrot


【解决方案1】:

颜色#000000、#010000、...、#FE0000、#FF0000 之间的差异非常小,以至于您可以获得从黑色到红色的平滑渐变。因此,只需将您的值四舍五入:假设您的平滑函数的平滑颜色值范围从 0 到(不包括)1,那么您只需使用 (int) (值 * 256)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多