gh-88773: Added teleport method to Turtle library (#103974)

Add a `teleport` method to `turtle` module turtle instances that acts a lot like `goto`, _but_ ensures the pen is up while warping to the new position to and can control shape filling behavior as part of the jump.

Based on an educator user feature request.

---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Liam Gersten 2023-04-30 16:17:36 -04:00 committed by GitHub
parent 654d44b3a4
commit 74a2b79c62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 12 deletions

View file

@ -267,6 +267,14 @@ class TestTNavigator(VectorComparisonMixin, unittest.TestCase):
self.assertAlmostEqual(self.nav.xcor(), 100)
self.assertAlmostEqual(self.nav.ycor(), -100)
def test_teleport(self):
self.nav.teleport(20, -30, fill_gap=True)
self.assertAlmostEqual(self.nav.xcor(), 20)
self.assertAlmostEqual(self.nav.ycor(), -30)
self.nav.teleport(-20, 30, fill_gap=False)
self.assertAlmostEqual(self.nav.xcor(), -20)
self.assertAlmostEqual(self.nav.ycor(), 30)
def test_pos(self):
self.assertEqual(self.nav.pos(), self.nav._position)
self.nav.goto(100, -100)
@ -440,6 +448,18 @@ class TestTPen(unittest.TestCase):
tpen.showturtle()
self.assertTrue(tpen.isvisible())
def test_teleport(self):
tpen = turtle.TPen()
for fill_gap_value in [True, False]:
tpen.penup()
tpen.teleport(100, 100, fill_gap=fill_gap_value)
self.assertFalse(tpen.isdown())
tpen.pendown()
tpen.teleport(-100, -100, fill_gap=fill_gap_value)
self.assertTrue(tpen.isdown())
if __name__ == '__main__':
unittest.main()