Iāve spent a happy morning āplayingā with Pico Explorer and built routines for lines at any angle, outline rectangles and circles, and special characters.
If you are new to graphical programming on Pico Explorer you may find this helps get you started:
# Graphics routines for Pimoroni Pico Explorer
# and Raspberry Pi Pico
# Tony Goodhew (arduinolink(AT)gmail.com)
# 25 January 2021
import picoexplorer as display
import time
import math
width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)
# Set the backlight to 90%
display.set_backlight(0.9)
# Define special 5x8 characters - 8 bytes each - 0...7
# Bytes top to bottom, 5 least significant bits only
smiley = [0x00,0x0A,0x00,0x04,0x11,0x0E,0x00,0x00]
sad = [0x00,0x0A,0x00,0x04,0x00,0x0E,0x11,0x00]
heart = [0,0,0,10,31,14,4,0]
b_heart = [0,10,31,0,0,14,4,0]
up_arrow =[0,4,14,21,4,4,0,0]
down_arrow = [0,4,4,21,14,4,0,0]
bits = [128,64,32,16,8,4,2,1] # Powers of 2
def mychar(xpos, ypos, pattern): # Print defined character
for line in range(8): # 5x8 characters
for ii in range(5): # Low value bits only
i = ii + 3
dot = pattern[line] & bits[i] # Extract bit
if dot: # Only print WHITE dots
display.pixel(xpos+i*2, ypos+line*2)
display.pixel(xpos+i*2+1, ypos+line*2)
display.pixel(xpos+i*2, ypos+line*2+1)
display.pixel(xpos+i*2+1, ypos+line*2+1)
def horiz(l,t,r): # left, top, right
n = r-l+1 # Horizontal line
for i in range(n):
display.pixel(l + i, t )
def vert(l,t,b): # left, top, bottom
n = b-t+1 # Vertical line
for i in range(n):
display.pixel(l, t+i)
def box(l,t,r,b): # left, top, right, bottom
horiz(l,t,r) # Empty rectangle
horiz(l,b,r)
vert(l,t,b)
vert(r,t,b)
def line(x,y,xx,yy): # (x,y) to (xx,yy)
if x > xx:
t = x # Swap co-ordinates if necessary
x = xx
xx = t
t = y
y = yy
yy = t
if xx-x == 0: # Avoid div by zero if vertical
vert(x,min(y,yy),max(y,yy))
else: # Draw line one dot at a time L to R
n=xx-x+1
grad = float((yy-y)/(xx-x)) # Calculate gradient
for i in range(n):
y3 = y + int(grad * i)
display.pixel(x+i,y3) # One dot at a time
def ring(cx,cy,rr): # Centre and radius
display.circle(cx,cy,rr)
display.set_pen(0,0,0) # background colour
display.circle(cx,cy,rr-1)
def ring2(cx,cy,r): # Centre (x,y), radius
for angle in range(0, 90, 2): # 0 to 90 degrees in 2s
y3=int(r*math.sin(math.radians(angle)))
x3=int(r*math.cos(math.radians(angle)))
display.pixel(cx-x3,cy+y3) # 4 quadrants
display.pixel(cx-x3,cy-y3)
display.pixel(cx+x3,cy+y3)
display.pixel(cx+x3,cy-y3)
def show(t): # Update display and short pause
display.update()
time.sleep(t)
# ===== Main ======
display.set_pen(255,255,0)
line(10,10,100,100)
show(1)
display.set_pen(255,0,255)
line(10,100,100,10)
show(1)
display.set_pen(0,255,255)
box(0,105,100,205)
show(1)
display.set_pen(255,0,0)
ring(160,50,50)
show(1)
display.set_pen(0,0,255)
ring2(160,160,50)
show(1)
display.text("Tony Goodhew", 15, 220, 240,3)
display.update()
mychar(20, 130, up_arrow) # Defined characters
mychar(40, 130, smiley)
mychar(60, 130, heart)
mychar(20, 160, down_arrow)
mychar(40, 160, sad)
mychar(60, 160, b_heart)
display.update()