MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / _undogoto

Method _undogoto

Python/Turtle.py:3096–3159  ·  view source on GitHub ↗

Reverse a _goto. Used for undo()

(self, entry)

Source from the content-addressed store, hash-verified

3094 self._update() #count=True)
3095
3096 def _undogoto(self, entry):
3097 """Reverse a _goto. Used for undo()
3098 """
3099 old, new, go_modes, coodata = entry
3100 drawing, pc, ps, filling = go_modes
3101 cLI, cL, pl, items = coodata
3102 screen = self.screen
3103 if abs(self._position - new) > 0.5:
3104 print ("undogoto: HALLO-DA-STIMMT-WAS-NICHT!")
3105 # restore former situation
3106 self.currentLineItem = cLI
3107 self.currentLine = cL
3108
3109 if pl == [(0, 0), (0, 0)]:
3110 usepc = ""
3111 else:
3112 usepc = pc
3113 screen._drawline(cLI, pl, fill=usepc, width=ps)
3114
3115 todelete = [i for i in self.items if (i not in items) and
3116 (screen._type(i) == "line")]
3117 for i in todelete:
3118 screen._delete(i)
3119 self.items.remove(i)
3120
3121 start = old
3122 if self._speed and screen._tracing == 1:
3123 diff = old - new
3124 diffsq = (diff[0]*screen.xscale)**2 + (diff[1]*screen.yscale)**2
3125 nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
3126 delta = diff * (1.0/nhops)
3127 for n in range(1, nhops):
3128 if n == 1:
3129 top = True
3130 else:
3131 top = False
3132 self._position = new + delta * n
3133 if drawing:
3134 screen._drawline(self.drawingLineItem,
3135 (start, self._position),
3136 pc, ps, top)
3137 self._update()
3138 if drawing:
3139 screen._drawline(self.drawingLineItem, ((0, 0), (0, 0)),
3140 fill="", width=ps)
3141 # Turtle now at position old,
3142 self._position = old
3143 ## if undo is done during creating a polygon, the last vertex
3144 ## will be deleted. if the polygon is entirely deleted,
3145 ## creatingPoly will be set to False.
3146 ## Polygons created before the last one will not be affected by undo()
3147 if self._creatingPoly:
3148 if len(self._poly) > 0:
3149 self._poly.pop()
3150 if self._poly == []:
3151 self._creatingPoly = False
3152 self._poly = None
3153 if filling:

Callers 1

_undoMethod · 0.95

Calls 7

_updateMethod · 0.95
_drawlineMethod · 0.80
_typeMethod · 0.80
_deleteMethod · 0.80
printFunction · 0.50
removeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected