Skip to content

Commit 49d941a

Browse files
authored
Merge pull request #45 from adafruit/issue41
Account for fractions of a pixel when drawing
2 parents 06de267 + 614e9e2 commit 49d941a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

adafruit_turtle.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,17 @@ def goto(
407407
xn: float = x1[0] if y1 is None else x1 # type: ignore
408408
xn += self._w // 2
409409
yn = self._h // 2 - yn
410-
x0 = self._x
411-
y0 = self._y
412410
if not self.isdown():
413411
self._x = xn # woot, we just skip ahead
414412
self._y = yn
415413
self._drawturtle()
416414
return
415+
416+
self._do_draw_line(round(self._x), round(self._y), round(xn), round(yn))
417+
self._x = xn
418+
self._y = yn
419+
420+
def _do_draw_line(self, x0: int, y0: int, xn: int, yn: int):
417421
steep = abs(yn - y0) > abs(xn - x0)
418422
rev = False
419423
dx = xn - x0
@@ -444,15 +448,11 @@ def goto(
444448
self._plot(int(y0), int(x0), self._pencolor)
445449
except IndexError:
446450
pass
447-
self._x = y0
448-
self._y = x0
449451
else:
450452
try:
451453
self._plot(int(x0), int(y0), self._pencolor)
452454
except IndexError:
453455
pass
454-
self._x = x0
455-
self._y = y0
456456
if self._speed > 0:
457457
if step >= self._speed:
458458
# mark the step

0 commit comments

Comments
 (0)