我试图在python中编码Mandelbrot集。但我的代码显示的是黑色图像,而不是Mandelbrot图像。这是我的完整密码。
import numpy as np
from PIL import Image
def mandelbrot_count(c,n):
z = 0j
for i in range(n):
z = z*z+c
if abs(z)>2:
return i
return n
width = 300
height = 300
image_array = np.zeros((height,width))
for i in range(height):
for j in range(width):
c = complex(i,j)
n = mandelbrot_count(c,30)
image_array[i][j]=n
image = Image.fromarray(image_array)
image.show()
发布于 2020-01-31 00:06:56
如前所述:重新标度。例如,范围-2.25到0.75和-1.25到1.25与> 1000步为您带来附加的图像。
import numpy as np
from PIL import Image
def mandelbrot_count(c,n):
z = 0j
for i in range(n):
z = z*z+c
if abs(z)>2:
return i
return n
width = 1500
height = 1250
image_array = np.zeros((height,width))
for i in range(height):
for j in range(width):
c = complex(-2.25+i*(0.75+2.25)/1500,-1.25 + j*(1.25 + 1.25)/1250)
n = mandelbrot_count(c,30)
image_array[i][j]=n
image = Image.fromarray(image_array)
image.show()
https://stackoverflow.com/questions/59997134
复制相似问题