def test_order_bgra_to_rgba(self): test_file = os.path.join(os.path.dirname(__file__), "..", "examples", "images", "4bit.bmp") bitmap, palette = load(filename=test_file, bitmap=Bitmap_C_Interface, palette=Palette_C_Interface) self.assertTrue(isinstance(bitmap, Bitmap_C_Interface), bitmap) self.assertEqual(16, bitmap.colors) self.assertEqual(15, bitmap.width) self.assertEqual(17, bitmap.height) bitmap.validate() # uncomment line below to see a string representation of the object # self.fail(str(bitmap)) self.assertEqual(5, bitmap[0]) # check first row self.assertEqual(5, bitmap[11, 1]) # check second row self.assertEqual(16, palette.num_colors) palette.validate() # make sure bye order swapped self.assertTrue(palette[4] in [b"\x9d\x00\xff\x00", b"\x9d\x00\xff"])
def __init__(self, filename, transparent=None): """Create Sprite object from color-paletted BMP file, optionally set one color to transparent (pass as RGB tuple or list to locate nearest color, or integer to use a known specific color index). """ bitmap, palette = adafruit_imageload.load(filename, bitmap=displayio.Bitmap, palette=displayio.Palette) if isinstance(transparent, (tuple, list)): # Find closest RGB match closest_distance = 0x1000000 # Force first match for color_index, color in enumerate(palette): # Compare each... delta = (transparent[0] - ((color >> 16) & 0xFF), transparent[1] - ((color >> 8) & 0xFF), transparent[2] - (color & 0xFF)) rgb_distance = (delta[0] * delta[0] + delta[1] * delta[1] + delta[2] * delta[2]) # Actually dist^2 if rgb_distance < closest_distance: # but adequate for closest_distance = rgb_distance # compare purposes, closest_index = color_index # no sqrt needed palette.make_transparent(closest_index) elif isinstance(transparent, int): palette.make_transparent(transparent) super(Sprite, self).__init__(bitmap, pixel_shader=palette) self.height = bitmap.height
def __init__(self, ble, display, circ, heart=True, speed=True, cad=True, ams=True, debug=False): #pylint: disable=too-many-arguments self.debug = debug self.ble = ble self.display = display self.circumference = circ self.heart_enabled = heart self.speed_enabled = speed self.cadence_enabled = cad self.ams_enabled = ams self.hr_connection = None self.num_enabled = heart + speed + cad + ams self._previous_wheel = 0 self._previous_crank = 0 self._previous_revolutions = 0 self._previous_rev = 0 self._previous_speed = 0 self._previous_cadence = 0 self._previous_heart = 0 self._speed_failed = 0 self._cadence_failed = 0 self._setup = 0 self._hr_label = None self._sp_label = None self._cadence_label = None self._ams_label = None self._hr_service = None self._heart_y = None self._speed_y = None self._cadence_y = None self._ams_y = None self.ams = None self.cyc_connections = None self.cyc_services = None self.track_artist = True self.start = time.time() self.splash = displayio.Group() self.loading_group = displayio.Group() self._load_fonts() self.sprite_sheet, self.palette = adafruit_imageload.load( "/sprite_sheet.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) self.text_group = displayio.Group() self.status = label.Label(font=self.arial12, x=10, y=200, text='', color=self.YELLOW) self.status1 = label.Label(font=self.arial12, x=10, y=220, text='', color=self.YELLOW) self.text_group.append(self.status) self.text_group.append(self.status1)
import time import displayio from adafruit_circuitplayground import cp import adafruit_imageload from adafruit_gizmo import tft_gizmo from adafruit_display_shapes.circle import Circle # setup for the Gizmo TFT display = tft_gizmo.TFT_Gizmo() # loading the background image bg_bitmap, bg_palette = adafruit_imageload.load("/clouds_bg.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) bg_grid = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette) # loading the crescent moon bitmap sequence bitmap, palette = adafruit_imageload.load("/moon_anime.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # makes the black background transparent so we only see the cresent moon palette.make_transparent(0) tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette, width = 1, height = 1, tile_height = 120, tile_width = 120, default_tile = 0) # two circles for the center "jewel" jewel_outline = Circle(x0=120, y0=120, r=40, fill=0xfbf236) jewel = Circle(x0=120, y0=120, r=35, fill=0xf70570)
Basic imageload example script adapted for use on MagTag. """ import time import board import displayio import adafruit_imageload # use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.) # see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) # https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus display = board.DISPLAY # wait until the display is ready time.sleep(display.time_to_refresh) image, palette = adafruit_imageload.load("images/magtag_2x2_test.bmp") tile_grid = displayio.TileGrid(image, pixel_shader=palette) # scale 8 for full screen group = displayio.Group(scale=8) group.append(tile_grid) # show the group and refresh display.show(group) display.refresh() while True: pass
import board import displayio import adafruit_imageload display = board.DISPLAY bitmap, palette = adafruit_imageload.load("images/color_wheel.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette) group = displayio.Group() group.append(tile_grid) display.show(group) while True: pass
# the sensor scd30 = adafruit_scd30.SCD30(board.I2C()) # optional if known (pick one) # scd30.ambient_pressure = 1013.25 # scd30.altitude = 0 # the display matrix = Matrix(width=64, height=32, bit_depth=6) display = matrix.display display.rotation = 90 # matrixportal up # display.rotation = 270 # matrixportal down # current condition smiley face smileys_bmp, smileys_pal = adafruit_imageload.load("/bmps/smileys.bmp") smiley = displayio.TileGrid( smileys_bmp, pixel_shader=smileys_pal, x=0, y=0, width=1, height=1, tile_width=32, tile_height=32, ) # current condition label tags_bmp, tags_pal = adafruit_imageload.load("/bmps/tags.bmp") label = displayio.TileGrid( tags_bmp,
# restore saved sea level pressure from NVM slp = struct.unpack("f", nvm[0:4])[0] clue.sea_level_pressure = slp if 0 < slp < 2000 else STD_SLP # -------------------------------------------------------------------- # D I S P L A Y S E T U P # -------------------------------------------------------------------- # create main display group splash = displayio.Group(max_size=4) clue.display.show(splash) # background bg_bmp, bg_pal = adafruit_imageload.load( "/network23.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette ) for i, color in enumerate(bg_pal): if color == 0xFF0000: bg_pal.make_transparent(i) break background = displayio.TileGrid(bg_bmp, pixel_shader=bg_pal) # a group for both altitude readouts alti_readouts = displayio.Group(max_size=2, scale=6) # altitude (corrected) alti_disp = label.Label(FONT, text="12345", color=ORANGE) alti_disp.anchor_point = (0, 0) alti_disp.anchored_position = (7, 2)
graphics = Graphics(auto_refresh=False) display = graphics.display group = displayio.Group() selector = False if not btnA.value or not btnB.value or not btnC.value or not btnD.value: selector = True if selector: background = Rect(0, 0, 296, 128, fill=0xFFFFFF) group.append(background) for i in range(8): sprite_sheet, palette = adafruit_imageload.load( f"/bmps/{projects[i]}.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette, ) sprite = displayio.TileGrid( sprite_sheet, pixel_shader=palette, width=1, height=1, tile_width=62, tile_height=54, x=6 + 74 * (i % 4), y=6 + 62 * (i // 4), ) group.append(sprite) rect = Rect(4, 4, 66, 58, outline=0x000000, stroke=2)
parrot4 = 4 parrot5 = 5 parrot6 = 6 parrot7 = 7 parrot8 = 8 parrot9 = 9 # creates display display = board.DISPLAY # scale=2 allows the sprites to be bigger group = displayio.Group(max_size=20) def_tile = randint(0, 15) parrot, parrot_pal = adafruit_imageload.load("/partyParrotsClue.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) parrot0_grid = displayio.TileGrid(parrot, pixel_shader=parrot_pal, width=4, height=1, tile_height=60, tile_width=60, default_tile=def_tile, x=0, y=0) parrot1_grid = displayio.TileGrid(parrot, pixel_shader=parrot_pal, width=4,
"September", "October", "November", "December", ) magtag = MagTag() # ---------------------------- # Backgrounnd bitmap # ---------------------------- magtag.graphics.set_background(BACKGROUND_BMP) # ---------------------------- # Weather icons sprite sheet # ---------------------------- icons_large_bmp, icons_large_pal = adafruit_imageload.load(ICONS_LARGE_FILE) icons_small_bmp, icons_small_pal = adafruit_imageload.load(ICONS_SMALL_FILE) # ///////////////////////////////////////////////////////////////////////// def get_data_source_url(api="onecall", location=None): """Build and return the URL for the OpenWeather API.""" if api.upper() == "FORECAST5": URL = "https://api.openweathermap.org/data/2.5/forecast?" URL += "q=" + location elif api.upper() == "ONECALL": URL = "https://api.openweathermap.org/data/2.5/onecall?exclude=minutely,hourly,alerts" URL += "&lat={}".format(location[0]) URL += "&lon={}".format(location[1]) else:
PLOT_WIDTH = 116 PLOT_HEIGHT = 116 PLOT_X = 174 PLOT_Y = 6 PLOT_Y_SCALE = round(PLOT_HEIGHT / (4 * VSCALE)) DATE_FONT = bitmap_font.load_font("/fonts/Kanit-Black-24.bdf") TIME_FONT = bitmap_font.load_font("/fonts/Kanit-Medium-20.bdf") # 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)
def __init__(self, bitmap): #imported bitmap displayio.release_displays() oled_reset = board.D9 #defines display; change device address/width/height if needed i2c = board.I2C() display_bus = displayio.I2CDisplay(i2c, device_address=0x3D, reset=oled_reset) self.display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64) #imports sprite sheet, this should contain all sprites, you'll parse them later self.sprite_sheet, palette = adafruit_imageload.load( bitmap, bitmap=displayio.Bitmap, palette=displayio.Palette) #making individual tilemaps from main sprite sheet self.words = displayio.TileGrid( self.sprite_sheet, pixel_shader=palette, width=35, height=1, tile_width=1, tile_height=5 ) #width and height are of the tilegrid: tile_width and tile_height are the number of pixels of the bitmap self.background = displayio.TileGrid(self.sprite_sheet, pixel_shader=palette, width=8, height=4, tile_width=16, tile_height=16) self.sprite = displayio.TileGrid(self.sprite_sheet, pixel_shader=palette, width=1, height=1, tile_width=3, tile_height=3) self.highscore = displayio.TileGrid(self.sprite_sheet, pixel_shader=palette, width=60, height=1, tile_width=1, tile_height=5) #sub groups self.words_group = displayio.Group( scale=3 ) #creates subgroups; the scale value, suprisingly, changes the scale of the tilegrid self.words_group.x = 11 #position of subgroup in relation to main group self.words_group.y = 24 self.background_group = displayio.Group(scale=1) self.background_group.x = 0 self.background_group.y = 0 self.sprite_group = displayio.Group(scale=1) self.highscore_group = displayio.Group(scale=2) self.highscore_group.x = 4 self.highscore_group.y = 27 #main group self.group = displayio.Group() #creates main group
WHITE, AQUA, None, None, RED, TEAL, MAGENTA, PINK, ] print(colors) group = displayio.Group() # pyportal_setter.xcf has been included so you can edit the colors used in GIMP, just make sure to # change them here as well background, palette = adafruit_imageload.load("bmps/pyportal_setter.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) tile_grid = displayio.TileGrid(background, pixel_shader=palette) group.append(tile_grid) rect = Rect(0, 0, 160, 320, fill=0x000000) group.append(rect) print(len(group)) # Get wifi details and more from a secrets.py file try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise # PyPortal ESP32 Setup
import displayio import adafruit_imageload image, palette = adafruit_imageload.load("images/4bit.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
import adafruit_imageload import analogio import board import digitalio import displayio import time from gamepadshift import GamePadShift display = board.DISPLAY # Load the sprite sheet (bitmap) sprite_sheet, palette = adafruit_imageload.load("/tiny_dungeon_world.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # Create the sprite TileGrid sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette, width=1, height=1, tile_width=16, tile_height=16, default_tile=0) # Create the castle TileGrid castle = displayio.TileGrid(sprite_sheet, pixel_shader=palette, width=16, height=19, tile_width=16, tile_height=16)
stop = 0 z = 0 # image groups five_minGroup = displayio.Group() ten_minGroup = displayio.Group() twenty_minGroup = displayio.Group() hourGroup = displayio.Group() reverseqGroup = displayio.Group() backingUpGroup = displayio.Group() stopGroup = displayio.Group() progBarGroup = displayio.Group() # bitmap setup for all of the menu screens five_minBG, five_minPal = adafruit_imageload.load(five_minBMP, bitmap=displayio.Bitmap, palette=displayio.Palette) five_minDis = displayio.TileGrid(five_minBG, pixel_shader=five_minPal) ten_minBG, ten_minPal = adafruit_imageload.load(ten_minBMP, bitmap=displayio.Bitmap, palette=displayio.Palette) ten_minDis = displayio.TileGrid(ten_minBG, pixel_shader=ten_minPal) twenty_minBG, twenty_minPal = adafruit_imageload.load( twenty_minBMP, bitmap=displayio.Bitmap, palette=displayio.Palette) twenty_minDis = displayio.TileGrid(twenty_minBG, pixel_shader=twenty_minPal) hourBG, hourPal = adafruit_imageload.load(hourBMP, bitmap=displayio.Bitmap, palette=displayio.Palette) hourDis = displayio.TileGrid(hourBG, pixel_shader=hourPal) runningBG, runningPal = adafruit_imageload.load(runningBMP, bitmap=displayio.Bitmap,
import adafruit_imageload spi = board.SPI() tft_cs = board.D9 tft_dc = board.D10 displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) # image = "images/netpbm_p1_mono_ascii.pbm" # image = "images/netpbm_p2_ascii.pgm" # image = "images/netpbm_p3_rgb_ascii.ppm" # image = "images/netpbm_p4_mono_binary.pbm" # image = "images/netpbm_p5_binary.pgm" image = "images/netpbm_p6_binary.ppm" bitmap, palette = adafruit_imageload.load(image, bitmap=displayio.Bitmap, palette=displayio.Palette) bg_sprite = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=0) splash.append(bg_sprite) while True: pass
NUM_FLAKES = 50 # total number of snowflakes SNOW_COLOR = 0xFFFFFF # snow color SHAKE_THRESHOLD = 27 # shake sensitivity, lower=more sensitive #---| User Config |--------------- # 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): 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)
# 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 bg_palette.make_transparent(0) background = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette) # Add background to display splash.append(background) print('loading fonts...') # Fonts within /fonts/ folder
:param tile_coords: (x, y) tuple :return: True if the player can walk on this tile. False otherwise. """ return TILES[GAME_STATE["CURRENT_MAP"][tile_coords[0], tile_coords[1]]]["can_walk"] print("after funcs {}".format(gc.mem_free())) # display object variable display = board.DISPLAY # Load the sprite sheet (bitmap) sprite_sheet, palette = adafruit_imageload.load( "tilegame_assets/sprite_sheet.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette, ) # make green be transparent so entities can be drawn on top of map tiles palette.make_transparent(0) # Create the castle TileGrid castle = displayio.TileGrid( sprite_sheet, pixel_shader=palette, width=10, height=8, tile_width=16, tile_height=16, )
import displayio import time import os import adafruit_imageload button = digitalio.DigitalInOut(board.USR_BTN) button.direction = digitalio.Direction.INPUT button.pull = digitalio.Pull.UP display = board.DISPLAY group = displayio.Group(max_size=8) # Load bitmap ground_bmp, palette = adafruit_imageload.load("/img/ground512x12.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) palette.make_transparent(1) palette[0] = 0x808000 ground = displayio.TileGrid(ground_bmp, pixel_shader=palette, width=120, height=1, tile_width=2, tile_height=12, x=0, y=192) for x in range(120):
import board import displayio import adafruit_imageload image, palette = adafruit_imageload.load("images/4bit.bmp") tile_grid = displayio.TileGrid(image, pixel_shader=palette) group = displayio.Group() group.append(tile_grid) board.DISPLAY.show(group) while True: pass
# SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board import displayio import adafruit_imageload display = board.DISPLAY # Load the sprite sheet (bitmap) sprite_sheet, palette = adafruit_imageload.load("/cp_sprite_sheet.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # Create a sprite (tilegrid) sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette, width = 1, height = 1, tile_width = 16, tile_height = 16) # Create a Group to hold the sprite group = displayio.Group(scale=1) # Add the sprite to the Group group.append(sprite) # Add the Group to the Display display.show(group)
""" Used to switch to a different page """ p_num = tup[0] tile_grid = tup[1] new_page = pages[p_num - 1] new_page_vals = pages_vals[p_num - 1] my_display_group[-1] = tile_grid return new_page, new_page_vals # Verifies the Roku and Pyportal are connected and visible channels = getchannels() my_display_group = displayio.Group() image_1, palette_1 = adafruit_imageload.load("images/page_1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) tile_grid_1 = displayio.TileGrid(image_1, pixel_shader=palette_1) my_display_group.append(tile_grid_1) image_2, palette_2 = adafruit_imageload.load("images/page_2.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) tile_grid_2 = displayio.TileGrid(image_2, pixel_shader=palette_2) image_3, palette_3 = adafruit_imageload.load("images/page_3.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) tile_grid_3 = displayio.TileGrid(image_3, pixel_shader=palette_3) # fmt: off
} # BLE Radio Stuff ble = BLERadio() uart_service = UARTService() advertisement = ProvideServicesAdvertisement(uart_service) ble._adapter.name = MY_NAME #pylint: disable=protected-access # Display Stuff display = clue.display disp_group = displayio.Group() display.show(disp_group) # Background BMP with the Morse Code cheat sheet bmp, pal = adafruit_imageload.load("morse_bg.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) disp_group.append(displayio.TileGrid(bmp, pixel_shader=pal)) # Incoming messages show up here in_label = label.Label(terminalio.FONT, text='A' * 18, scale=2, color=0x000000) in_label.anchor_point = (0.5, 0) in_label.anchored_position = (65, 12) disp_group.append(in_label) # Outging messages show up here out_label = label.Label(terminalio.FONT, text='B' * 18, scale=2, color=0x000000) out_label.anchor_point = (0.5, 0)
import time import board import displayio import adafruit_sgp30 from adafruit_bitmap_font import bitmap_font from adafruit_display_text import label import adafruit_imageload from adafruit_clue import clue # --| User Config |------------------------- TVOC_LEVELS = (80, 120) # set two TVOC levels MESSAGES = ("GOOD", "SUS?", "BAD!") # set three messages (4 char max) # ------------------------------------------ # setup UI cow_bmp, cow_pal = adafruit_imageload.load("bmps/milk_bg.bmp") background = displayio.TileGrid(cow_bmp, pixel_shader=cow_pal) mouth_bmp, mouth_pal = adafruit_imageload.load("bmps/mouth_sheet.bmp") mouth = displayio.TileGrid( mouth_bmp, pixel_shader=mouth_pal, tile_width=40, tile_height=20, width=1, height=1, x=35, y=110, ) msg_font = bitmap_font.load_font("fonts/Alphakind_28.bdf")
0x9D50FF, # purple 0x13B0FE, # blue 0xABFF96, # green 0xFF96FF, # pink ) MESSAGE_COLORS = ( 0xFF0000, # red ) #---| User Config |-------------------------------------------------- # Create the display display = board.DISPLAY # Load the candy heart BMP bitmap, palette = adafruit_imageload.load("/images/heart_bw.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) heart = displayio.TileGrid(bitmap, pixel_shader=palette) # Set up message text font = bitmap_font.load_font("/fonts/Multicolore_36.bdf") line1 = label.Label(font, text="?" * 9) line2 = label.Label(font, text="?" * 5) line1.anchor_point = (0.5, 0) # middle top line2.anchor_point = (0.5, 1.0) # middle bottom # Set up group and add to display group = displayio.Group() group.append(heart) group.append(line1)
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) speaker_enable.direction = digitalio.Direction.OUTPUT speaker_enable.value = True # Set up audio audio = AudioOut(board.SPEAKER) mp3 = open("laugh.mp3", "rb") decoder = MP3Decoder(mp3) # set up the display for the board or external display = tft_gizmo.TFT_Gizmo() display.brightness = 0.0 # start off # load the images for the skull bitmap_top, palette_top = adafruit_imageload.load("/skull_top.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) bitmap_close, palette_close = adafruit_imageload.load( "/skull_close.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) bitmap_open, palette_open = adafruit_imageload.load("/skull_open.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) bitmap_middle, palette_middle = adafruit_imageload.load( "/skull_middle.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # Create the TileGrids for the skull picture skull_top = displayio.TileGrid(bitmap_top, pixel_shader=palette_top) skull_top.x = 53 # center on the display
# Create a TileGrid for the orange background bg_left_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette) bg_right_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette) # Create background groups scaled 24x to match screen size bg_left_group = displayio.Group(scale=24) bg_right_group = displayio.Group(scale=24) # add the background tilegrids to the scaled groups bg_left_group.append(bg_left_tile_grid) bg_right_group.append(bg_right_tile_grid) # load the eye image eye_image, eye_palette = adafruit_imageload.load("/small_triangle_eye.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # Create a TileGrid to hold the bitmap for each eye right_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette) left_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette) # initialize the monster m4sk hardware i2c_bus = board.I2C() mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus) # left eye group setup left_group = displayio.Group() mask.left_display.show(left_group)
EMPTY = 0 BLINKA_1 = 1 BLINKA_2 = 2 SPARKY = 3 HEART = 4 JUMP_1 = 5 JUMP_2 = 6 # creates display display = board.DISPLAY # scale=2 allows the sprites to be bigger group = displayio.Group(scale=2) # Blinka sprite setup blinka, blinka_pal = adafruit_imageload.load("/spritesNew.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # creates a transparent background for Blinka blinka_pal.make_transparent(7) blinka_grid = displayio.TileGrid(blinka, pixel_shader=blinka_pal, width=2, height=1, tile_height=16, tile_width=16, default_tile=EMPTY) blinka_grid.x = 0 blinka_grid.y = 32 blinka_group = displayio.Group()