palette[3] = RED palette[4] = YELLOW palette.make_transparent(0) BACKGROUND_COLOR = 0 PROFILE_COLOR = 1 GRID_COLOR = 2 TEMP_COLOR = 3 AXIS_COLOR = 2 GXSTART = 100 GYSTART = 80 GWIDTH = WIDTH - GXSTART GHEIGHT = HEIGHT - GYSTART plot = displayio.Bitmap(GWIDTH, GHEIGHT, 4) display_group.append( displayio.TileGrid(plot, pixel_shader=palette, x=GXSTART, y=GYSTART)) ts = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(WIDTH, HEIGHT), ) class Beep(object):
import board import displayio import terminalio import time import random from adafruit_display_text import label display = board.DISPLAY font = terminalio.FONT group = displayio.Group() while True: bitmap = displayio.Bitmap(display.width, display.height, 2) palette = displayio.Palette(2) palette[0] = 0x000000 palette[1] = 0x00FF00 bitmap_grid = displayio.TileGrid(bitmap, pixel_shader=palette) bitmap_grid.x = 0 bitmap_grid.y = 0 size = random.randint(20,100) posx = random.randint(0,display.width-size) posy = random.randint(0,display.height-size) for x in range(posx, posx+size): for y in range(posy, posy+size): bitmap[x, y] = 1 text = "HELLO WORLD " + str(random.randint(0,250)) text_grid = label.Label(font, text=text, color=0xFFFFFF) text_grid.x = random.randint(10,160)
# load the sprite sheet sprite_sheet, palette = adafruit_imageload.load("/spritesheet.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette, width=1, height=1, tile_width=32, tile_height=32, x=4) # fill the background color_bitmap = displayio.Bitmap(160, 128, 1) color_palette = displayio.Palette(1) color_palette[0] = WHITE bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) group = displayio.Group(scale=4) group.append(bg_sprite) group.append(sprite) display.show(group) source_index = 0
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset, baudrate=1000000) time.sleep(1) display = adafruit_ssd1322.SSD1322(display_bus, width=256, height=64, colstart=28) g = displayio.Group() dimension = min(display.width, display.height) color_count = 16 gamma_pattern = displayio.Bitmap(dimension, dimension, color_count) gamma_palette = displayio.Palette(color_count) t = displayio.TileGrid(gamma_pattern, pixel_shader=gamma_palette) pixels_per_step = dimension // color_count for i in range(dimension): if i % pixels_per_step == 0: continue gamma_pattern[i, i] = i // pixels_per_step for i in range(color_count): component = i * 255 // (color_count - 1) print(component) gamma_palette[i] = component << 16 | component << 8 | component print(hex(gamma_palette[i]))
def __init__(self, colours, bg_colour=None, max_value=None, min_value=None, display=None, top_space=None, width=None, height=None, extra_data=16, auto_show=True, auto_discard=True): """__init__ :param list colours: a list of colours to use for data lines :param int bg_colour: a background colour to use (default black) :param int max_value: the max value to show on the plotter (the top) :param int min_value: the min value to show on the plotter (the bottom) :param display: a supplied display object (creates one if not supplied) :param int top_space: the number of pixels in height to reserve for titles and labels (and not draw lines in) :param int width: the width in pixels of the plot (uses display width if not supplied) :param int height: the height in pixels of the plot (uses display width if not supplied) :param int extra_data: the number of updates that can be applied before a draw (16 if not supplied) :param bool auto_show: invoke show on the displayio object here and per execution of draw() (default True) :param bool auto_discard: discard values which would over fill data_points (True) """ import displayio if not display: from pimoroni_envirowing import screen self.display = screen.Screen() else: self.display = display self.num_colours = len(colours) + 1 plot_width = self.display.width if width is None else width plot_height = self.display.height if height is None else height if top_space: self.bitmap = displayio.Bitmap(plot_width, plot_height - top_space, self.num_colours) self.top_offset = top_space else: self.bitmap = displayio.Bitmap(plot_width, plot_height, self.num_colours) self.top_offset = 0 self.palette = displayio.Palette(self.num_colours) if bg_colour: self.palette[0] = bg_colour else: self.palette[0] = 0x000000 # black for i, j in enumerate(colours): self.palette[i + 1] = j self.tile_grid = displayio.TileGrid(self.bitmap, pixel_shader=self.palette, y=self.top_offset) self.group = displayio.Group() self.group.append(self.tile_grid) self.auto_show = auto_show if self.auto_show: self.display.show(self.group) if max_value: self.max_value = max_value else: self.max_value = 2**16 - 1 # max 16 bit value (unsigned) if min_value: self.min_value = min_value else: self.min_value = 0 # min 16 bit value (unsigned) self.value_range = self.max_value - self.min_value # the extra list element is a gap used for this implementation # of a circular buffer self.data_len = plot_width + extra_data + 1 self.data_points = [None] * self.data_len self.data_head = 0 self.data_tail = 0 self.display_tail = 0 self.displayed_points = 0 self.auto_discard = auto_discard
red = int( round((color[idx2][0] - color[idx1][0]) * fractBetween + color[idx1][0])) green = int( round((color[idx2][1] - color[idx1][1]) * fractBetween + color[idx1][1])) blue = int( round((color[idx2][2] - color[idx1][2]) * fractBetween + color[idx1][2])) palette[c] = (0x010000 * red) + (0x000100 * green) + (0x000001 * blue) MakeHeatMapColor() # Bitmap for colour coded thermal value image_bitmap = displayio.Bitmap(24, 32, number_of_colors) # Create a TileGrid using the Bitmap and Palette image_tile = displayio.TileGrid(image_bitmap, pixel_shader=palette) # Create a Group that scale 24*32 to 168*224 image_group = displayio.Group(scale=7) image_group.append(image_tile) scale_bitmap = displayio.Bitmap(1, number_of_colors, number_of_colors) scale_group = displayio.Group(scale=3) scale_tile = displayio.TileGrid(scale_bitmap, pixel_shader=palette, x=69, y=8) scale_group.append(scale_tile) for i in range(number_of_colors): scale_bitmap[0, i] = i # Fill the scale with the palette gradian
def _create_test_content(self): text_string = "Here is a single Palette+Bitmap\nplaced on a 2x3 TileGrid" text1 = Label( self._font, x = 5, y = 5, text = text_string, max_glyphs = len(text_string), scale = 1, line_spacing = 1, color = self.LABEL_COLOR ) text_string = "The bitmap:" text2 = Label( self._font, x = 5, y = 40, text = text_string, max_glyphs = len(text_string), scale = 1, line_spacing = 1, color = self.LABEL_COLOR ) text_string = "The tiled bitmap:" text3 = Label( self._font, x = 5, y = 80, text = text_string, max_glyphs = len(text_string), scale = 1, line_spacing = 1, color = self.LABEL_COLOR ) # to draw something other than text, first make # a palette object to store the colors palette = displayio.Palette(color_count = 4) palette[0] = 0xFF0000 palette[1] = 0x00FF00 palette[2] = 0x0000FF palette[3] = 0x000000 # then, create a bitmap object bitmap = displayio.Bitmap(30, 30, 4) # we can fill up the bitmap. # the values are just integers, which correspond # to the indices in the palette we just set up for x in range(25): for y in range(25): bitmap[x,y] = x//10 for y in range(25,30): bitmap[x,y] = 3 for x in range(25,30): for y in range(30): bitmap[x,y] = 3 # now, we need to place it in a TileGrid object... tilegrid1 = displayio.TileGrid( bitmap, pixel_shader = palette, width = 2, height = 3, x = 20, y = 100 ) tilegrid2 = displayio.TileGrid( bitmap, pixel_shader = palette, x = 80, y = 40 ) # and, finally... we place this on a group content = displayio.Group(max_size = 5) content.append(text1) content.append(text2) content.append(text3) content.append(tilegrid1) content.append(tilegrid2) return content
move_u = True elif panel.joystick[1] > 44000: move_d = True else: # For PyBadge read the buttons if panel.button.up: move_u = True if panel.button.down: move_d = True return move_u, move_d ### Define the display group ### image_group = displayio.Group() # Create a background color fill layer; image_group[0] color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1) color_palette = displayio.Palette(1) color_palette[0] = BLACK background = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) image_group.append(background) # Define the foundational thermal image element layers; image_group[1:64] # image_group[#]=(row * 8) + column for row in range(0, 8): for col in range(0, 8): pos_x, pos_y = element_grid(col, row) element = Rect(x=pos_x, y=pos_y,
import displayio import terminalio from adafruit_display_text import label import adafruit_displayio_ssd1306 displayio.release_displays() i2c = board.I2C() display_bus = displayio.I2CDisplay(i2c, device_address=0x3c) display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(128, 32, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFFFFFF # White bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle inner_bitmap = displayio.Bitmap(118, 24, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette,
# SPDX-License-Identifier: MIT import time import board import displayio from adafruit_cursorcontrol.cursorcontrol import Cursor from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager # Create the display display = board.DISPLAY # Create the display context splash = displayio.Group(max_size=5) # initialize the mouse cursor object bmp = displayio.Bitmap(20, 20, 3) for i in range(0, bmp.height): bmp[0, i] = 1 bmp[bmp.width - 1, i] = 1 for i in range(0, bmp.width): bmp[i, 0] = 1 bmp[i, bmp.height - 1] = 1 mouse_cursor = Cursor(display, display_group=splash, bmp=bmp) # initialize the cursormanager cursor = CursorManager(mouse_cursor) # show displayio group display.show(splash)
# Release any resources currently in use for the displays displayio.release_displays() spi = board.SPI() tft_cs = board.CE0 tft_dc = board.D25 display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) display = HX8357(display_bus, width=480, height=320) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(display.width, display.height, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x00FF00 # Bright Green bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle inner_bitmap = displayio.Bitmap(display.width - 40, display.height - 40, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0xAA0088 # Purple inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette,
] n_yay = 0 n_nay = 0 ping_mode = 0 ping_x, ping_y = 0, 0 button_a = button.Button(board.D9, digitalio.Pull.UP) button_b = button.Button(board.D6, digitalio.Pull.UP) button_c = button.Button(board.D5, digitalio.Pull.UP) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) # Fill with white color_bitmap = displayio.Bitmap(128, 32, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFFFFFF # White bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle inner_bitmap = displayio.Bitmap(118, 24, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5,
b"\xF2\x01\x00" # 3Gamma Function Disable b"\x26\x01\x01" # Gamma curve selected b"\xe0\x0f\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00" # Set Gamma b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma b"\x11\x80\x78" # Exit Sleep then delay 0x78 (120ms) b"\x29\x80\x78" # Display on then delay 0x78 (120ms) ) # Setup the Display display = displayio.Display(display_bus, INIT_SEQUENCE, width=320, height=240) # # DONE - now you can use the display however you want # bitmap = displayio.Bitmap(320, 240, 2) palette = displayio.Palette(2) palette[0] = 0 palette[1] = 0xFFFFFF for x in range(10, 20): for y in range(10, 20): bitmap[x, y] = 1 tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette) group = displayio.Group() group.append(tile_grid) display.show(group)
command=tft_dc, chip_select=tft_cs, reset=board.D9) display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(160, 80, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x00FF00 # Bright Green bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle inner_bitmap = displayio.Bitmap(150, 70, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0xAA0088 # Purple inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette,
def _reset_text( self, font: Optional[Union[BuiltinFont, BDF, PCF]] = None, text: Optional[str] = None, line_spacing: Optional[float] = None, scale: Optional[int] = None, ) -> None: # pylint: disable=too-many-branches, too-many-statements # Store all the instance variables if font is not None: self._font = font if line_spacing is not None: self._line_spacing = line_spacing # if text is not provided as a parameter (text is None), use the previous value. if (text is None) and self._save_text: text = self._text if self._save_text: # text string will be saved self._text = self._replace_tabs(text) if self._label_direction == "RTL": self._text = "".join(reversed(self._text)) else: self._text = None # save a None value since text string is not saved # Check for empty string if (text == "") or ( text is None ): # If empty string, just create a zero-sized bounding box and that's it. self._bounding_box = ( 0, 0, 0, # zero width with text == "" 0, # zero height with text == "" ) # Clear out any items in the self._local_group Group, in case this is an # update to the bitmap_label for _ in self._local_group: self._local_group.pop(0) else: # The text string is not empty, so create the Bitmap and TileGrid and # append to the self Group # Calculate the text bounding box # Calculate both "tight" and "loose" bounding box dimensions to match label for # anchor_position calculations ( box_x, tight_box_y, x_offset, tight_y_offset, loose_box_y, loose_y_offset, ) = self._text_bounding_box( text, self._font, ) # calculate the box size for a tight and loose backgrounds if self._background_tight: box_y = tight_box_y y_offset = tight_y_offset else: # calculate the box size for a loose background box_y = loose_box_y y_offset = loose_y_offset # Calculate the background size including padding box_x = box_x + self._padding_left + self._padding_right box_y = box_y + self._padding_top + self._padding_bottom # Create the bitmap and TileGrid self._bitmap = displayio.Bitmap(box_x, box_y, len(self._palette)) # Place the text into the Bitmap self._place_text( self._bitmap, text, self._font, self._padding_left - x_offset, self._padding_top + y_offset, ) if self._base_alignment: label_position_yoffset = 0 else: label_position_yoffset = self._ascent // 2 self._tilegrid = displayio.TileGrid( self._bitmap, pixel_shader=self._palette, width=1, height=1, tile_width=box_x, tile_height=box_y, default_tile=0, x=-self._padding_left + x_offset, y=label_position_yoffset - y_offset - self._padding_top, ) if self._label_direction == "UPR": self._tilegrid.transpose_xy = True self._tilegrid.flip_x = True if self._label_direction == "DWR": self._tilegrid.transpose_xy = True self._tilegrid.flip_y = True if self._label_direction == "UPD": self._tilegrid.flip_x = True self._tilegrid.flip_y = True # Clear out any items in the local_group Group, in case this is an update to # the bitmap_label for _ in self._local_group: self._local_group.pop(0) self._local_group.append( self._tilegrid) # add the bitmap's tilegrid to the group # Update bounding_box values. Note: To be consistent with label.py, # this is the bounding box for the text only, not including the background. if self._label_direction in ("UPR", "DWR"): self._bounding_box = ( self._tilegrid.x, self._tilegrid.y, tight_box_y, box_x, ) else: self._bounding_box = ( self._tilegrid.x, self._tilegrid.y, box_x, tight_box_y, ) if ( scale is not None ): # Scale will be defined in local_group (Note: self should have scale=1) self.scale = scale # call the setter # set the anchored_position with setter after bitmap is created, sets the # x,y positions of the label self.anchored_position = self._anchored_position
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C) # SH1107 is vertically oriented 64x128 WIDTH = 128 HEIGHT = 64 BORDER = 2 display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFFFFFF # White bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle in black inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette,
messages = [ "HELLO FROM ADAFRUIT INDUSTRIES", "12345678910 -$!+='()/:;?", "WOULD YOU LIKE TO PLAY A GAME?", "WELCOME TO JOHN PARK'S WORKSHOP", ] clue.display.brightness = 1.0 screen = displayio.Group() VFD_GREEN = 0x00FFD2 VFD_BG = 0x000505 # setup screen # BG color_bitmap = displayio.Bitmap(240, 240, 1) color_palette = displayio.Palette(1) color_palette[0] = VFD_BG bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, pixel_shader=color_palette) screen.append(bg_sprite) # title title_label = label.Label(terminalio.FONT, text="TTY CLUE", scale=4, color=VFD_GREEN) title_label.x = 20 title_label.y = 16
pyportal.set_backlight(0.5) # Create a new DisplayIO group splash = displayio.Group(max_size=15) # show splash group display.show(splash) # Palette for water bitmap palette = displayio.Palette(2) palette[0] = 0x000000 palette[1] = WATER_COLOR palette.make_transparent(0) # Create water bitmap water_bmp = displayio.Bitmap(display.width, display.height, len(palette)) water = displayio.TileGrid(water_bmp, pixel_shader=palette) splash.append(water) print("drawing background..") # Load background image try: bg_bitmap, bg_palette = adafruit_imageload.load(BACKGROUND, bitmap=displayio.Bitmap, palette=displayio.Palette) # Or just use solid color except (OSError, TypeError): BACKGROUND = BACKGROUND if isinstance(BACKGROUND, int) else 0x000000 bg_bitmap = displayio.Bitmap(display.width, display.height, 1) bg_palette = displayio.Palette(1) bg_palette[0] = BACKGROUND
def __init__(self, output, screen_width=240, screen_height=240 ): self._output = output self._font = terminalio.FONT self._screen_width = screen_width self._screen_height = screen_height LABEL_COLOR = 0xc0c0c0 self.cur_source = None # create title cur_val = 0 self.title = Label( self._font, x = 5, y = 10, text = f'No source!\nCurrent: {round(cur_val,2)}\nFree Mem: {gc.mem_free()}', max_glyphs = 80, scale = 2, line_spacing = 1, color = self.LABEL_COLOR ) # create graph self.palette = displayio.Palette(color_count = 4) self.palette[0] = 0x000000 self.palette[1] = 0xFF0000 self.palette[2] = 0x00FF00 self.palette[3] = 0X0000FF graph_width = 200 self.graph_bitmap = displayio.Bitmap(graph_width, 120, 4) self.graph_tg = displayio.TileGrid( self.graph_bitmap, pixel_shader = self.palette, x = 240-graph_width, y = 120 ) # create y axis ticks self.num_ticks = 5 # these quantities will be the min and max of graph window self.y_min = 0 self.y_max = self.num_ticks - 1 self.y_axis_labels = displayio.Group(max_size = self.num_ticks) for tick_num in range(self.num_ticks): y_screen = int(120-(self.num_ticks - tick_num)*24) # for x in range(5): # y_axis_bitmap[x,y_screen] = 0 self.y_axis_labels.append(Label( self._font, x = 0, y = 120+y_screen, text = f'{round(tick_num,2)}', max_glyphs = 10, scale = 1, color = 0xFFFFFF )) # merge together into the display group self.content = displayio.Group(max_size = 4) self.content.append(self.title) self.content.append(self.graph_tg) self.content.append(self.y_axis_labels)
# Accelerometer setup accelo_i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) accelo = adafruit_lis3dh.LIS3DH_I2C(accelo_i2c, address=0x19) # Create the TFT Gizmo display display = tft_gizmo.TFT_Gizmo() # Load background image try: bg_bitmap, bg_palette = adafruit_imageload.load(BACKGROUND, bitmap=displayio.Bitmap, palette=displayio.Palette) # Or just use solid color except (OSError, TypeError, AttributeError): BACKGROUND = BACKGROUND if isinstance(BACKGROUND, int) else 0x000000 bg_bitmap = displayio.Bitmap(display.width, display.height, 1) bg_palette = displayio.Palette(1) bg_palette[0] = BACKGROUND background = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette) # Shared palette for snow bitmaps palette = displayio.Palette(2) palette[0] = 0xADAF00 # transparent color palette[1] = SNOW_COLOR # snow color palette.make_transparent(0) # Snowflake setup FLAKES = ( 0, 0, 0,
tft_cs = board.GP17 tft_dc = board.GP16 spi_mosi = board.GP19 spi_clk = board.GP18 spi = busio.SPI(spi_clk, spi_mosi) display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) display = ST7789(display_bus, width=240, height=240, rowstart=80, rotation=180) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(240, 240, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x00FF00 # Bright Green bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle inner_bitmap = displayio.Bitmap(200, 200, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0xAA0088 # Purple inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette,
#give it a moment to read (just a guess) time.sleep(0.05) light_value = light_sensor.value power.value = True # turn the sensor offset print("Light is:", light_value) # No need to update the screen if it is dark and you can't read it if light_value > 600: display = board.DISPLAY display_group = displayio.Group(max_size=25) # Set background to white color_bitmap = displayio.Bitmap(display.width, display.height, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFFFFFF bg_sprite = displayio.TileGrid( color_bitmap, pixel_shader=color_palette, x=0, y=0, ) display_group.append(bg_sprite) display.show(display_group) bg_file = open("bg.bmp", "rb") background = displayio.OnDiskBitmap(bg_file) bg_sprite = displayio.TileGrid( background,
0xEE00EE, 0xCCCCCC, 0xFF9999, 0x99FF99, 0x9999FF] ble = BLERadio() i = 0 advertisement = AdafruitColor() advertisement.color = color_options[i] display = board.DISPLAY # Create a bitmap with two colors + 64 colors for the map bitmap = displayio.Bitmap(8, 8, 64 + 2) # Create a 8*8 bitmap pre-filled with 64 colors (color 0 and 1 are reserved) for i in range(0, 8): for j in range(0, 8): bitmap[i, j] = 2+i+j*8 # Create an empty palette that will be used in one to one mapping palette_mapping = displayio.Palette(64 + 2) palette_mapping[0] = 0x000000 palette_mapping[1] = 0xFFFFFF color_select_palette = displayio.Palette(len(color_options)) for i, color in enumerate(color_options): color_select_palette[i] = color
def show_QR(self, qr_data, qr_size=128, position=None): import adafruit_miniqr if not qr_data: # delete it if self._qr_group: try: self._qr_group.pop() except IndexError: pass board.DISPLAY.refresh_soon() board.DISPLAY.wait_for_frame() return if not position: position = (0, 0) if qr_size % 32 != 0: raise RuntimeError("QR size must be divisible by 32") qr = adafruit_miniqr.QRCode() qr.add_data(qr_data) qr.make() # how big each pixel is, add 2 blocks on either side BLOCK_SIZE = qr_size // (qr.matrix.width + 4) # Center the QR code in the middle X_OFFSET = (qr_size - BLOCK_SIZE * qr.matrix.width) // 2 Y_OFFSET = (qr_size - BLOCK_SIZE * qr.matrix.height) // 2 # monochome (2 color) palette palette = displayio.Palette(2) palette[0] = 0xFFFFFF palette[1] = 0x000000 # bitmap the size of the matrix + borders, monochrome (2 colors) qr_bitmap = displayio.Bitmap(qr_size, qr_size, 2) # raster the QR code line = bytearray(qr_size // 8) # monochrome means 8 pixels per byte for y in range(qr.matrix.height): # each scanline in the height for i, _ in enumerate(line): # initialize it to be empty line[i] = 0 for x in range(qr.matrix.width): if qr.matrix[x, y]: for b in range(BLOCK_SIZE): _x = X_OFFSET + x * BLOCK_SIZE + b line[_x // 8] |= 1 << (7 - (_x % 8)) for b in range(BLOCK_SIZE): # load this line of data in, as many time as block size qr_bitmap._load_row(Y_OFFSET + y * BLOCK_SIZE + b, line) #pylint: disable=protected-access # display the bitmap using our palette qr_sprite = displayio.Sprite(qr_bitmap, pixel_shader=palette, position=position) if self._qr_group: try: self._qr_group.pop() except IndexError: # later test if empty pass else: self._qr_group = displayio.Group() self.splash.append(self._qr_group) self._qr_group.append(qr_sprite) board.DISPLAY.refresh_soon() board.DISPLAY.wait_for_frame()
# our MagTag magtag = MagTag() magtag.json_path = ["predictions"] # ---------------------------- # Grid overlay for plot # ---------------------------- grid_bmp, grid_pal = adafruit_imageload.load("/bmps/tides_bg_land.bmp") grid_pal.make_transparent(1) grid_overlay = displayio.TileGrid(grid_bmp, pixel_shader=grid_pal) # ---------------------------- # Tide plot (bitmap, palette, tilegrid) # ---------------------------- tide_plot = displayio.Bitmap(PLOT_WIDTH, PLOT_HEIGHT, 4) tide_pal = displayio.Palette(4) tide_pal[0] = 0x000000 # black tide_pal[1] = 0x555555 # dark gray tide_pal[2] = 0xAAAAAA # light gray tide_pal[3] = 0xFFFFFF # white tide_pal.make_transparent(3) tide_tg = displayio.TileGrid(tide_plot, pixel_shader=tide_pal, x=PLOT_X, y=PLOT_Y) # ---------------------------- # Plot scale labels
import time import board import displayio import terminalio import fontio from adafruit_bitmap_font import bitmap_font from adafruit_display_text import label, bitmap_label display = board.DISPLAY main_group = displayio.Group() MEDIUM_FONT = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf") BIG_FONT = bitmap_font.load_font("fonts/LibreBodoniv2002-Bold-27.bdf") TIME_PAUSE = 2 bitmap = displayio.Bitmap(4, display.width, 2) palette = displayio.Palette(2) palette[0] = 0x004400 palette[1] = 0x00FFFF horizontal_line = displayio.TileGrid(bitmap, pixel_shader=palette, x=155, y=0) main_group.append(horizontal_line) bitmap = displayio.Bitmap(display.width, 4, 2) vertical_line = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=110) main_group.append(vertical_line) # Tests text_area = label.Label(terminalio.FONT, text="Circuit Python") main_group.append(text_area) display.show(main_group) time.sleep(TIME_PAUSE)
def playHand(minitft, companbot_x): #---------------------------------- bj_screen = displayio.Group(max_size=8) cardslot1 = displayio.Group(max_size=2) cardslot2 = displayio.Group(max_size=1) cardslot3 = displayio.Group(max_size=1) cardslot4 = displayio.Group(max_size=1) cardslot5 = displayio.Group(max_size=1) text_group_bj = displayio.Group(max_size=3) card2BMP = "/bmp/cards.bmp" color_bitmap = displayio.Bitmap(160, 80, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x20c040 bjbgDisp = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) text_area1_bj = label.Label(terminalio.FONT, text="Dealing", color=0xFFFFFF, max_glyphs=20, x=5, y=55) text_area2_bj = label.Label(terminalio.FONT, text="Cards", color=0xFFFFFF, max_glyphs=20, x=80, y=55) text_area3_bj = label.Label(terminalio.FONT, text=" ", color=0xFFFFFF, max_glyphs=20, x=50, y=70) card2_SP, card2_Pal = adafruit_imageload.load(card2BMP, bitmap=displayio.Bitmap, palette=displayio.Palette) cardSlot1_Disp = displayio.TileGrid(card2_SP, pixel_shader=card2_Pal, width=1, height=1, tile_width=25, tile_height=30, x=5, y=2) cardSlot2_Disp = displayio.TileGrid(card2_SP, pixel_shader=card2_Pal, width=1, height=1, tile_width=25, tile_height=30, x=35, y=2) cardSlot3_Disp = displayio.TileGrid(card2_SP, pixel_shader=card2_Pal, width=1, height=1, tile_width=25, tile_height=30, x=65, y=2) cardSlot4_Disp = displayio.TileGrid(card2_SP, pixel_shader=card2_Pal, width=1, height=1, tile_width=25, tile_height=30, x=95, y=2) cardSlot5_Disp = displayio.TileGrid(card2_SP, pixel_shader=card2_Pal, width=1, height=1, tile_width=25, tile_height=30, x=125, y=2) cardslot1.append(cardSlot1_Disp) cardslot2.append(cardSlot2_Disp) cardslot3.append(cardSlot3_Disp) cardslot4.append(cardSlot4_Disp) cardslot5.append(cardSlot5_Disp) text_group_bj.append(text_area1_bj) text_group_bj.append(text_area2_bj) text_group_bj.append(text_area3_bj) #text_area2_bj.x = 80 #text_area2_bj.y = 55 #text_area3_bj.x = 50 #text_area3_bj.y = 70 bj_screen.append(bjbgDisp) bj_screen.append(cardslot1) bj_screen.append(cardslot2) bj_screen.append(cardslot3) bj_screen.append(cardslot4) bj_screen.append(cardslot5) bj_screen.append(text_group_bj) #---------------------------------- minitft.display.show(bj_screen) cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] player = [] # draw 2 cards for the player to start player.append(rc(cards)) player.append(rc(cards)) pbust = False # player busted flag cbust = False # computer busted flag playerTurn = True #text_area1_bj.text = " " #text_area2_bj.text = " " cardslot1.hidden = True cardslot2.hidden = True cardslot3.hidden = True cardslot4.hidden = True cardslot5.hidden = True cardSlot1_Disp[0] = cardmap(int(player[0])) cardslot1.hidden = False time.sleep(1) cardSlot2_Disp[0] = cardmap(int(player[1])) cardslot2.hidden = False time.sleep(1) #Input eater #time.sleep(0.4) while playerTurn: playerInput = False tp = total(player) text_area1_bj.text = " " text_area2_bj.text = " " text_area3_bj.text = "Total: {}".format(tp) time.sleep(2) if tp > 21: text_area1_bj.text = "Player bust!" time.sleep(2) pbust = True playerTurn = False elif tp == 21: text_area1_bj.text = "BLACKJACK!!!" time.sleep(2) playerTurn = False else: text_area1_bj.text = "Hit (A)" text_area2_bj.text = "Stand (B)" while not playerInput: buttons = minitft.buttons if buttons.a: print("Awaiting User") playerInput = True text_area1_bj.text = "Hit" text_area2_bj.text = "" player.append(rc(cards)) if len(player) == 3: cardslot3.hidden = False cardSlot3_Disp[0] = cardmap(int(player[2])) time.sleep(1) elif len(player) == 4: cardslot4.hidden = False cardSlot4_Disp[0] = cardmap(int(player[3])) time.sleep(1) elif len(player) == 5: cardslot5.hidden = False cardSlot5_Disp[0] = cardmap(int(player[4])) time.sleep(1) playerTurn = False if buttons.b: text_area1_bj.text = "Stand" text_area2_bj.text = "" time.sleep(1) playerInput = True playerTurn = False while True: # loop for the computer's play ... cardslot1.hidden = True cardslot2.hidden = True cardslot3.hidden = True cardslot4.hidden = True cardslot5.hidden = True text_area1_bj.text = "Dealer's Turn" text_area2_bj.text = " " text_area3_bj.text = " " comp = [] time.sleep(1) comp.append(rc(cards)) cardslot1.hidden = False cardSlot1_Disp[0] = cardmap(int(comp[0])) time.sleep(1) comp.append(rc(cards)) cardslot2.hidden = False cardSlot2_Disp[0] = cardmap(int(comp[1])) time.sleep(1) while not pbust or cbust: tc = total(comp) text_area3_bj.text = "Total: {}".format(tc) if tc < 17: comp.append(rc(cards)) if cardslot3.hidden: cardslot3.hidden = False cardSlot3_Disp[0] = cardmap(int(comp[2])) time.sleep(2) elif cardslot4.hidden and not cardslot3.hidden: cardslot4.hidden = False cardSlot4_Disp[0] = cardmap(int(comp[3])) time.sleep(2) elif cardslot5.hidden and not cardslot4.hidden: cardslot5.hidden = False cardSlot5_Disp[0] = cardmap(int(comp[4])) time.sleep(2) else: break text_area3_bj.text = " " # now figure out who won ... if tc > 21: text_area1_bj.text = "Dealer bust!" cbust = True if pbust == False: text_area1_bj.text = "Player wins!" companbot_x.cred = companbot_x.cred + 20 elif tc > tp: text_area1_bj.text = "Dealer Wins!" elif tc == tp: text_area1_bj.text = "It's a draw!" elif tp > tc: if pbust == False: text_area1_bj.text = "Player wins!" companbot_x.cred = companbot_x.cred + 10 elif cbust == False: text_area1_bj.text = "Dealer Wins!" break time.sleep(2) return companbot_x
reset=board.B5) #display = ILI9341(display_bus, width=160, height=128) display = displayio.Display(display_bus, init_sequence, width=128, height=160) display.rotation = 90 print(const("Initializing UI...")) # Fonts font10 = terminalio.FONT font20 = bitmap_font.load_font("fonts/dseg-10.bdf") font_spd = bitmap_font.load_font("fonts/dseg-48.bdf") # UI print(const("Loading fonts...")) main_group = displayio.Group(max_size=50) #background bg_bitmap = displayio.Bitmap(160, 128, 2) bg_palette = displayio.Palette(1) bg_palette[0] = 0xffbf00 # Bright Green bg_sprite = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette, x=0, y=0) main_group.append(bg_sprite) # Main Screen Round rectangle roundrect = RoundRect(2, 2, 156, 124, 5, fill=0x454545, outline=0x454545, stroke=2) main_group.append(roundrect) # Status Bar Down
tft_cs = board.D5 tft_dc = board.D6 displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(128, 128, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x00FF00 # Bright Green bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a smaller inner rectangle inner_bitmap = displayio.Bitmap(108, 108, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0xAA0088 # Purple inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette,
line_spacing=0.9, color=0x000000, anchor_point=(0.5, 0.5), anchored_position=(0, 0)) text_group = displayio.Group(scale=1, x=120, y=155) text_group.append(text_area) main.append(text_group) # Subgroup for text scaling # 30x140 pointer bitmap_pointer, palette_pointer = adafruit_imageload.load( pointer_filename, bitmap=displayio.Bitmap, palette=displayio.Palette) palette_pointer.make_transparent(0) # Blank bitmap the same size as the pointer bitmap bitmap_pointer_blank = displayio.Bitmap(bitmap_pointer.width, bitmap_pointer.height, 1) # len(palette_pointer)) #bitmap_pointer_blank.fill(0) # Transparent overlay that is "scribbled" into by rotozoom # to create rotated version of pointer bitmap_scribble = displayio.Bitmap(display.width, display.height, len(palette_pointer)) tile_grid = displayio.TileGrid(bitmap_scribble, pixel_shader=palette_pointer) main.append(tile_grid) # Do initial draw display.refresh() print("Hello World!")