Neo
Neo

Reputation: 29

Setting Mandelbrot Python Image Background Color to Cyan

How do I set the Mandelbrot Set background to cyan? I don't understand the code.

Here's the code:

# 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()

I would like to set the background color to cyan. More Info needs to be entered here in order for me to post but I have no more info.

Thanks.

Neo

Upvotes: 1

Views: 68

Answers (1)

svfat
svfat

Reputation: 3363

try to change "mandelbrot" function to

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

Final return statement is a background color

Upvotes: 1

Related Questions