Skip to content

Commit b5a040f

Browse files
committed
correct layout on pico display 1 & 2
1 parent d790d3d commit b5a040f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

micropython/examples/pico_display/display_png_offset_palette.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8
1+
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8
22
import pngdec
33

44
# Create a PicoGraphics instance
5-
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8, rotate=270)
5+
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P8, rotate=270)
6+
7+
# Get the display width/height so we can position the PNGs
8+
width, height = display.get_bounds()
69

710
# Set the backlight so we can see it!
811
display.set_backlight(1.0)
@@ -33,15 +36,24 @@
3336
display.set_pen(BG)
3437
display.clear()
3538

39+
3640
try:
3741
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
3842
# You can use Thonny to transfer PNG Images to your Pico.
3943
png.open_file("pencil_gray.png")
44+
45+
# Horizontally/vertically center the three PNG Images.
46+
png_w = png.get_width()
47+
png_h = png.get_height()
48+
49+
offset_x = (width - png_w * 2) // 2
50+
height_y = (height // 3)
51+
offset_y = (height_y - png_h * 2) // 2
4052

4153
# Decode our PNG file and set the X and Y
42-
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
43-
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
44-
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
54+
png.decode(offset_x, offset_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
55+
png.decode(offset_x, offset_y + height_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
56+
png.decode(offset_x, offset_y + (height_y * 2), scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
4557

4658
# Handle the error if the image doesn't exist on the flash.
4759
except OSError:

0 commit comments

Comments
 (0)