Compare commits

..

14 Commits

Author SHA1 Message Date
Ryan 49b2e193de
Merge 662df5a8b1 into 32c10482d9 2024-04-24 12:11:30 +00:00
thirdr 662df5a8b1 linting 2024-04-24 13:04:38 +01:00
thirdr eb841fbe53 correct layout on pico display 1 & 2 2024-04-24 13:04:38 +01:00
thirdr 14877b1793 adding pngdec 2024-04-24 13:04:38 +01:00
thirdr 233896ac81 fixed background colour 2024-04-24 13:04:38 +01:00
thirdr badc679c2b fixed background colour 2024-04-24 13:04:38 +01:00
thirdr fc67c0db86 offset palette example 2024-04-24 13:04:38 +01:00
thirdr 3b56bc1781 adjustment to scale and location 2024-04-24 13:04:38 +01:00
thirdr d74279dbdf png palette offset example 2024-04-24 13:04:38 +01:00
thirdr 4a7f552f8a Changed the png used 2024-04-24 13:04:38 +01:00
thirdr a4e8fda4d8 png decode example for tufty 2024-04-24 13:04:38 +01:00
thirdr 111e00de64 png decode example for display pack 2024-04-24 13:04:38 +01:00
thirdr 9cce6a7474 Error handling 2024-04-24 13:04:38 +01:00
thirdr dc63b215cd pngdec example for inky 2024-04-24 13:04:38 +01:00
1 changed files with 17 additions and 5 deletions

View File

@ -1,8 +1,11 @@
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8
import pngdec
# Create a PicoGraphics instance
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8, rotate=270)
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P8, rotate=270)
# Get the display width/height so we can position the PNGs
width, height = display.get_bounds()
# Set the backlight so we can see it!
display.set_backlight(1.0)
@ -33,15 +36,24 @@ for i in range(3):
display.set_pen(BG)
display.clear()
try:
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Pico.
png.open_file("pencil_gray.png")
# Horizontally/vertically center the three PNG Images.
png_w = png.get_width()
png_h = png.get_height()
offset_x = (width - png_w * 2) // 2
height_y = (height // 3)
offset_y = (height_y - png_h * 2) // 2
# Decode our PNG file and set the X and Y
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
png.decode(offset_x, offset_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
png.decode(offset_x, offset_y + height_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
png.decode(offset_x, offset_y + (height_y * 2), scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
# Handle the error if the image doesn't exist on the flash.
except OSError: