Movement¶
- movement.fly(x, y)[source]¶
Moves the turtle to (x,y) without drawing.
This is really just a simple shortcut for lifting the pen, going to a position, and putting the pen down again. But it’s such a commonly-used pattern that it makes sense to put it into a function. Here’s an example:
from turtle import setheading, forward from movement import fly from math import sin, cos, tau def to_radians(degrees): return degrees * (tau / 360) for angle in range(0, 360, 20): fly(50 * cos(to_radians(angle)), 50 * sin(to_radians(angle))) setheading(angle) forward(100)
- movement.update_position(x, y=None)[source]¶
Updates the turtle’s position, adding x to the turtle’s current x and y to the turtle’s current y. Generally, this function should be called with two arguments, but it may also be called with a list containing x and y values:
update_position(10, 20) update_position([10, 20])
- class movement.restore_state_when_finished[source]¶
A context manager which records the turtle’s position and heading at the beginning and restores them at the end of the code block. For example:
from turtle import forward, right from helpers import restore_state_when_finished for angle in range(0, 360, 15): with restore_state_when_finished(): right(angle) forward(100)