Skip to content

Commit f0246bd

Browse files
author
Melissa LeBlanc-Williams
committed
Updated examples to work with smaller screen better
1 parent d460be8 commit f0246bd

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

examples/ra8875_bmptest.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def __init__(self, filename):
3535
self.data_size = 0
3636
self.bpp = 0
3737
self.width = 0
38-
self.height=0
38+
self.height = 0
39+
self.read_header()
3940

4041
def read_header(self):
4142
if self.colors:
@@ -54,7 +55,6 @@ def read_header(self):
5455
self.colors = int.from_bytes(f.read(4), 'little')
5556

5657
def draw(self, disp, x=0, y=0):
57-
self.read_header()
5858
print("{:d}x{:d} image".format(self.width, self.height))
5959
print("{:d}-bit encoding detected".format(self.bpp))
6060
line = 0
@@ -80,4 +80,10 @@ def draw(self, disp, x=0, y=0):
8080
disp.push_pixels(current_line_data)
8181
disp.set_window(0, 0, disp.width, disp.height)
8282

83-
BMP("/ra8875_blinka.bmp").draw(display, 287, 127)
83+
bitmap = BMP("/ra8875_blinka.bmp")
84+
print(display.width)
85+
print(display.height)
86+
print(bitmap.width)
87+
print(bitmap.height)
88+
bitmap.draw(display, (display.width // 2) - (bitmap.width // 2),
89+
(display.height // 2) - (bitmap.height // 2))

examples/ra8875_simpletest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
display.curve(50, 100, 80, 40, 2, BLACK)
6060
display.fill_curve(50, 100, 78, 38, 2, WHITE)
6161

62-
display.txt_set_cursor(240, 240)
62+
display.txt_set_cursor(display.width // 2 - 200, display.height // 2 - 20)
63+
print(display.width)
64+
print(display.height)
6365
display.txt_trans(WHITE)
6466
display.txt_size(2)
6567
testvar = 99
@@ -77,7 +79,7 @@
7779
coords = display.touch_read()
7880
display.fill_circle(int(coords[0]/x_scale), int(coords[1]/y_scale), 4, MAGENTA)
7981
display.txt_color(WHITE, BLACK)
80-
display.txt_set_cursor(240, 240)
82+
display.txt_set_cursor(display.width // 2 - 220, display.height // 2 - 20)
8183
display.txt_size(2)
8284
display.txt_write("Position (" + str(int(coords[0]/x_scale)) + ", " +
8385
str(int(coords[1]/y_scale)) + ")")

0 commit comments

Comments
 (0)