Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-65276: Fixed Turtle library circle method bug #104022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
22 changes: 17 additions & 5 deletions Lib/turtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,19 @@ def circle(self, radius, extent = None, steps = None):
self._rotate(w)
self._rotate(-w2)
if speed == 0:
self._tracer(tr, dl)
previous_values = []
for t in self.screen.turtles():
if t == self:
continue
value_tuple = (t, t._shown, t._hidden_from_screen)
t._shown = False
t._hidden_from_screen = True
previous_values.append(value_tuple)
self._tracer(flag=tr, delay=dl)
for values in previous_values:
t, _shown, _hidden_from_screen = values
t._shown = _shown
t._hidden_from_screen = _hidden_from_screen
self.speed(speed)
if self.undobuffer:
self.undobuffer.cumulate = False
Expand Down Expand Up @@ -2726,7 +2738,7 @@ def _cc(self, args):
if not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255)):
raise TurtleGraphicsError("bad color sequence: %s" % str(args))
return "#%02x%02x%02x" % (r, g, b)

def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None:
"""Instantly move turtle to an absolute position.

Expand All @@ -2738,14 +2750,14 @@ def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None:
call: teleport(x, y) # two coordinates
--or: teleport(x) # teleport to x position, keeping y as is
--or: teleport(y=y) # teleport to y position, keeping x as is
--or: teleport(x, y, fill_gap=True)
--or: teleport(x, y, fill_gap=True)
# teleport but fill the gap in between

Move turtle to an absolute position. Unlike goto(x, y), a line will not
be drawn. The turtle's orientation does not change. If currently
filling, the polygon(s) teleported from will be filled after leaving,
and filling will begin again after teleporting. This can be disabled
with fill_gap=True, which makes the imaginary line traveled during
with fill_gap=True, which makes the imaginary line traveled during
teleporting act as a fill barrier like in goto(x, y).

Example (for a Turtle instance named turtle):
Expand Down Expand Up @@ -2773,7 +2785,7 @@ def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None:
self._position = Vec2D(new_x, new_y)
self.pen(pendown=pendown)
if was_filling and not fill_gap:
self.begin_fill()
self.begin_fill()

def clone(self):
"""Create and return a clone of the turtle.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed bug in the :mod:`turtle` module's :func:`turtle.circle` method, where calling with speed 0 made some objects disappear.
Patch by Liam Gersten.