def __init__(self, output): self.output = output self.palette = displayio.Palette(color_count=2) self.palette[0] = 0x000000 self.palette[1] = 0xFFFFFF self.rect = vectorio.VectorShape( shape=vectorio.Rectangle(100, 100), pixel_shader=self.palette, ) self.gp = displayio.Group(max_size=1) self.gp.append(self.rect)
def rectangle_helper( x0: int, y0: int, height: int, width: int, bitmap, color_index: int, palette, bitmaptool: bool = True, ) -> None: """rectangle_helper function Draws a rectangle to the bitmap given using ``bitmapstools.bitmap`` or ``vectorio.rectangle`` functions :param int x0: rectangle lower corner x position :param int y0: rectangle lower corner y position :param int width: rectangle upper corner x position :param int height: rectangle upper corner y position :param int color_index: palette color index to be used :param palette: palette object to be used to draw the rectangle :param bitmap: bitmap for the rectangle to be drawn :param bool bitmaptool: uses :py:func:`~bitmaptools.draw_line` to draw the rectanlge. when `False` uses :py:func:`~vectorio.Rectangle` :return: None :rtype: None ┌───────────────────────┐ │ │ │ │ (x0,y0) └───────────────────────┘ """ if bitmaptool: bitmaptools.fill_region(bitmap, x0, y0, x0 + width, y0 + height, color_index) else: rect = vectorio.Rectangle(width, height) vectorio.VectorShape( shape=rect, pixel_shader=palette, x=x0, y=y0, )
display = board.DISPLAY # Store the initial memory usage gc.collect() # pylint: disable=no-member start_mem = gc.mem_free() # pylint: enable=no-member print("1 gc.mem_free: {}".format(start_mem)) ################################### # 1. Create the graphical elements # # create three vectorio.Rectangles and put them into groups ################################### rect1 = vectorio.Rectangle(10, 20) rect2 = vectorio.Rectangle(30, 20) rect3 = vectorio.Rectangle(20, 40) rect4 = vectorio.Rectangle(20, 20) palette1 = displayio.Palette(2) palette2 = displayio.Palette(2) palette3 = displayio.Palette(2) palette4 = displayio.Palette(2) palette1.make_transparent(0) palette1[1] = 0xFF0000 # red palette1[0] = 0x000000 palette2.make_transparent(0) palette2[1] = 0x00FF00 # green
display = board.DISPLAY main_group = displayio.Group() palette = displayio.Palette(4) palette[0] = 0x125690 palette[1] = 0x34BB90 palette[2] = 0xAA1220 palette[3] = 0xAA04BA circle = vectorio.Circle(pixel_shader=palette, radius=25, x=25, y=25) main_group.append(circle) rectangle = vectorio.Rectangle(pixel_shader=palette, width=50, height=50, x=25, y=75) main_group.append(rectangle) points = [(5, 5), (70, 20), (35, 35), (20, 70)] polygon = vectorio.Polygon(pixel_shader=palette, points=points, x=145, y=55) main_group.append(polygon) display.show(main_group) while True: for x in range(25, display.width - 25): circle.x = x time.sleep(0.01)
circle_palette.make_transparent(0) RADIUS = 30 circle = vectorio.VectorShape(shape=vectorio.Circle(RADIUS), pixel_shader=circle_palette, x=120, y=120) rect_palette = displayio.Palette(color_count=2) rect_palette[0] = 0xffffff rect_palette[1] = 0x00ff00 rect_palette.make_transparent(0) HEIGHT = 120 WIDTH = 60 rectangle = vectorio.VectorShape(shape=vectorio.Rectangle(WIDTH, HEIGHT), pixel_shader=rect_palette, x=120, y=120) poly_palette = displayio.Palette(color_count=2) poly_palette[0] = 0xffffff poly_palette[1] = 0x0000ff poly_palette.make_transparent(0) points = [(30, 30), (120, 120), (120, 30), (30, 120)] polygon = vectorio.VectorShape(shape=vectorio.Polygon(points), pixel_shader=poly_palette, x=0, y=0)
display_rotation = Label( font=font_0, text="rotation: " + str(display.rotation), color=WHITE, ) display_rotation.anchor_point = (0.5, 0.5) display_rotation.anchored_position = (display.width // 2, display.height // 4 - 30) # Define graphic objects for the screen fill, boundary, and touch pen. target_palette = displayio.Palette(1) target_palette[0] = BLUE_DK screen_fill = vectorio.Rectangle( pixel_shader=target_palette, x=2, y=2, width=display.width - 4, height=display.height - 4, ) target_palette = displayio.Palette(1) target_palette[0] = RED boundary = vectorio.Rectangle( pixel_shader=target_palette, x=0, y=0, width=display.width, height=display.height, ) pen = vectorio.Rectangle(