Skip to content

Commit cb3d4b5

Browse files
authored
Merge pull request #25 from lesamouraipourpre/ondiskbitmap-changes
Update the pixel_shader usage of OnDiskBitmap
2 parents 2dab785 + 15e766f commit cb3d4b5

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

adafruit_turtle.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ def stamp(self, bitmap=None, palette=None):
641641
turtle position. Return a stamp_id for that stamp, which can be used to
642642
delete it by calling clearstamp(stamp_id).
643643
"""
644+
# The restriction on max_size in displayio.Group has been removed.
645+
# For now, leave this with a limit of 6 so as not to break any
646+
# deployed code.
644647
if len(self._fg_addon_group) >= 6:
645648
print("Addon group full")
646649
return -1
@@ -657,7 +660,11 @@ def stamp(self, bitmap=None, palette=None):
657660
# odb bitmap
658661
new_stamp = displayio.TileGrid(
659662
self._turtle_odb,
660-
pixel_shader=displayio.ColorConverter(),
663+
pixel_shader=getattr(
664+
self._turtle_odb, "pixel_shader", displayio.ColorConverter()
665+
),
666+
# TODO: Once CP6 is no longer supported, replace the above line with below
667+
# pixel_shader=self._turtle_odb.pixel_shader,
661668
x=int(self._x - self._turtle_odb.width // 2),
662669
y=int(self._y - self._turtle_odb.height // 2),
663670
)
@@ -970,7 +977,10 @@ def bgpic(self, picname=None):
970977
with open(picname, "rb") as self._bg_pic:
971978
odb = displayio.OnDiskBitmap(self._bg_pic)
972979
self._odb_tilegrid = displayio.TileGrid(
973-
odb, pixel_shader=displayio.ColorConverter()
980+
odb,
981+
pixel_shader=getattr(odb, "pixel_shader", displayio.ColorConverter()),
982+
# TODO: Once CP6 is no longer supported, replace the above line with below
983+
# pixel_shader=odb.pixel_shader,
974984
)
975985
self._bg_addon_group.append(self._odb_tilegrid)
976986
self._bg_pic_filename = picname
@@ -1092,7 +1102,12 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
10921102
self._turtle_odb_use += 1
10931103
self._turtle_pic = True
10941104
self._turtle_alt_sprite = displayio.TileGrid(
1095-
self._turtle_odb, pixel_shader=displayio.ColorConverter()
1105+
self._turtle_odb,
1106+
pixel_shader=getattr(
1107+
self._turtle_odb, "pixel_shader", displayio.ColorConverter()
1108+
),
1109+
# TODO: Once CP6 is no longer supported, replace the above line with below
1110+
# pixel_shader=self._turtle_odb.pixel_shader,
10961111
)
10971112

10981113
if self._turtle_group:

examples/icons/Play_48x48_small.bmp

1.27 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries
2+
# SPDX-License-Identifier: MIT

examples/turtle_bgpic_changeturtle.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
from adafruit_turtle import Color, turtle
6+
7+
turtle = turtle(board.DISPLAY)
8+
9+
# The purpose of this test is to check that the OnDiskBitmap usage is
10+
# working correctly: bgpic(), changeturtle() & stamp()
11+
12+
# Make sure that the following file is copied to the CircuitPython drive
13+
ICON = "/icons/Play_48x48_small.bmp"
14+
turtle.bgpic(ICON)
15+
turtle.changeturtle(ICON)
16+
17+
starsize = min(board.DISPLAY.width, board.DISPLAY.height) * 0.9 # 90% of screensize
18+
19+
print("Turtle time! Lets draw a star")
20+
21+
turtle.pencolor(Color.BLUE)
22+
turtle.setheading(90)
23+
24+
turtle.penup()
25+
turtle.goto(-starsize / 2, 0)
26+
turtle.pendown()
27+
28+
start = turtle.pos()
29+
while True:
30+
turtle.forward(starsize)
31+
turtle.stamp()
32+
turtle.left(170)
33+
if abs(turtle.pos() - start) < 1:
34+
break
35+
36+
while True:
37+
pass

0 commit comments

Comments
 (0)