Skip to content Skip to sidebar Skip to footer

Why Is Turtle Lightening Pixels?

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,

Solution 1:

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

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. :-)

Solution 2:

Can i offer a suggestion?

i tried your code and it was taking forever to run which you are aware of but what you may not be aware of is the tracer function... i simply put at the beginning of your code:

 wn=turtle.Screen()
 wn.tracer(10000)

that also eliminates the need for the speed(0) function :)

Try that and run it again, i did and it rendered the whole image in 62 seconds, i timed it by importing the time module by putting this code at the beginning:

 import time
 st=time.time()

and this code at the end:

printtime.time()-st

Well done by the way, Ive just made my own thats a lot slower and lower quality then yours but was using an array of the square shape and stamping to each location i wanted in the array lol, but will be trying to improve it in the future as i only found out turtle existed less then a week ago.

One last thing, if you type:

from turtle import *

instead of "import turtle" you dont need to put turtle at the beginning of every function call :) same thing goes for every other module.

Ive included the pic of your fractal that took 62 seconds to render on my machine thats not even that powerfulYour code run on my weak machine.

I hope all this helps you greatly. also youll notice i dont have that light line problem, not sure if you fixed that issue in the original code up top?

Post a Comment for "Why Is Turtle Lightening Pixels?"