|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import supervisor |
| 6 | +from displayio import Group, OnDiskBitmap, TileGrid, Palette |
| 7 | +from tilepalettemapper import TilePaletteMapper |
| 8 | + |
| 9 | +# use the default built-in display, |
| 10 | +# the HSTX / PicoDVI display for the Metro RP2350 |
| 11 | +display = supervisor.runtime.display |
| 12 | + |
| 13 | +# a group to hold all other visual elements |
| 14 | +main_group = Group(scale=4, x=30, y=30) |
| 15 | + |
| 16 | +# set the main group to show on the display |
| 17 | +display.root_group = main_group |
| 18 | + |
| 19 | +# load the sprite sheet bitmap |
| 20 | +spritesheet_bmp = OnDiskBitmap("match3_cards_spritesheet.bmp") |
| 21 | + |
| 22 | +# create a TilePaletteMapper |
| 23 | +tile_palette_mapper = TilePaletteMapper( |
| 24 | + spritesheet_bmp.pixel_shader, # input pixel_shader |
| 25 | + 5, # input color count |
| 26 | + 3, # grid width |
| 27 | + 1 # grid height |
| 28 | +) |
| 29 | + |
| 30 | +# create a TileGrid to show some cards |
| 31 | +cards_tilegrid = TileGrid(spritesheet_bmp, pixel_shader=tile_palette_mapper, |
| 32 | + width=3, height=1, tile_width=24, tile_height=32) |
| 33 | + |
| 34 | +# set each tile in the grid to a different sprite index |
| 35 | +cards_tilegrid[0, 0] = 10 |
| 36 | +cards_tilegrid[1, 0] = 25 |
| 37 | +cards_tilegrid[2, 0] = 2 |
| 38 | + |
| 39 | +# re-map each tile in the grid to use a different color for index 1 |
| 40 | +# all other indexes remain their default values |
| 41 | +tile_palette_mapper[0, 0] = [0, 2, 2, 3, 4] |
| 42 | +tile_palette_mapper[1, 0] = [0, 3, 2, 3, 4] |
| 43 | +tile_palette_mapper[2, 0] = [0, 4, 2, 3, 4] |
| 44 | + |
| 45 | +# add the tilegrid to the main group |
| 46 | +main_group.append(cards_tilegrid) |
| 47 | + |
| 48 | +# wait forever so it remains visible on the display |
| 49 | +while True: |
| 50 | + pass |
0 commit comments