【问题标题】:Setting Mandelbrot Python Image Background Color to Cyan将 Mandelbrot Python 图像背景颜色设置为青色
【发布时间】:2022-11-30 03:19:14
【问题描述】:

如何将 Mandelbrot 集背景设置为青色?我不明白代码。

这是代码:

# Python code for Mandelbrot Fractal

# Import necessary libraries
from PIL import Image
from numpy import complex, array
import colorsys

# setting the width of the output image as 1024
WIDTH = 1024

# a function to return a tuple of colors
# as integer value of rgb
def rgb_conv(i):
    color = 255 * array(colorsys.hsv_to_rgb(i / 255.0, 1.0, 0.5))
    return tuple(color.astype(int))

# function defining a mandelbrot
def mandelbrot(x, y):
    c0 = complex(x, y)
    c = 0
    for i in range(1, 1000):
        if abs(c) > 2:
            return rgb_conv(i)
        c = c * c + c0
    return (0, 0, 0)

# creating the new image in RGB mode
img = Image.new('RGB', (WIDTH, int(WIDTH / 2)))
pixels = img.load()

for x in range(img.size[0]):

    # displaying the progress as percentage
    print("%.2f %%" % (x / WIDTH * 100.0))
    for y in range(img.size[1]):
        pixels[x, y] = mandelbrot((x - (0.75 * WIDTH)) / (WIDTH / 4),
                                    (y - (WIDTH / 4)) / (WIDTH / 4))

# to display the created fractal after
# completing the given number of iterations
img.show()

我想将背景颜色设置为青色。需要在此处输入更多信息以便我发布,但我没有更多信息。

谢谢。

尼奥

【问题讨论】:

    标签: python mandelbrot


    【解决方案1】:

    尝试将“mandelbrot”功能更改为

    def mandelbrot(x, y):
        c0 = complex(x, y)
        c = 0
        for i in range(1, 1000):
            if abs(c) > 2:
                return rgb_conv(i)
            c = c * c + c0
        return (0, 255, 255)
    

    最后的退货声明是背景色

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      相关资源
      最近更新 更多