diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 23b2a54..1df457a 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -46,21 +46,84 @@ class Color: """Standard colors""" WHITE = 0xFFFFFF + """0xFFFFFF + + :meta hide-value:""" + BLACK = 0x000000 + """0x000000 + + :meta hide-value:""" + RED = 0xFF0000 + """0xFF0000 + + :meta hide-value:""" + ORANGE = 0xFFA500 + """0xFFA500 + + :meta hide-value:""" + YELLOW = 0xFFEE00 + """0xFFEE00 + + :meta hide-value:""" + GREEN = 0x00C000 + """0x00C000 + + :meta hide-value:""" + BLUE = 0x0000FF + """0x0000FF + + :meta hide-value:""" + PURPLE = 0x8040C0 + """0x8040C0 + + :meta hide-value:""" + PINK = 0xFF40C0 + """0xFF40C0 + + :meta hide-value:""" + LIGHT_GRAY = 0xAAAAAA + """0xAAAAAA + + :meta hide-value:""" + GRAY = 0x444444 + """0x444444 + + :meta hide-value:""" + BROWN = 0xCA801D + """0xCA801D + + :meta hide-value:""" + DARK_GREEN = 0x008700 + """0x008700 + + :meta hide-value:""" + TURQUOISE = 0x00C0C0 + """0x00C0C0 + + :meta hide-value:""" + DARK_BLUE = 0x0000AA + """0x0000AA + + :meta hide-value:""" + DARK_RED = 0x800000 + """0x800000 + + :meta hide-value:""" colors = ( BLACK, @@ -171,11 +234,11 @@ def __init__( self._y = self._h // (2 * scale) self._speed = 6 self._heading: float = 0 - self._logomode = True self._fullcircle = 360.0 self._degreesPerAU = 1.0 - self._angleOrient = 1 - self._angleOffset: float = 0 + self._logomode = False + self._angleOrient = -1 + self._angleOffset: float = self._fullcircle / 4 self._bg_color = 0 self._splash: displayio.Group = displayio.Group() @@ -248,6 +311,8 @@ def __init__( self._turtle_pic = None self._turtle_odb = None self._turtle_alt_sprite = None + self._turtle_x = self._x + self._turtle_y = self._y self._drawturtle() self._stamps = {} self._turtle_odb_use = 0 @@ -260,15 +325,23 @@ def __init__( def _drawturtle(self) -> None: if self._turtle_pic is None: - self._turtle_sprite.x = int(self._x - 4) - self._turtle_sprite.y = int(self._y - 4) + self._turtle_sprite.x = int(self._turtle_x - 4) + self._turtle_sprite.y = int(self._turtle_y - 4) else: if self._turtle_odb is not None: - self._turtle_alt_sprite.x = int(self._x - self._turtle_odb.width // 2) - self._turtle_alt_sprite.y = int(self._y - self._turtle_odb.height // 2) + self._turtle_alt_sprite.x = int( + self._turtle_x - self._turtle_odb.width // 2 + ) + self._turtle_alt_sprite.y = int( + self._turtle_y - self._turtle_odb.height // 2 + ) else: - self._turtle_alt_sprite.x = int(self._x - self._turtle_pic[0] // 2) - self._turtle_alt_sprite.y = int(self._y - self._turtle_pic[1] // 2) + self._turtle_alt_sprite.x = int( + self._turtle_x - self._turtle_pic[0] // 2 + ) + self._turtle_alt_sprite.y = int( + self._turtle_y - self._turtle_pic[1] // 2 + ) ########################################################################### # Move and draw @@ -344,13 +417,17 @@ def goto( xn: float = x1[0] if y1 is None else x1 # type: ignore xn += self._w // 2 yn = self._h // 2 - yn - x0 = self._x - y0 = self._y if not self.isdown(): self._x = xn # woot, we just skip ahead self._y = yn self._drawturtle() return + + self._do_draw_line(round(self._x), round(self._y), round(xn), round(yn)) + self._x = xn + self._y = yn + + def _do_draw_line(self, x0: int, y0: int, xn: int, yn: int): steep = abs(yn - y0) > abs(xn - x0) rev = False dx = xn - x0 @@ -381,15 +458,15 @@ def goto( self._plot(int(y0), int(x0), self._pencolor) except IndexError: pass - self._x = y0 - self._y = x0 + self._turtle_x = y0 + self._turtle_y = x0 else: try: self._plot(int(x0), int(y0), self._pencolor) except IndexError: pass - self._x = x0 - self._y = y0 + self._turtle_x = x0 + self._turtle_y = y0 if self._speed > 0: if step >= self._speed: # mark the step @@ -563,6 +640,12 @@ def circle( # --or: circle(radius, extent) # arc # --or: circle(radius, extent, steps) # --or: circle(radius, steps=6) # 6-sided polygon + change_back = False + if not self._in_degrees(): + change_back = True + original_mode = "standard" if not self._logomode else "logo" + self.degrees() + self.mode("standard") pos = self.pos() h = self._heading if extent is None: @@ -584,6 +667,9 @@ def circle( # get back to exact same position and heading self.goto(pos) self.setheading(h) + if change_back: + self.radians() + self.mode(original_mode) # pylint:disable=inconsistent-return-statements def speed(self, speed: Optional[int] = None) -> Optional[int]: @@ -627,6 +713,13 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: :param color: the color of the dot """ + change_back = False + if not self._in_degrees(): + change_back = True + original_mode = "standard" if not self._logomode else "logo" + print(f"old mode: {original_mode}") + self.degrees() + self.mode("standard") if size is None: size = max(self._pensize + 4, self._pensize * 2) if color is None: @@ -650,6 +743,9 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: self._pensize = 1 self._plot(self._x, self._y, color) self._pensize = pensize + if change_back: + self.radians() + self.mode(original_mode) def stamp( self, @@ -819,6 +915,10 @@ def degrees(self, fullcircle: float = 360) -> None: """ self._setDegreesPerAU(fullcircle) + def _in_degrees(self) -> bool: + print(self._degreesPerAU) + return self._degreesPerAU == 1.0 + def radians(self) -> None: """Set the angle measurement units to radians. Equivalent to degrees(2*math.pi).""" diff --git a/docs/conf.py b/docs/conf.py index 58baf1e..e4137e6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -39,7 +39,6 @@ "adafruit_bitmap_font", "adafruit_display_text", "adafruit_esp32spi", - "secrets", "adafruit_sdcard", "storage", "adafruit_io", @@ -127,7 +126,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme