The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
turtle.towards()
This function is used to return the angle, between the line from turtle-position to the position specified by x, y, and the turtle’s start orientation.
Syntax :
turtle.towards(x, y=None)
Parameters:
Arguments | Description |
x | a number or a pair/vector of numbers or a turtle instance |
y | a number or None or None |
Below is the implementation of the above method with an example :
Python3
# import package import turtle # go towards east ang = turtle.towards( 100 , 0 ) # print angle print (ang) # go towards north ang = turtle.towards( 0 , 100 ) # print angle print (ang) # go towards west ang = turtle.towards( - 100 , 0 ) # print angle print (ang) # go towards south ang = turtle.towards( 0 , - 100 ) # print angle print (ang) |
Output :
0.0 90.0 180.0 270.0
Here we can see that one can easily get an angle towards any coordinate point without going to that point. In the above example turtle remain on (0,0) i.e. home and get all angles to the specified position without any movement.