from board import DISPLAY
import displayio, time
class rect(displayio.TileGrid):
def __init__(self, x, y, width, height, color):
self.plt = displayio.Palette(2)
self.plt.make_transparent(0)
self.color = color
super().__init__(displayio.Shape(width, height), pixel_shader = self.plt, position = (x,y))
@property
def color(self):
return self.plt[1]
@color.setter
def color(self, valin):
self.plt[1] = valin
@property
def x(self):
return self.position[0]
@property
def y(self):
return self.position[1]
@x.setter
def x(self, valin):
self.position = (valin, self.position[1])
@x.setter
def y(self, valin):
self.position = (self.position[0], valin)
grp = displayio.Group(max_size = 1)
r = rect(5,5,50,30,0xffffff)
print(type(r))
grp.append(r)
print(type(r))
DISPLAY.show(grp)
r.x = 50
time.sleep(1)
print(type(grp[0]))
causes:
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:
<class 'rect'>
<class 'rect'>
Traceback (most recent call last):
File "main.py", line 47, in
NameError: name 'grp' is not defined
causes:
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:
<class 'rect'>
<class 'rect'>
Traceback (most recent call last):
File "main.py", line 47, in
NameError: name 'grp' is not defined