Skip to content

Commit 829f688

Browse files
committed
offset palette example
1 parent 8fb17a3 commit 829f688

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_P8
2+
import pngdec
3+
4+
display = PicoGraphics(display=DISPLAY_TUFTY_2040, pen_type=PEN_P8)
5+
6+
# Create an instance of the PNG Decoder
7+
png = pngdec.PNG(display)
8+
9+
# Create some pens for use later.
10+
BG = display.create_pen(200, 200, 200)
11+
TEXT = display.create_pen(0, 0, 0)
12+
13+
# 16 Reds
14+
for i in range(16):
15+
display.create_pen(i * 16, 0, 0)
16+
17+
# 16 Greens
18+
for i in range(16):
19+
display.create_pen(0, i * 16, 0)
20+
21+
# 16 Blues
22+
for i in range(16):
23+
display.create_pen(0, 0, i * 16)
24+
25+
# Clear the screen
26+
display.set_pen(BG)
27+
display.clear()
28+
29+
display.set_pen(TEXT)
30+
display.text("PNG Pencil \n& Offset Palette", 125, 115)
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
497 Bytes
Loading

0 commit comments

Comments
 (0)