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

Method towards

Python/Turtle.py:1759–1792  ·  view source on GitHub ↗

Return the angle of the line from the turtle's position to (x, y). Arguments: x -- a number or a pair/vector of numbers or a turtle instance y -- a number None None call: distance(x, y) # two coordinates --or:

(self, x, y=None)

Source from the content-addressed store, hash-verified

1757 return abs(pos - self._position)
1758
1759 def towards(self, x, y=None):
1760 """Return the angle of the line from the turtle's position to (x, y).
1761
1762 Arguments:
1763 x -- a number or a pair/vector of numbers or a turtle instance
1764 y -- a number None None
1765
1766 call: distance(x, y) # two coordinates
1767 --or: distance((x, y)) # a pair (tuple) of coordinates
1768 --or: distance(vec) # e.g. as returned by pos()
1769 --or: distance(mypen) # where mypen is another turtle
1770
1771 Return the angle, between the line from turtle-position to position
1772 specified by x, y and the turtle's start orientation. (Depends on
1773 modes - "standard" or "logo")
1774
1775 Example (for a Turtle instance named turtle):
1776 >>> turtle.pos()
1777 (10.00, 10.00)
1778 >>> turtle.towards(0,0)
1779 225.0
1780 """
1781 if y is not None:
1782 pos = Vec2D(x, y)
1783 if isinstance(x, Vec2D):
1784 pos = x
1785 elif isinstance(x, tuple):
1786 pos = Vec2D(*x)
1787 elif isinstance(x, TNavigator):
1788 pos = x._position
1789 x, y = pos - self._position
1790 result = round(math.atan2(y, x)*180.0/math.pi, 10) % 360.0
1791 result /= self._degreesPerAU
1792 return (self._angleOffset + self._angleOrient*result) % self._fullcircle
1793
1794 def heading(self):
1795 """ Return the turtle's current heading.

Callers 1

demo2Function · 0.80

Calls 1

Vec2DClass · 0.85

Tested by

no test coverage detected