|
1 |
| -from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8 |
| 1 | +from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8 |
2 | 2 | import pngdec
|
3 | 3 |
|
4 | 4 | # 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() |
6 | 9 |
|
7 | 10 | # Set the backlight so we can see it!
|
8 | 11 | display.set_backlight(1.0)
|
|
33 | 36 | display.set_pen(BG)
|
34 | 37 | display.clear()
|
35 | 38 |
|
| 39 | + |
36 | 40 | try:
|
37 | 41 | # Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
38 | 42 | # You can use Thonny to transfer PNG Images to your Pico.
|
39 | 43 | 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 |
40 | 52 |
|
41 | 53 | # 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) |
45 | 57 |
|
46 | 58 | # Handle the error if the image doesn't exist on the flash.
|
47 | 59 | except OSError:
|
|
0 commit comments