diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 548d0b6..07e732d 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -638,6 +638,9 @@ def stamp(self, bitmap=None, palette=None): turtle position. Return a stamp_id for that stamp, which can be used to delete it by calling clearstamp(stamp_id). """ + # The restriction on max_size in displayio.Group has been removed. + # For now, leave this with a limit of 6 so as not to break any + # deployed code. if len(self._fg_addon_group) >= 6: print("Addon group full") return -1 @@ -654,7 +657,11 @@ def stamp(self, bitmap=None, palette=None): # odb bitmap new_stamp = displayio.TileGrid( self._turtle_odb, - pixel_shader=displayio.ColorConverter(), + pixel_shader=getattr( + self._turtle_odb, "pixel_shader", displayio.ColorConverter() + ), + # TODO: Once CP6 is no longer supported, replace the above line with below + # pixel_shader=self._turtle_odb.pixel_shader, x=int(self._x - self._turtle_odb.width // 2), y=int(self._y - self._turtle_odb.height // 2), ) @@ -967,7 +974,10 @@ def bgpic(self, picname=None): self._bg_pic = open(picname, "rb") odb = displayio.OnDiskBitmap(self._bg_pic) self._odb_tilegrid = displayio.TileGrid( - odb, pixel_shader=displayio.ColorConverter() + odb, + pixel_shader=getattr(odb, "pixel_shader", displayio.ColorConverter()), + # TODO: Once CP6 is no longer supported, replace the above line with below + # pixel_shader=odb.pixel_shader, ) self._bg_addon_group.append(self._odb_tilegrid) self._bg_pic_filename = picname @@ -1087,7 +1097,12 @@ def changeturtle(self, source=None, dimensions=(12, 12)): self._turtle_odb_use += 1 self._turtle_pic = True self._turtle_alt_sprite = displayio.TileGrid( - self._turtle_odb, pixel_shader=displayio.ColorConverter() + self._turtle_odb, + pixel_shader=getattr( + self._turtle_odb, "pixel_shader", displayio.ColorConverter() + ), + # TODO: Once CP6 is no longer supported, replace the above line with below + # pixel_shader=self._turtle_odb.pixel_shader, ) if self._turtle_group: diff --git a/examples/icons/Play_48x48_small.bmp b/examples/icons/Play_48x48_small.bmp new file mode 100644 index 0000000..eb446a1 Binary files /dev/null and b/examples/icons/Play_48x48_small.bmp differ diff --git a/examples/icons/Play_48x48_small.bmp.license b/examples/icons/Play_48x48_small.bmp.license new file mode 100644 index 0000000..92d94c9 --- /dev/null +++ b/examples/icons/Play_48x48_small.bmp.license @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries +# SPDX-License-Identifier: MIT diff --git a/examples/turtle_bgpic_changeturtle.py b/examples/turtle_bgpic_changeturtle.py new file mode 100644 index 0000000..e461854 --- /dev/null +++ b/examples/turtle_bgpic_changeturtle.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +import board +from adafruit_turtle import Color, turtle + +turtle = turtle(board.DISPLAY) + +# The purpose of this test is to check that the OnDiskBitmap usage is +# working correctly: bgpic(), changeturtle() & stamp() + +# Make sure that the following file is copied to the CircuitPython drive +ICON = "/icons/Play_48x48_small.bmp" +turtle.bgpic(ICON) +turtle.changeturtle(ICON) + +starsize = min(board.DISPLAY.width, board.DISPLAY.height) * 0.9 # 90% of screensize + +print("Turtle time! Lets draw a star") + +turtle.pencolor(Color.BLUE) +turtle.setheading(90) + +turtle.penup() +turtle.goto(-starsize / 2, 0) +turtle.pendown() + +start = turtle.pos() +while True: + turtle.forward(starsize) + turtle.stamp() + turtle.left(170) + if abs(turtle.pos() - start) < 1: + break + +while True: + pass