本文经授权转自微信公众号“大数据文摘 | bigdatadigest” 编译团队:Aileen,徐凌霄 用Python绘制著名的数学图片或动画, 展示数学中的算法魅力。 Mandelbrot 集 代码:46 lines (34 sloc) 1.01 KB ''' A fast Mandelbrot set wallpaper renderer reddit discussion: https://www.reddit.com/r/math/comments/2abwyt/smooth_colour_mandelbrot/ ''' import numpy as np from PIL import Image from numba import jit MAXITERS = 200 RADIUS = 100 @jit def color ( z , i ): v = np.log2(i + 1 - np.log2(np.log2( abs (z)))) / 5 if v < 1.0 : return v ** 4 , v ** 2.5 , v else : v = max ( 0 , 2 - v) return v, v ** 1.5 , v ** 3 @jit def iterate ( c ): z = 0 j for i in range ( MAXITERS ): if z.real * z.real + z.imag * z.imag > RADIUS : return color(z, i) z = z * z + c return