我该怎么给这套曼德尔布洛特的衣服上色?

2024-10-05 14:31:29 发布

您现在位置:Python中文网/ 问答频道 /正文

虽然我不知道如何像维基百科上其他地方的颜色一样,但我创建的这个曼德尔布洛特集效果很好。我的版本是纯黄色的(见下文)。在

from graphics import *

zoom = 0.1
xOffset = -0.171
yOffset = 0.61

def mandelbrot(spacing, maxIterations, width, height):
    win = GraphWin("Mandelbrot",width,height)
    win.setBackground('black')

    for x in range(0,width,spacing):
        for y in range(0,height,spacing):
            a = ((x / width) * zoom) - xOffset
            b = ((y / height) * zoom) - yOffset
            pt = Point(x,y)
            n = 0
            coordA = a
            coordB = b
            while(n<maxIterations):
                aa = a * a - b * b
                bb = 2 * a * b
                a = aa + coordA
                b = bb + coordB
                n+=1
                colourR = int(round(n/maxIterations * 255))
                colourB = 255-colourR
                if(abs(a+b) > 2):
                    break


            pt.setFill(color_rgb(colourR, colourR, 0))
            pt.draw(win)

mandelbrot(1,2000,700,700)

图片:

Mandelbrot set image


Tags: inptforrangewidthwinheightzoom