From 017591b4d49fc33a1fd3309b0a050a7ff076cad9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 10:53:31 -0500 Subject: [PATCH 1/4] try has-a tuple instead of is-a tuple for Vec2D --- adafruit_turtle.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index ca6b6a2..24b80f0 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -80,7 +80,7 @@ def __init__(self): pass -class Vec2D(tuple): +class Vec2D: """A 2 dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs also. @@ -95,7 +95,11 @@ class Vec2D(tuple): # |a| absolute value of a # a.rotate(angle) rotation def __init__(self, x, y): - super().__init__((x, y)) + # super().__init__() + self.values = (x, y) + + def __getitem__(self, index): + return self.values[index] def __add__(self, other): return Vec2D(self[0] + other[0], self[1] + other[1]) @@ -268,8 +272,8 @@ def forward(self, distance): """ p = self.pos() angle = ( - self._angleOffset + self._angleOrient * self._heading - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading + ) % self._fullcircle x1 = p[0] + math.sin(math.radians(angle)) * distance y1 = p[1] + math.cos(math.radians(angle)) * distance self.goto(x1, y1) @@ -397,6 +401,7 @@ def goto(self, x1, y1=None): setpos = goto setposition = goto + # pylint:enable=too-many-branches,too-many-statements def setx(self, x): @@ -455,8 +460,8 @@ def _plot(self, x, y, c): pass r = self._pensize // 2 + 1 angle = ( - self._angleOffset + self._angleOrient * self._heading - 90 - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading - 90 + ) % self._fullcircle sin = math.sin(math.radians(angle)) cos = math.cos(math.radians(angle)) x0 = x + sin * r From 5acb2d0585eab612973e78b766d36fb3a5ed9b6a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 11:04:45 -0500 Subject: [PATCH 2/4] only import board if we are going to try to use builtin display --- adafruit_turtle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 24b80f0..4938c29 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -30,7 +30,6 @@ import gc import math import time -import board import displayio __version__ = "0.0.0+auto.0" @@ -151,6 +150,7 @@ def __init__(self, display=None, scale=1): self._display = display else: try: + import board self._display = board.DISPLAY except AttributeError as err: raise RuntimeError( From c146d6bb77866c419b857c8d9ce02412c748f6a4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 11:10:10 -0500 Subject: [PATCH 3/4] allow import outside top for board --- adafruit_turtle.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 4938c29..2c5f046 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -150,7 +150,9 @@ def __init__(self, display=None, scale=1): self._display = display else: try: + # pylint: disable=import-outside-toplevel import board + self._display = board.DISPLAY except AttributeError as err: raise RuntimeError( @@ -272,8 +274,8 @@ def forward(self, distance): """ p = self.pos() angle = ( - self._angleOffset + self._angleOrient * self._heading - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading + ) % self._fullcircle x1 = p[0] + math.sin(math.radians(angle)) * distance y1 = p[1] + math.cos(math.radians(angle)) * distance self.goto(x1, y1) @@ -460,8 +462,8 @@ def _plot(self, x, y, c): pass r = self._pensize // 2 + 1 angle = ( - self._angleOffset + self._angleOrient * self._heading - 90 - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading - 90 + ) % self._fullcircle sin = math.sin(math.radians(angle)) cos = math.cos(math.radians(angle)) x0 = x + sin * r From 87ee248a953a4c3fc307881e21d1b697c0a12c4b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 11:11:26 -0500 Subject: [PATCH 4/4] remove unused super init --- adafruit_turtle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 2c5f046..4f49fa0 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -94,7 +94,6 @@ class Vec2D: # |a| absolute value of a # a.rotate(angle) rotation def __init__(self, x, y): - # super().__init__() self.values = (x, y) def __getitem__(self, index):