Skip to content

Instantly share code, notes, and snippets.

@kmatch98
Created August 24, 2020 22:32
Show Gist options
  • Save kmatch98/0cfd1a2a5ae4dab7969ccef01be4b797 to your computer and use it in GitHub Desktop.
Save kmatch98/0cfd1a2a5ae4dab7969ccef01be4b797 to your computer and use it in GitHub Desktop.
Test script evaluating TileGrid and Bitmap references
import gc
import time
import board
import displayio
import terminalio
class testGroup(displayio.Group):
def __init__(self,
color):
# creates a Group containing a TileGrid with a 200x200 Bitmap with the given color
self._color=color
self.bitmap=displayio.Bitmap(200, 200, 1)
self.palette=displayio.Palette(1)
self.palette[0]=self._color
self.tilegrid = displayio.TileGrid(
self.bitmap,
pixel_shader=self.palette,
width=1,
height=1,
tile_width=self.bitmap.width,
tile_height=self.bitmap.height,
default_tile=0,
x=0,
y=0,
)
super().__init__(
max_size=1,
x=10,
y=10,
)
self.append(self.tilegrid)
@property
def color(self):
return self._color
@color.setter
def color(self, new_color):
# Updates the self Group with a TileGrid containing including a new smaller 20x20 bitmap with the given color
self._color=new_color
self.bitmap=displayio.Bitmap(20,20, 1) # Create the new bitmap smaller.
self.palette=displayio.Palette(1)
self.palette[0]=self._color
self.tilegrid = displayio.TileGrid(
self.bitmap,
pixel_shader=self.palette,
width=1,
height=1,
tile_width=self.bitmap.width,
tile_height=self.bitmap.height,
default_tile=0,
x=0,
y=0,
)
super().__init__(
max_size=1,
x=10,
y=10,
)
self.append(self.tilegrid)
# start the display
display = board.DISPLAY
# Create the original testGroup as RED
myGroup=testGroup(color=0xFF0000)
display.show(myGroup) # put the group on the display
print('This shows a 200x200 RED bitmap')
time.sleep(0.1)
time.sleep(2)
# Change the color to GREEN
myGroup.color=0x00FF00
print('The screen does not change')
time.sleep(0.1)
time.sleep(2)
# Change the color to BLUE
myGroup.color=0x0000FF
print('The screen does not change')
time.sleep(0.1)
time.sleep(2)
display.show(myGroup) # The screen changes to a 20x20 pixel BLUE bitmap
print('The screen changes to show a 20x20 blue square')
while True:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment