为什么乌龟会减轻像素? [英] Why is turtle lightening pixels?

查看:119
本文介绍了为什么乌龟会减轻像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建Mandelbrot集的程序有一个错误:每当笔改变颜色时,此后的第42个像素就会变亮.碰巧的是,这是一个mandelbug(是的,我刚刚学到了该术语),因为边缘"附近的许多像素都不一致(实际上,它在应该是的颜色和最后一个颜色之间可能是模糊的,或者接下来,应该假定为像素),但在下一个颜色更改之前,它始终是该像素之后的第42个像素.我正在使用OSX 10.6.8,PYTHON 2.7.当我在学校编写该程序时,它可以完美运行(Windows),然后将其发送给自己,并对其进行了更多处理(主要是使样本大小增大,因此图像更大),然后运行它,我得到了漏洞.我不好,我忘了提到这只发生在我的Mandelbrot程序中,我在家其他几个乌龟程序也很好.

My program for creating a Mandelbrot set has a bug: whenever the pen changes colors, and every 42nd pixel after that, is lighter. This is, rather coincidentally, a mandelbug (yes, I just learned that term), as it is inconsistent for many pixels near an "edge" (it might actually be blurred between the color it's supposed to be and the color the last, or next, pixel is supposed to be), but it's always the 42nd pixel after that one until the next color change. I am using OSX 10.6.8, PYTHON 2.7. When I wrote this program at school, it worked perfectly (Windows), and then I sent it to myself, and worked on it a little more (mostly just making the sample size and therefore image larger), and ran it, I got this bug. My bad, I forgot to mention that this only happens with my Mandelbrot program, the few other turtle programs I have at home are fine.

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

Parts of screenshots (so that you don't have to wait forever while the program runs to see what I'm talking about):

从我在家的第一个版本开始:

From my first version from home:

从当前版本(横向):

此处提供代码:

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")

喜欢此bug的DSM已建议修复.但是,我没有编辑Python源代码的经验,所有下划线都让我感到紧张.有人可以告诉我具体编辑什么和/或如何做吗?

A fix has been suggested by DSM, who likes this bug. However, I have no experience editing Python source code, and all the underscores are making me nervous. Can someone tell me specifically what to edit and/or how?

推荐答案

哇.我认为这是我有史以来最喜欢的错误之一,信不信由你,这个数字恰好是42,这实际上是有意义的!好吧,外围,无论如何.. 在turtle.py中:

Wow. I think this is one of my favourite bugs ever, and believe it or not, the fact that the number happens to be 42 is actually relevant! Well, peripherally, anyhow.. In 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)

因此,当它决定换行时,问题就出在这里,这显然是出于性能方面的原因:

So the problem comes about when it decides to break a line, apparently for performance reasons:

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.                                       
    """

我能够通过提高行数限制和/或分散self._pencolor引用在没有任何位置的地方来修复"该错误.但是,无论如何,您并不疯,而且您所做的也不是任何事情. :-)

I was able to "fix" the bug by bumping up the linenumber limit and/or scattering self._pencolor references in places that didn't have any. But you're not crazy, anyway, and it's not really anything that you're doing. :-)

这篇关于为什么乌龟会减轻像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆