Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions adafruit_turtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Binary file added examples/icons/Play_48x48_small.bmp
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/icons/Play_48x48_small.bmp.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries
# SPDX-License-Identifier: MIT
37 changes: 37 additions & 0 deletions examples/turtle_bgpic_changeturtle.py
Original file line number Diff line number Diff line change
@@ -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