|
| 1 | +from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8 |
| 2 | +import pngdec |
| 3 | + |
| 4 | +# Create a PicoGraphics instance |
| 5 | +display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8, rotate=270) |
| 6 | + |
| 7 | +# Set the backlight so we can see it! |
| 8 | +display.set_backlight(1.0) |
| 9 | + |
| 10 | +# Create an instance of the PNG Decoder |
| 11 | +png = pngdec.PNG(display) |
| 12 | + |
| 13 | +# Create some pens for use later. |
| 14 | +BG = display.create_pen(200, 200, 200) |
| 15 | + |
| 16 | +# 16 Reds |
| 17 | +for i in range(16): |
| 18 | + display.create_pen(i * 16, 0, 0) |
| 19 | + |
| 20 | +# 16 Greens |
| 21 | +for i in range(16): |
| 22 | + display.create_pen(0, i * 16, 0) |
| 23 | + |
| 24 | +# 16 Blues |
| 25 | +for i in range(16): |
| 26 | + display.create_pen(0, 0, i * 16) |
| 27 | + |
| 28 | +# Clear the screen |
| 29 | +display.set_pen(BG) |
| 30 | +display.clear() |
| 31 | + |
| 32 | +try: |
| 33 | + # Open our PNG File from flash. In this example we're using an image of a cartoon pencil. |
| 34 | + # You can use Thonny to transfer PNG Images to your Pico. |
| 35 | + png.open_file("pencil_gray.png") |
| 36 | + |
| 37 | + # Decode our PNG file and set the X and Y |
| 38 | + png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0) |
| 39 | + png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16) |
| 40 | + png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32) |
| 41 | + |
| 42 | +# Handle the error if the image doesn't exist on the flash. |
| 43 | +except OSError: |
| 44 | + print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.") |
| 45 | + |
| 46 | +display.update() |
| 47 | + |
| 48 | +# We're not doing anything else with the display now but we want to keep the program running! |
| 49 | +while True: |
| 50 | + pass |
0 commit comments