为什么龟可以点亮像素?

Iro*_*ard 7 python turtle-graphics mandelbrot

我创建Mandelbrot集的程序有一个错误:每当笔改变颜色时,每隔42个像素就会变亮.这是一个非常巧合的mandelbug(是的,我刚刚学过这个术语),因为它对于"边缘"附近的许多像素是不一致的(它实际上可能在它应该是的颜色和最后一个颜色之间模糊,或者接下来,像素应该是),但它总是在那之后的第42个像素,直到下一个颜色变化.我使用的是OSX 10.6.8,PYTHON 2.7.当我在学校写这个程序时,它完美地工作(Windows),然后我把它发送给自己,并且更多地工作(大多只是制作样本大小,因此图像更大),然后运行它,我得到了这个错误.编辑:我的坏,我忘了提到这只发生在我的Mandelbrot程序,我在家里的其他几个海龟程序都很好.

截图的一部分(这样你就不必在程序运行时永远等待,看看我在说什么):

从我家的第一个版本:

我的意思是,是什么?

从当前版本(侧面):

请注意:此图片是侧面的

下面是代码:

import turtle
import math
turtle.speed(0)
def benoit(onelen):
    turtle.left(90)
    for x in range(-2*onelen, onelen):
        turtle.up()
        turtle.goto(x, int(-1.5*onelen)-1)
        turtle.down()
        for y in range(int(-1.5*onelen)-1, int(1.5*onelen)-1):
            z = complex(0,0)
            c = complex(x*1.0/onelen,y*1.0/onelen)
            for k in range(20):
                z = z*z+c
                if abs(z) > 2:
                    g = .2 + .8*(20-k)/20
                    break
                if k == 19:
                    g = 0
            turtle.pencolor(0,g,0)
            turtle.forward(1)
benoit(250)
x = raw_input("Press Enter to Exityadayadayada")
Run Code Online (Sandbox Code Playgroud)

编辑:DSM建议修复,他喜欢这个bug.但是,我没有编辑Python源代码的经验,所有下划线都让我感到紧张.有人能告诉我具体编辑和/或如何编辑?

DSM*_*DSM 7

哇.我认为这是我最喜欢的错误之一,不管你信不信,这个数字恰好是42的事实实际上是相关的!嗯,外围,无论如何..在turtle.py:

   def _goto(self, end):
        """Move the pen to the point end, thereby drawing a line
        if pen is down. All other methodes for turtle movement depend
        on this one.

[...]

    ######    vererbung!!!!!!!!!!!!!!!!!!!!!!
    self._position = end
    if self._creatingPoly:
        self._poly.append(end)
    if len(self.currentLine) > 42: # 42! answer to the ultimate question
                                   # of life, the universe and everything
        self._newLine()
    self._update() #count=True)
Run Code Online (Sandbox Code Playgroud)

因此,当它决定打破一条线时出现问题,显然是出于性能原因:

def _newLine(self, usePos=True):
    """Closes current line item and starts a new one.                                              
       Remark: if current line became too long, animation                                          
       performance (via _drawline) slowed down considerably.                                       
    """
Run Code Online (Sandbox Code Playgroud)

我能够通过提高亚麻限制和/或在没有任何地方的地方散布self._pencolor参考来"修复"这个错误.但无论如何,你并不疯狂,这并不是你正在做的任何事情.:-)