|
| 1 | +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +""" |
| 5 | +This test will initialize the display using displayio and draw a solid green |
| 6 | +background, a smaller purple rectangle, and some yellow text. |
| 7 | +""" |
| 8 | +import board |
| 9 | +import terminalio |
| 10 | +import displayio |
| 11 | +from adafruit_display_text import label |
| 12 | + |
| 13 | +# First set some parameters used for shapes and text |
| 14 | +BORDER = 20 |
| 15 | +FONTSCALE = 2 |
| 16 | +BACKGROUND_COLOR = 0x00FF00 # Bright Green |
| 17 | +FOREGROUND_COLOR = 0xAA0088 # Purple |
| 18 | +TEXT_COLOR = 0xFFFF00 |
| 19 | + |
| 20 | +display = board.DISPLAY |
| 21 | + |
| 22 | +# Make the display context |
| 23 | +splash = displayio.Group() |
| 24 | +display.root_group = splash |
| 25 | + |
| 26 | +color_bitmap = displayio.Bitmap(display.width, display.height, 1) |
| 27 | +color_palette = displayio.Palette(1) |
| 28 | +color_palette[0] = BACKGROUND_COLOR |
| 29 | + |
| 30 | +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) |
| 31 | +splash.append(bg_sprite) |
| 32 | + |
| 33 | +# Draw a smaller inner rectangle |
| 34 | +inner_bitmap = displayio.Bitmap( |
| 35 | + display.width - BORDER * 2, display.height - BORDER * 2, 1 |
| 36 | +) |
| 37 | +inner_palette = displayio.Palette(1) |
| 38 | +inner_palette[0] = FOREGROUND_COLOR |
| 39 | +inner_sprite = displayio.TileGrid( |
| 40 | + inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER |
| 41 | +) |
| 42 | +splash.append(inner_sprite) |
| 43 | + |
| 44 | +# Draw a label |
| 45 | +text = "Hello World!" |
| 46 | +text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR) |
| 47 | +text_width = text_area.bounding_box[2] * FONTSCALE |
| 48 | +text_group = displayio.Group( |
| 49 | + scale=FONTSCALE, |
| 50 | + x=display.width // 2 - text_width // 2, |
| 51 | + y=display.height // 2, |
| 52 | +) |
| 53 | +text_group.append(text_area) # Subgroup for text scaling |
| 54 | +splash.append(text_group) |
| 55 | + |
| 56 | +while True: |
| 57 | + pass |
0 commit comments