From fc67c0db86a4235e375d196bcfef17b1cbd1d4c6 Mon Sep 17 00:00:00 2001 From: thirdr Date: Thu, 4 Apr 2024 14:03:08 +0100 Subject: [PATCH] offset palette example --- .../tufty2040/display_png_offset_palette.py | 50 ++++++++++++++++++ .../examples/tufty2040/pencil_gray.png | Bin 0 -> 497 bytes 2 files changed, 50 insertions(+) create mode 100644 micropython/examples/tufty2040/display_png_offset_palette.py create mode 100644 micropython/examples/tufty2040/pencil_gray.png diff --git a/micropython/examples/tufty2040/display_png_offset_palette.py b/micropython/examples/tufty2040/display_png_offset_palette.py new file mode 100644 index 00000000..f1e402dd --- /dev/null +++ b/micropython/examples/tufty2040/display_png_offset_palette.py @@ -0,0 +1,50 @@ +from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_P8 +import pngdec + +display = PicoGraphics(display=DISPLAY_TUFTY_2040, pen_type=PEN_P8) + +# Create an instance of the PNG Decoder +png = pngdec.PNG(display) + +# Create some pens for use later. +BG = display.create_pen(200, 200, 200) +TEXT = display.create_pen(0, 0, 0) + +# 16 Reds +for i in range(16): + display.create_pen(i * 16, 0, 0) + +# 16 Greens +for i in range(16): + display.create_pen(0, i * 16, 0) + +# 16 Blues +for i in range(16): + display.create_pen(0, 0, i * 16) + +# Clear the screen +display.set_pen(BG) +display.clear() + +display.set_pen(TEXT) +display.text("PNG Pencil \n& Offset Palette", 125, 115) + +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") + + # 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) + +# Handle the error if the image doesn't exist on the flash. +except OSError: + print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.") + +display.update() + +# We're not doing anything else with the display now but we want to keep the program running! +while True: + pass diff --git a/micropython/examples/tufty2040/pencil_gray.png b/micropython/examples/tufty2040/pencil_gray.png new file mode 100644 index 0000000000000000000000000000000000000000..38e6d0862f446e47831dd24f341b923e67c0ad7b GIT binary patch literal 497 zcmeAS@N?(olHy`uVBq!ia0vp^3Lwk^Bp4lDyqr z82GJ>>=pxgoCO|{#X#NHL734=V|E2lkiEpy*OmPR3k!#ok=2PG)O|Mp4yn&0K?4F6;se#%bJ z-03vs)Hb1O_hcQmlvz6$9dlYT*jFazio)e_f;l9a@fRIB8oR3OD*WME{X zYhbKvWD#O$U}a!vWooHy0Av{a{)SSJ8ANP}$1Ois2+&M&Ae z%1qBFVF)Nq%E?StaLLb2%*@+1(J&gQObMneCAB!YD6^m>Ge3{P-P1QfA*nPor$je1 zPoX%--N`52Q5dLN6s9^iF|RZ&F}b9)D76Tz+-Kf|Q$PiLa0U4(sW}WFt