You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original implementation of turtle.RawTurtle._goto:
def_goto(self, end):
"""Move the pen to the point end, thereby drawing a line if pen is down. All other methods for turtle movement depend on this one. """## Version with undo-stuffgo_modes= ( self._drawing,
self._pencolor,
self._pensize,
isinstance(self._fillpath, list))
screen=self.screenundo_entry= ("go", self._position, end, go_modes,
(self.currentLineItem,
self.currentLine[:],
screen._pointlist(self.currentLineItem),
self.items[:])
)
ifself.undobuffer:
self.undobuffer.push(undo_entry)
start=self._positionifself._speedandscreen._tracing==1:
diff= (end-start)
diffsq= (diff[0]*screen.xscale)**2+ (diff[1]*screen.yscale)**2nhops=1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
delta=diff* (1.0/nhops)
forninrange(1, nhops):
ifn==1:
top=Trueelse:
top=Falseself._position=start+delta*nifself._drawing:
screen._drawline(self.drawingLineItem,
(start, self._position),
self._pencolor, self._pensize, top)
self._update()
ifself._drawing:
screen._drawline(self.drawingLineItem, ((0, 0), (0, 0)),
fill="", width=self._pensize) # ---- calls _drawline(), causing the time complexity to be O(n**2) ----# Turtle now at end,ifself._drawing: # now update currentLineself.currentLine.append(end)
ifisinstance(self._fillpath, list):
self._fillpath.append(end)
###### vererbung!!!!!!!!!!!!!!!!!!!!!!self._position=endifself._creatingPoly:
self._poly.append(end)
iflen(self.currentLine) >42: # ---- hard-coded ----self._newLine()
self._update() #count=True)
The hard-coded number 42 performs well on my Ubuntu, but it seriously lowers the frame rate of complicated turtle programs on Windows. According to my own FPS test, the number 320 performs best on Windows.
On the other hand, the TurtleScreenBase._drawline method:
def_drawline(self, lineitem, coordlist=None,
fill=None, width=None, top=False):
"""Configure lineitem according to provided arguments: coordlist is sequence of coordinates fill is drawing color width is width of drawn line. top is a boolean value, which specifies if polyitem will be put on top of the canvas' displaylist so it will not be covered by other items. """ifcoordlistisnotNone:
cl= []
forx, yincoordlist: # ---- Repeats converting data ----cl.append(x*self.xscale)
cl.append(-y*self.yscale)
self.cv.coords(lineitem, *cl)
iffillisnotNone:
self.cv.itemconfigure(lineitem, fill=fill)
ifwidthisnotNone:
self.cv.itemconfigure(lineitem, width=width)
iftop:
self.cv.tag_raise(lineitem)
The current time complexity is O(n**2). With some data preprocessed in _goto method, the performance can be further optimized.
From my perspective, the turtle module could be an excellent substitute for original tkinter.Canvas if it were optimized significantly.
Additionally, this proposal originally comes from my own project's source code.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered:
Feature or enhancement
Proposal:
The original implementation of
turtle.RawTurtle._goto
:The hard-coded number
42
performs well on my Ubuntu, but it seriously lowers the frame rate of complicated turtle programs on Windows. According to my own FPS test, the number 320 performs best on Windows.On the other hand, the
TurtleScreenBase._drawline
method:The current time complexity is O(n**2). With some data preprocessed in
_goto
method, the performance can be further optimized.From my perspective, the
turtle
module could be an excellent substitute for originaltkinter.Canvas
if it were optimized significantly.Additionally, this proposal originally comes from my own project's source code.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: