Skip to content

Commit

Permalink
Merge pull request #12 from caternuson/disp_fix
Browse files Browse the repository at this point in the history
External display and time.sleep patches.
  • Loading branch information
ladyada committed Oct 15, 2019
2 parents bae9464 + 2f7b1a1 commit 0808605
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions adafruit_turtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@ def __repr__(self):
class turtle(object):
"""A Turtle that can be given commands to draw."""

def __init__(self, display=board.DISPLAY):
def __init__(self, display=None):
if display:
self._display = display
else:
try:
self._display = board.DISPLAY
except AttributeError:
raise RuntimeError("No display available. One must be provided.")
self._logger = logging.getLogger("Turtle")
self._logger.setLevel(logging.INFO)
self._display = display
self._w = self._display.width
self._h = self._display.height
self._x = self._w // 2
Expand Down Expand Up @@ -193,9 +199,7 @@ def __init__(self, display=board.DISPLAY):
self.pencolor(Color.WHITE)

self._display.show(self._splash)
self._display.refresh_soon()
gc.collect()
self._display.wait_for_frame()

def _drawturtle(self):
self._turtle_sprite.x = int(self._x - 4)
Expand Down Expand Up @@ -298,7 +302,6 @@ def goto(self, x1, y1=None):
self._x = y0
self._y = x0
self._drawturtle()
time.sleep(0.003)
else:
try:
self._plot(int(x0), int(y0), self._pencolor)
Expand All @@ -307,7 +310,6 @@ def goto(self, x1, y1=None):
self._x = x0
self._y = y0
self._drawturtle()
time.sleep(0.003)
err -= dy
if err < 0:
y0 += ystep
Expand Down Expand Up @@ -804,10 +806,8 @@ def clear(self):
self._fg_bitmap[w, h] = 0
for i, c in enumerate(Color.colors):
self._fg_palette[i + 1] = c ^ 0xFFFFFF
self._display.refresh_soon()
for i, c in enumerate(Color.colors):
self._fg_palette[i + 1] = c
self._display.refresh_soon()
time.sleep(0.1)

def write(self, arg, move=False, align="left", font=("Arial", 8, "normal")):
Expand Down

0 comments on commit 0808605

Please sign in to comment.