Skip to content

Commit 490c0ba

Browse files
authored
Merge pull request #3188 from FoamyGuy/magtag_haiku_viewer
Haiku viewer updates
2 parents 11ae87c + c4e3f2e commit 490c0ba

2 files changed

Lines changed: 7833 additions & 39 deletions

File tree

MagTag/MagTag_Haiku_Viewer/code.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,45 +51,6 @@
5151
# Initialize an Adafruit IO HTTP API object
5252
io = IO_HTTP(aio_username, aio_key, requests)
5353

54-
# variable to hold the built-in eInk display reference
55-
display = supervisor.runtime.display
56-
57-
# main group to hold all other visual elements
58-
main_group = displayio.Group()
59-
60-
# background group used for white background behind the quote
61-
# scale 8x to save memory on the Bitmap
62-
bg_group = displayio.Group(scale=8)
63-
64-
# Create & append Bitmap for the white background
65-
bg_bmp = displayio.Bitmap(display.width // 8, display.height // 8, 1)
66-
bg_palette = displayio.Palette(1)
67-
bg_palette[0] = 0xFFFFFF
68-
bg_tg = displayio.TileGrid(bg_bmp, pixel_shader=bg_palette)
69-
bg_group.append(bg_tg)
70-
main_group.append(bg_group)
71-
72-
73-
# Bamboo image element across the bottom
74-
bamboo_bmp, bamboo_palette = adafruit_imageload.load("bamboo.bmp")
75-
bamboo_tg = displayio.TileGrid(bitmap=bamboo_bmp, pixel_shader=bamboo_palette)
76-
bamboo_tg.y = display.height - bamboo_tg.tile_height - 5
77-
main_group.append(bamboo_tg)
78-
79-
# Grey border around the edges of the display
80-
border_group = displayio.Group(scale=4)
81-
border_bmp = displayio.Bitmap(display.width // 4, display.height // 4, 1)
82-
border_palette = displayio.Palette(2)
83-
border_palette[0] = 0x999999
84-
border_palette[1] = 0xFFFFFF
85-
border_palette.make_transparent(1)
86-
bitmaptools.fill_region(
87-
border_bmp, 1, 1, border_bmp.width - 1, border_bmp.height - 1, 1
88-
)
89-
border_tg = displayio.TileGrid(border_bmp, pixel_shader=border_palette)
90-
border_group.append(border_tg)
91-
main_group.append(border_group)
92-
9354
# if the AdafruitIO connection is active
9455
if io is not None:
9556
try:
@@ -131,6 +92,45 @@
13192
# get the selected haiku from the list
13293
haiku = all_haikus[current_index]
13394

95+
# variable to hold the built-in eInk display reference
96+
display = supervisor.runtime.display
97+
98+
# main group to hold all other visual elements
99+
main_group = displayio.Group()
100+
101+
# background group used for white background behind the quote
102+
# scale 8x to save memory on the Bitmap
103+
bg_group = displayio.Group(scale=8)
104+
105+
# Create & append Bitmap for the white background
106+
bg_bmp = displayio.Bitmap(display.width // 8, display.height // 8, 1)
107+
bg_palette = displayio.Palette(1)
108+
bg_palette[0] = 0xFFFFFF
109+
bg_tg = displayio.TileGrid(bg_bmp, pixel_shader=bg_palette)
110+
bg_group.append(bg_tg)
111+
main_group.append(bg_group)
112+
113+
114+
# Bamboo image element across the bottom
115+
bamboo_bmp, bamboo_palette = adafruit_imageload.load("bamboo.bmp")
116+
bamboo_tg = displayio.TileGrid(bitmap=bamboo_bmp, pixel_shader=bamboo_palette)
117+
bamboo_tg.y = display.height - bamboo_tg.tile_height - 5
118+
main_group.append(bamboo_tg)
119+
120+
# Grey border around the edges of the display
121+
border_group = displayio.Group(scale=4)
122+
border_bmp = displayio.Bitmap(display.width // 4, display.height // 4, 1)
123+
border_palette = displayio.Palette(2)
124+
border_palette[0] = 0x999999
125+
border_palette[1] = 0xFFFFFF
126+
border_palette.make_transparent(1)
127+
bitmaptools.fill_region(
128+
border_bmp, 1, 1, border_bmp.width - 1, border_bmp.height - 1, 1
129+
)
130+
border_tg = displayio.TileGrid(border_bmp, pixel_shader=border_palette)
131+
border_group.append(border_tg)
132+
main_group.append(border_group)
133+
134134
# load the custom font & initialze Label to show haiku
135135
FONT = bitmap_font.load_font("fanwood_webfont_15.bdf", displayio.Bitmap)
136136
haiku_lbl = Label(FONT, text=haiku, scale=1, color=0x333333, line_spacing=1.0)

0 commit comments

Comments
 (0)