Skip to content

Commit 63a6ffb

Browse files
authored
Merge pull request #48 from FoamyGuy/visible_turtle_loc_fix
fix for visible turtle location
2 parents 49d941a + 277983a commit 63a6ffb

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

adafruit_turtle.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ def __init__(
311311
self._turtle_pic = None
312312
self._turtle_odb = None
313313
self._turtle_alt_sprite = None
314+
self._turtle_x = self._x
315+
self._turtle_y = self._y
314316
self._drawturtle()
315317
self._stamps = {}
316318
self._turtle_odb_use = 0
@@ -323,15 +325,23 @@ def __init__(
323325

324326
def _drawturtle(self) -> None:
325327
if self._turtle_pic is None:
326-
self._turtle_sprite.x = int(self._x - 4)
327-
self._turtle_sprite.y = int(self._y - 4)
328+
self._turtle_sprite.x = int(self._turtle_x - 4)
329+
self._turtle_sprite.y = int(self._turtle_y - 4)
328330
else:
329331
if self._turtle_odb is not None:
330-
self._turtle_alt_sprite.x = int(self._x - self._turtle_odb.width // 2)
331-
self._turtle_alt_sprite.y = int(self._y - self._turtle_odb.height // 2)
332+
self._turtle_alt_sprite.x = int(
333+
self._turtle_x - self._turtle_odb.width // 2
334+
)
335+
self._turtle_alt_sprite.y = int(
336+
self._turtle_y - self._turtle_odb.height // 2
337+
)
332338
else:
333-
self._turtle_alt_sprite.x = int(self._x - self._turtle_pic[0] // 2)
334-
self._turtle_alt_sprite.y = int(self._y - self._turtle_pic[1] // 2)
339+
self._turtle_alt_sprite.x = int(
340+
self._turtle_x - self._turtle_pic[0] // 2
341+
)
342+
self._turtle_alt_sprite.y = int(
343+
self._turtle_y - self._turtle_pic[1] // 2
344+
)
335345

336346
###########################################################################
337347
# Move and draw
@@ -448,11 +458,15 @@ def _do_draw_line(self, x0: int, y0: int, xn: int, yn: int):
448458
self._plot(int(y0), int(x0), self._pencolor)
449459
except IndexError:
450460
pass
461+
self._turtle_x = y0
462+
self._turtle_y = x0
451463
else:
452464
try:
453465
self._plot(int(x0), int(y0), self._pencolor)
454466
except IndexError:
455467
pass
468+
self._turtle_x = x0
469+
self._turtle_y = y0
456470
if self._speed > 0:
457471
if step >= self._speed:
458472
# mark the step

0 commit comments

Comments
 (0)