python代码:
import numpy as npfrom PIL import Imagefrom numba import jitMAXITERS = 200RADIUS = 100@jitdef color(z, i):v = np.log2(i+1-np.log2(np.log2(abs(z))))/5if v < 1.0:return v**4, v**2.5, velse:v = max(0, 2-v)return v, v**1.5, v**3@jitdef iterate(c):z = 0jfor i in range(MAXITERS):if z.real*z.real +z.imag*z.imag > RADIUS:return color(z, i)z = z*z + creturn 0, 0, 0def main(xmin, xmax, ymin, ymax, width, height):x = np.linspace(xmin, xmax, width)y = np.linspace(ymax, ymin, height)z = x[None, :] +y[:, None]*1jred, green, blue = np.asarray(np.frompyfunc(iterate, 1, 3)(z)).astype(np.float)img = np.dstack((red, green, blue))Image.fromarray(np.uint8(img*255)).save('mandelbrot.png')main(-2.1, 0.8, -1.16, 1.16, 1200, 960)
效果图:
如果觉得《分型图z=z*z+c的画法》对你有帮助,请点赞、收藏,并留下你的观点哦!