Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the angle of a turtle in Python

I'm creating a function that will cause a giraffe to move in a certain direction and distance (don't ask).

If the user types "west" in the parameters, the turtle should move west however the direction is. But the turtle's angle changes every time, I can't fix a value for my turtle to turn to go a certain direction.

I need to set the angle to, say, 90 so that it can move East. I can't find useful functions for this purpose. I tried to use Pen().degrees(90) but that didn't work. Does anyone know how I can do this?

like image 854
Jonathan Spirit Avatar asked Dec 10 '13 18:12

Jonathan Spirit


1 Answers

You're looking for turtle.setheading()

>>> turtle.setheading(90)
>>> turtle.heading()
90.0

You can combine this with a simple dict to get exactly the result you are after.

like image 87
stranac Avatar answered Sep 21 '22 11:09

stranac