--- orig/turtle.py 2002-08-14 16:49:14.000000000 +0200 +++ ./turtle.py 2002-08-14 18:15:07.000000000 +0200 @@ -2,6 +2,7 @@ from math import * # Also for export import Tkinter + class Error(Exception): pass @@ -52,7 +53,6 @@ self._delete_turtle() self._draw_turtle() - def tracer(self, flag): self._tracing = flag if not self._tracing: @@ -117,7 +117,6 @@ self._color = color self._draw_turtle() - def write(self, arg, move=0): x, y = start = self._position x = x-1 # correction -- calibrated for Windows @@ -198,6 +197,41 @@ self._position = x1, y1 if self._filling: self._path.append(self._position) + self._draw_turtle() + + def heading(self): + return self._angle + + def setheading(self, angle): + self._angle = angle + self._draw_turtle() + + def window_width(self): + width = self._canvas.winfo_width() + if width <= 1: # the window isn't managed by a geometry manager + width = self._canvas['width'] + return width + + def window_height(self): + height = self._canvas.winfo_height() + if height <= 1: # the window isn't managed by a geometry manager + height = self._canvas['height'] + return height + + def position(self): + x0, y0 = self._origin + x1, y1 = self._position + return [x1-x0, -y1+y0] + + def setx(self, xpos): + x0, y0 = self._origin + x1, y1 = self._position + self._goto(x0+xpos, y1) + + def sety(self, ypos): + x0, y0 = self._origin + x1, y1 = self._position + self._goto(x1, -y1+y0) def goto(self, *args): if len(args) == 1: @@ -219,15 +253,16 @@ if self._filling: self._path.append(self._position) if self._drawing: + item = self._canvas.create_line(x0, y0, x1, y1, + width=self._width, + capstyle="round", + fill=self._color) + self._items.append(item) if self._tracing: dx = float(x1 - x0) dy = float(y1 - y0) distance = hypot(dx, dy) nhops = int(distance) - item = self._canvas.create_line(x0, y0, x0, y0, - width=self._width, - capstyle="round", - fill=self._color) try: for i in range(1, 1+nhops): x, y = x0 + dx*i/nhops, y0 + dy*i/nhops @@ -241,29 +276,22 @@ except Tkinter.TclError: # Probably the window was closed! return - else: - item = self._canvas.create_line(x0, y0, x1, y1, - width=self._width, - capstyle="round", - fill=self._color) - self._items.append(item) - self._draw_turtle() + self._draw_turtle() def _draw_turtle(self,position=[]): - if not self._tracing: - return - if position == []: - position = self._position - x,y = position - distance = 8 - dx = distance * cos(self._angle*self._invradian) - dy = distance * sin(self._angle*self._invradian) - self._delete_turtle() - self._arrow = self._canvas.create_line(x-dx,y+dy,x,y, - width=self._width, - arrow="last", - capstyle="round", - fill=self._color) + if self._tracing: + if position == []: + position = self._position + x,y = position + distance = 8 + dx = distance * cos(self._angle*self._invradian) + dy = distance * sin(self._angle*self._invradian) + self._delete_turtle() + self._arrow = self._canvas.create_line(x-dx,y+dy,x,y, + width=self._width, + arrow="last", + capstyle="round", + fill=self._color) self._canvas.update() def _delete_turtle(self): @@ -324,6 +352,13 @@ def fill(flag): _getpen().fill(flag) def circle(radius, extent=None): _getpen().circle(radius, extent) def goto(*args): apply(_getpen().goto, args) +def heading(): return _getpen().heading() +def setheading(angle): _getpen().setheading(angle) +def position(): return _getpen().position() +def window_width(): return _getpen().window_width() +def window_height(): return _getpen().window_height() +def setx(xpos): _getpen().setx(xpos) +def sety(ypos): _getpen().sety(ypos) def demo(): reset()