Why the luminous pixels of a turtle?

My program for creating a Mandelbrot set has an error: whenever the pen changes colors, and every 42nd pixel after that becomes lighter. It is rather a coincidence, a mandelbug (yes, I just recognized this term), since it is inconsistent for many pixels near the “edge” (it can be blurred between the color that it should have and the color of the last, or the next , the pixel should be), but it is always the 42nd pixel after that until the next color change. I am using OSX 10.6.8, PYTHON 2.7. When I wrote this program at school, it worked fine (Windows), and then I sent it to myself and worked on it a bit (basically just making the sample size and therefore enlarging the image) and running it, I got this error. EDIT: My bad one, I forgot to mention that this only happens with my Mandelbrot program, the several other tortoise programs that I have at home are wonderful.

Parts of screenshots (so you don’t have to wait long while the program is running to see what I'm talking about):

From my first version from home:

I mean, just what?

In the current version (sideways):

Please Note: this image is sideways

Here is the code:

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

EDIT: DSM recommended a solution that likes this bug. However, I have no experience editing Python source code, and all the underscores make me nervous. Can someone tell me what specifically change and / or how?

+6
source share
2 answers

Wow. I think this is one of my favorite mistakes ever, and believe it or not, the fact that the number is 42 is really true! Well, peripherally, anyway .. 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 arises when he decides to break the 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 error by clicking liniment and / or scattering self._pencolor links in places where they were not. Anyway, you are not crazy, and this is not quite what you are doing. :-)

+6
source

Can I offer an offer?

I tried your code, and it always did what you know, but what you might not know is a tracer function ... I'll just put it at the beginning of your code:

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

which also eliminates the need for a speed function (0) :)

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

  import time st=time.time() 

and this code at the end:

  print time.time()-st 

Well, by the way, Ive just made my own much slower and lower level of quality than yours, but used a square-shaped array and stamping in every place I wanted in the lol array, but will try to improve this in the future, since I only found out that the tortoise existed less than a week ago.

Last, if you type:

  from turtle import * 

instead of import turtle you don’t have to put a turtle at the beginning of every function call :) The same thing happens for every other module.

Ive included a pic of your fractal, which took 62 seconds to display on my machine that even this powerful code of yours doesn’t work on my weak machine .

I hope all this helps you a lot. you will also notice that I do not have this problem with the light line, not sure if this problem is fixed in the source code at the top?

0
source

Source: https://habr.com/ru/post/908219/


All Articles