simulation.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:live-plotter 作者: anandtrex 项目源码 文件源码
def mandelbrot(h, w, maxit):
    """
    Returns an image of the Mandelbrot fractal of size (h,w).
    """
    y, x = np.ogrid[-1.4:1.4:h * 1j, -2:0.8:w * 1j]
    c = x + y * 1j
    z = c
    divtime = maxit + np.zeros(z.shape, dtype=int)

    for i in range(maxit):
        z = z ** 2 + c
        diverge = z * np.conj(z) > 2 ** 2
        div_now = diverge & (divtime == maxit)
        divtime[div_now] = i + 100
        z[diverge] = 2
        logger.debug("Updating divtime")
        recorder.record('divtime', divtime)

    return divtime
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号