mirror of
https://github.com/python/cpython.git
synced 2025-09-30 20:31:52 +00:00
Split the goto() function in two: _goto() is the internal one,
using Canvas coordinates, and goto() uses turtle coordinates and accepts variable argument lists.
This commit is contained in:
parent
2457fc2a81
commit
5ac15bc9c8
1 changed files with 9 additions and 5 deletions
|
@ -55,7 +55,7 @@ class RawPen:
|
||||||
x0, y0 = start = self._position
|
x0, y0 = start = self._position
|
||||||
x1 = x0 + distance * cos(self._angle*self._invradian)
|
x1 = x0 + distance * cos(self._angle*self._invradian)
|
||||||
y1 = y0 - distance * sin(self._angle*self._invradian)
|
y1 = y0 - distance * sin(self._angle*self._invradian)
|
||||||
self.goto(x1, y1)
|
self._goto(x1, y1)
|
||||||
|
|
||||||
def backward(self, distance):
|
def backward(self, distance):
|
||||||
self.forward(-distance)
|
self.forward(-distance)
|
||||||
|
@ -106,14 +106,14 @@ class RawPen:
|
||||||
|
|
||||||
def write(self, arg, move=0):
|
def write(self, arg, move=0):
|
||||||
x, y = start = self._position
|
x, y = start = self._position
|
||||||
|
x = x-1 # correction -- calibrated for Windows
|
||||||
item = self._canvas.create_text(x, y,
|
item = self._canvas.create_text(x, y,
|
||||||
text=str(arg), anchor="sw",
|
text=str(arg), anchor="sw",
|
||||||
fill=self._color)
|
fill=self._color)
|
||||||
self._items.append(item)
|
self._items.append(item)
|
||||||
if move:
|
if move:
|
||||||
x0, y0, x1, y1 = self._canvas.bbox(item)
|
x0, y0, x1, y1 = self._canvas.bbox(item)
|
||||||
x1 = x1-1 # correction -- calibrated for Windows
|
self._goto(x1, y1)
|
||||||
self.goto(x1, y1)
|
|
||||||
|
|
||||||
def fill(self, flag):
|
def fill(self, flag):
|
||||||
if self._filling:
|
if self._filling:
|
||||||
|
@ -187,14 +187,18 @@ class RawPen:
|
||||||
def goto(self, *args):
|
def goto(self, *args):
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
try:
|
try:
|
||||||
x1, y1 = args[0]
|
x, y = args[0]
|
||||||
except:
|
except:
|
||||||
raise Error, "bad point argument: %s" % `args[0]`
|
raise Error, "bad point argument: %s" % `args[0]`
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
x1, y1 = args
|
x, y = args
|
||||||
except:
|
except:
|
||||||
raise Error, "bad coordinates: %s" % `args[0]`
|
raise Error, "bad coordinates: %s" % `args[0]`
|
||||||
|
x0, y0 = self._origin
|
||||||
|
self._goto(x0+x, y0-y)
|
||||||
|
|
||||||
|
def _goto(self, x1, y1):
|
||||||
x0, y0 = start = self._position
|
x0, y0 = start = self._position
|
||||||
self._position = map(float, (x1, y1))
|
self._position = map(float, (x1, y1))
|
||||||
if self._filling:
|
if self._filling:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue