def mandelbrot_color(matrix, output_file_name):
"""Generates a color version of the Mandelbrot Set
Writes its output file to output_file_name
Args:
matrix: np.array, 2D array representing the mandelbrot set
output_file_name: string, filename to write image to
"""
# I wasn't quite sure on how to do the coloring, so I just interpolated
# between two colors:
color1 = np.array([[.2], [.2], [.8]])
color2 = np.array([[1], [.2], [.5]])
color_img = np.zeros((matrix.shape[0], matrix.shape[1], 3))
color_img[:, :, 0] = color1[0] + matrix[:, :] * (color2[0] - color1[0])
color_img[:, :, 1] = color1[1] + matrix[:, :] * (color2[1] - color1[1])
color_img[:, :, 2] = color1[2] + matrix[:, :] * (color2[2] - color1[2])
print("\nWriting image to:", output_file_name)
skimage.io.imsave(output_file_name, color_img)
评论列表
文章目录