From: Kevin A. <ka...@us...> - 2004-05-11 13:04:06
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21191 Modified Files: turtle.py Log Message: added push and pop Index: turtle.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/turtle.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** turtle.py 9 May 2004 19:46:05 -0000 1.18 --- turtle.py 11 May 2004 13:03:56 -0000 1.19 *************** *** 315,318 **** --- 315,320 ---- self._savePosition = self._position self._saveAngle = self._angle + # used for LIFO stack of turtle state + self._turtleStack = [] self._odometer = 0.0 # don't waste time tracking unless requested *************** *** 360,371 **** --- 362,391 ---- self._position = (float(x1), float(y1)) + # could save more than position and heading below + # perhaps the turtle color, whether it is shown or not? + def saveState(self): + """save the current turtle position and heading""" self._savePosition = self._position self._saveAngle = self._angle def restoreState(self): + """restore the turtle position and heading to the last saved state""" self.moveTo(self._savePosition[0], self._savePosition[1]) self.setHeading(self._saveAngle) + def push(self): + """push the current turtle position and heading onto a LIFO stack""" + self._turtleStack.append((self._position, self._angle)) + + def pop(self): + """set the turtle position and heading to the state popped from a LIFO stack""" + try: + position, angle = self._turtleStack.pop() + self.moveTo(position[0], position[1]) + self.setHeading(angle) + except IndexError: + pass + class BitmapTurtle(AbstractTurtle): |